fix: gleiche einblendungen nicht stapeln
Wiederholte Hinweise ersetzen einander, höchstens drei gleichzeitig, damit sie auf dem iPhone keine Buttons verdecken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57eaede300
commit
f98247d492
2 files changed
+18
-1
No files matched your search
@@ -22,6 +22,20 @@ describe('toast store', () => {
|
||||
expect(toast.toasts).toEqual([])
|
||||
})
|
||||
|
||||
it('replaces identical notices instead of stacking them', () => {
|
||||
const toast = useToastStore()
|
||||
toast.show('Gespeichert')
|
||||
toast.show('Gespeichert')
|
||||
toast.show('Gespeichert')
|
||||
expect(toast.toasts).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('shows at most three notices', () => {
|
||||
const toast = useToastStore()
|
||||
for (const text of ['a', 'b', 'c', 'd']) toast.show(text)
|
||||
expect(toast.toasts.map((t) => t.text)).toEqual(['b', 'c', 'd'])
|
||||
})
|
||||
|
||||
it('can be dismissed early', () => {
|
||||
const toast = useToastStore()
|
||||
toast.show('Hallo')
|
||||
|
||||
@@ -8,6 +8,7 @@ export interface Toast {
|
||||
}
|
||||
|
||||
const DURATION_MS = { info: 2500, error: 5000 } as const
|
||||
const MAX_VISIBLE = 3
|
||||
|
||||
/** Short, self-dismissing notices at the bottom of the screen. */
|
||||
export const useToastStore = defineStore('toast', () => {
|
||||
@@ -19,8 +20,10 @@ export const useToastStore = defineStore('toast', () => {
|
||||
}
|
||||
|
||||
function show(text: string, kind: Toast['kind'] = 'info'): void {
|
||||
// Repeated notices replace each other instead of piling up over the content
|
||||
const others = toasts.value.filter((t) => !(t.text === text && t.kind === kind))
|
||||
const id = nextId++
|
||||
toasts.value.push({ id, text, kind })
|
||||
toasts.value = [...others, { id, text, kind }].slice(-MAX_VISIBLE)
|
||||
setTimeout(() => dismiss(id), DURATION_MS[kind])
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user