feat: feinschliff für iphone und ipad
- 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 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d58a697e3
commit
57eaede300
19 files changed
+301
-50
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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<typeof setTimeout> | undefined
|
||||
let watchdogTimer: ReturnType<typeof setTimeout> | 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
|
||||
}
|
||||
|
||||
@@ -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([])
|
||||
})
|
||||
})
|
||||
@@ -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<Toast[]>([])
|
||||
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 }
|
||||
})
|
||||
Reference in new issue
Block a user