feat(ux): zentrales deleteWithUndo + Undo-Toast in Birthdays

deleteWithUndo in ux.js: onDelete ausführen, Undo-Toast anzeigen.
Birthdays migriert; Contacts/Notes/Meals haben bereits optimistische Undo-Logik.
This commit is contained in:
Ulas Kalayci
2026-04-27 22:26:46 +02:00
parent 048e31e933
commit a66bd2b05c
3 changed files with 68 additions and 10 deletions
+21
View File
@@ -40,3 +40,24 @@ export function vibrate(pattern) {
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
navigator.vibrate(pattern);
}
/**
* Führt eine DELETE-Aktion aus und zeigt einen Undo-Toast.
*
* @param {Object} opts
* @param {() => Promise<void>} opts.onDelete - Async-Funktion die DELETE ausführt
* @param {() => Promise<void>} [opts.onUndo] - Async-Funktion die die Aktion rückgängig macht
* @param {string} opts.toastMessage - Text für den Toast
* @param {'success'|'danger'} [opts.toastType] - Toast-Typ, default 'success'
*/
export async function deleteWithUndo({ onDelete, onUndo, toastMessage, toastType = 'success' }) {
await onDelete();
if (window.oikos?.showToast) {
window.oikos.showToast(
toastMessage,
toastType,
onUndo ? 4000 : 2000,
onUndo ?? null,
);
}
}