From 57eaede30006fe6552f23e1893eb553c3942d7fd Mon Sep 17 00:00:00 2001 From: dbildhauer Date: Sun, 25 Oct 2026 11:49:27 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20feinschliff=20f=C3=BCr=20iphone=20und?= =?UTF-8?q?=20ipad?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Safe Areas: Header unter Statusleiste/Notch, Ränder im Querformat - Touch: alle Buttons mind. 44 px, kein Doppeltipp-Zoom-Verzug - ab 1024 px Breite zwei Spalten für die Clip-Karten - relative Zeitangaben ('vor 5 Min.'), genaues Datum als Tooltip - kurze Einblendungen für Speichern, Löschen, Anheften und Fehler - nach über 60 s im Hintergrund wird die Liste neu geladen Co-Authored-By: Claude Opus 5.5 --- frontend/src/App.vue | 4 +- frontend/src/assets/main.css | 25 ++++++++- frontend/src/components/AppHeader.vue | 2 +- frontend/src/components/ClipCard.vue | 16 +++++- frontend/src/components/QuickAdd.vue | 3 + frontend/src/components/ToastHost.vue | 70 ++++++++++++++++++++++++ frontend/src/components/UpdateBanner.vue | 29 ---------- frontend/src/main.ts | 2 + frontend/src/stores/sync.test.ts | 24 ++++++++ frontend/src/stores/sync.ts | 17 +++++- frontend/src/stores/toast.test.ts | 31 +++++++++++ frontend/src/stores/toast.ts | 32 +++++++++++ frontend/src/utils/format.test.ts | 21 ++++++- frontend/src/utils/format.ts | 16 ++++++ frontend/src/utils/now.ts | 10 ++++ frontend/src/views/ClipEditView.vue | 4 ++ frontend/src/views/HomeView.vue | 41 ++++++++++---- frontend/src/views/LoginView.vue | 2 +- frontend/src/views/OfflineView.vue | 2 +- 19 files changed, 301 insertions(+), 50 deletions(-) create mode 100644 frontend/src/components/ToastHost.vue delete mode 100644 frontend/src/components/UpdateBanner.vue create mode 100644 frontend/src/stores/toast.test.ts create mode 100644 frontend/src/stores/toast.ts create mode 100644 frontend/src/utils/now.ts diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 39ef7e1..6e3c5db 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -3,7 +3,7 @@ import { watch } from 'vue' import { RouterView } from 'vue-router' import AppHeader from '@/components/AppHeader.vue' -import UpdateBanner from '@/components/UpdateBanner.vue' +import ToastHost from '@/components/ToastHost.vue' import { useAuthStore } from '@/stores/auth' import { useClipsStore } from '@/stores/clips' import { useSyncStore } from '@/stores/sync' @@ -29,5 +29,5 @@ watch( diff --git a/frontend/src/assets/main.css b/frontend/src/assets/main.css index 3664042..9a368f3 100644 --- a/frontend/src/assets/main.css +++ b/frontend/src/assets/main.css @@ -32,9 +32,18 @@ body { -webkit-text-size-adjust: 100%; } +/* Top inset is handled by the sticky header (status bar overlays the app on iOS) */ body { - padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) - env(safe-area-inset-left); + padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); +} + +button, +a, +select, +input, +textarea { + /* No double-tap-to-zoom delay on touch devices */ + touch-action: manipulation; } /* --- Shared building blocks ------------------------------------------------ */ @@ -215,3 +224,15 @@ code { background: var(--accent); color: var(--bg); } + +.page.wide { + max-width: 72rem; +} + +/* Touch devices: every control at least 44 px high */ +@media (pointer: coarse) { + button.small, + .button-link.small { + min-height: 44px; + } +} diff --git a/frontend/src/components/AppHeader.vue b/frontend/src/components/AppHeader.vue index 74d90ee..75d24ec 100644 --- a/frontend/src/components/AppHeader.vue +++ b/frontend/src/components/AppHeader.vue @@ -50,7 +50,7 @@ async function logout(): Promise { align-items: center; justify-content: space-between; gap: 0.5rem 1rem; - padding: 0.5rem 1rem; + padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem; background: var(--surface); border-bottom: 1px solid var(--border); } diff --git a/frontend/src/components/ClipCard.vue b/frontend/src/components/ClipCard.vue index 581f8ed..b34a7f0 100644 --- a/frontend/src/components/ClipCard.vue +++ b/frontend/src/components/ClipCard.vue @@ -4,8 +4,9 @@ import { RouterLink } from 'vue-router' import type { Clip } from '@/api/types' import CopyButton from '@/components/CopyButton.vue' -import { formatDateTime } from '@/utils/format' +import { formatDateTime, formatRelative } from '@/utils/format' import { highlight, languageLabel } from '@/utils/highlight' +import { now } from '@/utils/now' const props = defineProps<{ clip: Clip }>() const emit = defineEmits<{ togglePin: []; remove: [] }>() @@ -38,7 +39,13 @@ const html = computed(() => angeheftet {{ languageLabel(clip.language) }} - {{ formatDateTime(clip.updated_at) }} + @@ -61,6 +68,11 @@ const html = computed(() => diff --git a/frontend/src/components/UpdateBanner.vue b/frontend/src/components/UpdateBanner.vue deleted file mode 100644 index 6da28c0..0000000 --- a/frontend/src/components/UpdateBanner.vue +++ /dev/null @@ -1,29 +0,0 @@ - - - - - diff --git a/frontend/src/main.ts b/frontend/src/main.ts index bba574c..db6d6ad 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -9,6 +9,7 @@ import App from './App.vue' import { initPwa } from './pwa' import router from './router' import { useAuthStore } from './stores/auth' +import { startClock } from './utils/now' const app = createApp(App) @@ -25,3 +26,4 @@ setUnauthorizedHandler(() => { app.mount('#app') initPwa() +startClock() diff --git a/frontend/src/stores/sync.test.ts b/frontend/src/stores/sync.test.ts index 5762a0b..c270859 100644 --- a/frontend/src/stores/sync.test.ts +++ b/frontend/src/stores/sync.test.ts @@ -154,6 +154,30 @@ describe('sync store', () => { expect(sync.status).toBe('live') }) + it('reloads the list after more than 60 s in the background', () => { + const sync = useSyncStore() + const clips = useClipsStore() + clips.loaded = true + const load = vi.spyOn(clips, 'load').mockResolvedValue() + sync.start() + let visibility: DocumentVisibilityState = 'visible' + vi.spyOn(document, 'visibilityState', 'get').mockImplementation(() => visibility) + const setVisibility = (state: DocumentVisibilityState) => { + visibility = state + document.dispatchEvent(new Event('visibilitychange')) + } + + setVisibility('hidden') + vi.advanceTimersByTime(30_000) + setVisibility('visible') + expect(load).not.toHaveBeenCalled() + + setVisibility('hidden') + vi.advanceTimersByTime(61_000) + setVisibility('visible') + expect(load).toHaveBeenCalledOnce() + }) + it('stop closes the socket and does not reconnect', () => { const sync = useSyncStore() sync.start() diff --git a/frontend/src/stores/sync.ts b/frontend/src/stores/sync.ts index 958d040..5b107ab 100644 --- a/frontend/src/stores/sync.ts +++ b/frontend/src/stores/sync.ts @@ -18,6 +18,8 @@ const MAX_RETRY_MS = 30_000 // Server pings every 30 s; silence beyond this means the connection is dead const WATCHDOG_MS = 75_000 const CLOSE_UNAUTHORIZED = 4401 +// iOS may keep a dead socket "open" in the background; refresh after longer absences +const STALE_AFTER_HIDDEN_MS = 60_000 /** * Live sync: receives change events over a WebSocket and applies them to the clip store. @@ -32,6 +34,7 @@ export const useSyncStore = defineStore('sync', () => { let retryTimer: ReturnType | undefined let watchdogTimer: ReturnType | undefined let listenersAdded = false + let hiddenSince: number | null = null function handle(message: ServerMessage): void { const clips = useClipsStore() @@ -108,6 +111,18 @@ export const useSyncStore = defineStore('sync', () => { retryDelay = Math.min(retryDelay * 2, MAX_RETRY_MS) } + function onVisibilityChange(): void { + if (document.visibilityState === 'hidden') { + hiddenSince = Date.now() + return + } + const away = hiddenSince === null ? 0 : Date.now() - hiddenSince + hiddenSince = null + const clips = useClipsStore() + if (wanted && away >= STALE_AFTER_HIDDEN_MS && clips.loaded) void clips.load() + reconnectNow() + } + /** Reconnect right away, e.g. when an iPhone brings the app back to the foreground. */ function reconnectNow(): void { if (!wanted || document.visibilityState !== 'visible') return @@ -121,7 +136,7 @@ export const useSyncStore = defineStore('sync', () => { function start(): void { wanted = true if (!listenersAdded) { - document.addEventListener('visibilitychange', reconnectNow) + document.addEventListener('visibilitychange', onVisibilityChange) window.addEventListener('online', reconnectNow) listenersAdded = true } diff --git a/frontend/src/stores/toast.test.ts b/frontend/src/stores/toast.test.ts new file mode 100644 index 0000000..8f32e22 --- /dev/null +++ b/frontend/src/stores/toast.test.ts @@ -0,0 +1,31 @@ +import { createPinia, setActivePinia } from 'pinia' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +import { useToastStore } from './toast' + +describe('toast store', () => { + beforeEach(() => { + setActivePinia(createPinia()) + vi.useFakeTimers() + }) + afterEach(() => vi.useRealTimers()) + + it('dismisses info toasts after 2.5 s and errors after 5 s', () => { + const toast = useToastStore() + toast.show('Gespeichert') + toast.error(new Error('Kaputt')) + expect(toast.toasts.map((t) => t.text)).toEqual(['Gespeichert', 'Kaputt']) + + vi.advanceTimersByTime(2500) + expect(toast.toasts.map((t) => t.kind)).toEqual(['error']) + vi.advanceTimersByTime(2500) + expect(toast.toasts).toEqual([]) + }) + + it('can be dismissed early', () => { + const toast = useToastStore() + toast.show('Hallo') + toast.dismiss(toast.toasts[0]!.id) + expect(toast.toasts).toEqual([]) + }) +}) diff --git a/frontend/src/stores/toast.ts b/frontend/src/stores/toast.ts new file mode 100644 index 0000000..4250ee3 --- /dev/null +++ b/frontend/src/stores/toast.ts @@ -0,0 +1,32 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' + +export interface Toast { + id: number + text: string + kind: 'info' | 'error' +} + +const DURATION_MS = { info: 2500, error: 5000 } as const + +/** Short, self-dismissing notices at the bottom of the screen. */ +export const useToastStore = defineStore('toast', () => { + const toasts = ref([]) + let nextId = 1 + + function dismiss(id: number): void { + toasts.value = toasts.value.filter((t) => t.id !== id) + } + + function show(text: string, kind: Toast['kind'] = 'info'): void { + const id = nextId++ + toasts.value.push({ id, text, kind }) + setTimeout(() => dismiss(id), DURATION_MS[kind]) + } + + function error(e: unknown): void { + show(e instanceof Error ? e.message : String(e), 'error') + } + + return { toasts, show, error, dismiss } +}) diff --git a/frontend/src/utils/format.test.ts b/frontend/src/utils/format.test.ts index 9746ab1..14628b6 100644 --- a/frontend/src/utils/format.test.ts +++ b/frontend/src/utils/format.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' -import { describeUserAgent, formatDateTime } from './format' +import { describeUserAgent, formatDateTime, formatRelative } from './format' describe('describeUserAgent', () => { it.each([ @@ -36,3 +36,22 @@ describe('formatDateTime', () => { expect(formatDateTime('2026-10-25T09:30:00Z')).toMatch(/25\.10\.2026|25\. Okt\. 2026/) }) }) + +describe('formatRelative', () => { + const now = Date.parse('2026-10-25T12:00:00Z') + const ago = (ms: number) => new Date(now - ms).toISOString() + + it.each([ + [10_000, 'gerade eben'], + [5 * 60_000, 'vor 5 Min.'], + [3 * 3_600_000, 'vor 3 Std.'], + [26 * 3_600_000, 'gestern'], + [3 * 86_400_000, 'vor 3 Tagen'], + ])('%i ms ago', (ms, expected) => { + expect(formatRelative(ago(ms), now)).toBe(expected) + }) + + it('shows the full date after a week', () => { + expect(formatRelative(ago(8 * 86_400_000), now)).toBe(formatDateTime(ago(8 * 86_400_000))) + }) +}) diff --git a/frontend/src/utils/format.ts b/frontend/src/utils/format.ts index a702484..eedbac3 100644 --- a/frontend/src/utils/format.ts +++ b/frontend/src/utils/format.ts @@ -7,6 +7,22 @@ export function formatDateTime(iso: string): string { return dateTimeFormat.format(new Date(iso)) } +const relativeFormat = new Intl.RelativeTimeFormat('de-DE', { numeric: 'auto', style: 'short' }) + +const MINUTE = 60_000 +const HOUR = 60 * MINUTE +const DAY = 24 * HOUR + +/** "gerade eben", "vor 5 Min.", "vor 3 Std.", "gestern"; older than a week: full date. */ +export function formatRelative(iso: string, now: number = Date.now()): string { + const diff = now - new Date(iso).getTime() + if (diff < MINUTE) return 'gerade eben' + if (diff < HOUR) return relativeFormat.format(-Math.floor(diff / MINUTE), 'minute') + if (diff < DAY) return relativeFormat.format(-Math.floor(diff / HOUR), 'hour') + if (diff < 7 * DAY) return relativeFormat.format(-Math.floor(diff / DAY), 'day') + return formatDateTime(iso) +} + // Order matters: iPad/iPhone before macOS, Edge/Chrome before Safari const DEVICES: [RegExp, string][] = [ [/iPad/, 'iPad'], diff --git a/frontend/src/utils/now.ts b/frontend/src/utils/now.ts new file mode 100644 index 0000000..10f84c3 --- /dev/null +++ b/frontend/src/utils/now.ts @@ -0,0 +1,10 @@ +import { ref } from 'vue' + +/** Current time, updated every 30 s, so relative timestamps stay fresh without reloads. */ +export const now = ref(Date.now()) + +let timer: ReturnType | undefined + +export function startClock(): void { + timer ??= setInterval(() => (now.value = Date.now()), 30_000) +} diff --git a/frontend/src/views/ClipEditView.vue b/frontend/src/views/ClipEditView.vue index fe48dd7..126a2cf 100644 --- a/frontend/src/views/ClipEditView.vue +++ b/frontend/src/views/ClipEditView.vue @@ -6,12 +6,14 @@ import { ApiError } from '@/api/client' import type { Clip, ClipKind } from '@/api/types' import CopyButton from '@/components/CopyButton.vue' import { ClipConflictError, useClipsStore } from '@/stores/clips' +import { useToastStore } from '@/stores/toast' import { formatDateTime } from '@/utils/format' import { detectLanguage, highlight, LANGUAGES } from '@/utils/highlight' const props = defineProps<{ id: string }>() const store = useClipsStore() +const toast = useToastStore() const router = useRouter() const clip = ref(null) @@ -89,6 +91,7 @@ async function save(version = baseVersion.value): Promise { conflict.value = null leaving = true clip.value = null // nothing left to lose; skip the leave guard + toast.show('Gespeichert') await router.push('/') } catch (e) { if (e instanceof ClipConflictError) { @@ -113,6 +116,7 @@ async function remove(): Promise { try { await store.remove(clip.value.id) clip.value = null + toast.show('Gelöscht') await router.push('/') } catch (e) { leaving = false diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index 2a2018d..da88380 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -5,14 +5,17 @@ import type { Clip } from '@/api/types' import ClipCard from '@/components/ClipCard.vue' import QuickAdd from '@/components/QuickAdd.vue' import { useClipsStore } from '@/stores/clips' +import { useToastStore } from '@/stores/toast' const store = useClipsStore() +const toast = useToastStore() async function togglePin(clip: Clip): Promise { try { await store.update(clip.id, { pinned: !clip.pinned }) + toast.show(clip.pinned ? 'Gelöst' : 'Angeheftet') } catch (e) { - store.error = e instanceof Error ? e.message : String(e) + toast.error(e) } } @@ -20,8 +23,9 @@ async function remove(clip: Clip): Promise { if (!confirm('Diesen Clip endgültig löschen?')) return try { await store.remove(clip.id) + toast.show('Gelöscht') } catch (e) { - store.error = e instanceof Error ? e.message : String(e) + toast.error(e) } } @@ -29,7 +33,7 @@ onMounted(store.load)