mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-13 04:06:57 +02:00
- Extract toast store to standalone module so notes store can show toasts - Add try/catch to all note mutations with optimistic updates + IDB queue on network error - Wire up startSync/stopSync in layout to enable online/offline event listeners - Reload notes from server after successful sync push to prevent data loss - Connect SyncIndicator to real sync status with Lucide cloud icons - Add 300ms minimum display time for status transitions - Add e2e tests for offline create, edit, trash, and sync-on-reconnect Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 lines
669 B
TypeScript
29 lines
669 B
TypeScript
import { writable } from 'svelte/store';
|
|
|
|
export interface ToastMessage {
|
|
id: number;
|
|
text: string;
|
|
type: 'info' | 'success' | 'error';
|
|
action?: { label: string; handler: () => void };
|
|
}
|
|
|
|
let counter = 0;
|
|
export const toasts = writable<ToastMessage[]>([]);
|
|
|
|
export function showToast(
|
|
text: string,
|
|
type: 'info' | 'success' | 'error' = 'info',
|
|
action?: { label: string; handler: () => void },
|
|
duration = 4000
|
|
) {
|
|
const id = ++counter;
|
|
toasts.update((t) => [...t, { id, text, type, action }]);
|
|
if (!action) {
|
|
setTimeout(() => dismiss(id), duration);
|
|
}
|
|
}
|
|
|
|
export function dismiss(id: number) {
|
|
toasts.update((t) => t.filter((toast) => toast.id !== id));
|
|
}
|