ui: undo toast after trash / archive
A global ToastHost (mounted in the app shell) shows a transient toast with an Undo action, driven by the ui store (showToast/dismiss/runAction, 5s auto-dismiss). The notes store fires it centrally: trash → Undo restores; archive → Undo unarchives — so it works from card, editor, and keyboard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FRgehjoz7Yv8LkUfADxACm
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
interface Toast {
|
||||
id: number;
|
||||
message: string;
|
||||
actionLabel: string;
|
||||
action: () => void;
|
||||
}
|
||||
|
||||
// Cross-component UI signals that don't belong to any single view (e.g. a
|
||||
// global shortcut in the app shell asking the board to act).
|
||||
export const useUiStore = defineStore("ui", () => {
|
||||
@@ -10,5 +17,31 @@ export const useUiStore = defineStore("ui", () => {
|
||||
composeTick.value++;
|
||||
}
|
||||
|
||||
return { composeTick, requestCompose };
|
||||
// Transient undo toast (e.g. after trash/archive).
|
||||
const toast = ref<Toast | null>(null);
|
||||
let toastTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let toastSeq = 0;
|
||||
|
||||
function showToast(message: string, actionLabel: string, action: () => void) {
|
||||
toastSeq += 1;
|
||||
const id = toastSeq;
|
||||
toast.value = { id, message, actionLabel, action };
|
||||
clearTimeout(toastTimer);
|
||||
toastTimer = setTimeout(() => {
|
||||
if (toast.value?.id === id) toast.value = null;
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function dismissToast() {
|
||||
clearTimeout(toastTimer);
|
||||
toast.value = null;
|
||||
}
|
||||
|
||||
function runToastAction() {
|
||||
const action = toast.value?.action;
|
||||
dismissToast();
|
||||
action?.();
|
||||
}
|
||||
|
||||
return { composeTick, requestCompose, toast, showToast, dismissToast, runToastAction };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user