From f98247d492b2ff7a1f8be0e5391f8742ff7a189c Mon Sep 17 00:00:00 2001 From: dbildhauer Date: Sun, 25 Oct 2026 11:53:37 +0100 Subject: [PATCH] fix: gleiche einblendungen nicht stapeln MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wiederholte Hinweise ersetzen einander, höchstens drei gleichzeitig, damit sie auf dem iPhone keine Buttons verdecken. Co-Authored-By: Claude Opus 5.5 --- frontend/src/stores/toast.test.ts | 14 ++++++++++++++ frontend/src/stores/toast.ts | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/frontend/src/stores/toast.test.ts b/frontend/src/stores/toast.test.ts index 8f32e22..b7912b2 100644 --- a/frontend/src/stores/toast.test.ts +++ b/frontend/src/stores/toast.test.ts @@ -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') diff --git a/frontend/src/stores/toast.ts b/frontend/src/stores/toast.ts index 4250ee3..884115b 100644 --- a/frontend/src/stores/toast.ts +++ b/frontend/src/stores/toast.ts @@ -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]) }