Files
Momento/memento-note/lib/notes/trash-toast.ts
Antigravity a7b16870a4
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 7m17s
CI / Deploy production (on server) (push) Successful in 24s
fix(ui): sélection groupée dans la boîte de réception
Permet de cocher plusieurs notes, les déplacer vers un carnet ou les envoyer à la corbeille, et rend la carte mentale plus lisible.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-01 19:40:10 +00:00

58 lines
1.5 KiB
TypeScript

'use client'
import { toast } from 'sonner'
import { restoreNote, restoreNotes } from '@/app/actions/notes'
import { emitNoteChange } from '@/lib/note-change-sync'
import type { Note } from '@/lib/types'
export function showNoteTrashedToast(
note: Note,
t: (key: string) => string,
onRestored?: () => void,
) {
toast.success(t('notes.noteDeletedToast'), {
action: {
label: t('notes.undoDelete'),
onClick: async () => {
try {
await restoreNote(note.id)
const restored = { ...note, trashedAt: null }
emitNoteChange({ type: 'created', note: restored })
onRestored?.()
toast.success(t('trash.noteRestored'))
} catch {
toast.error(t('general.error'))
}
},
},
})
}
export function showNotesTrashedToast(
notes: Note[],
t: (key: string, params?: Record<string, string | number>) => string,
onRestored?: () => void,
) {
if (notes.length === 1) {
showNoteTrashedToast(notes[0], t, onRestored)
return
}
toast.success(t('notes.bulkTrashedToast', { count: notes.length }), {
action: {
label: t('notes.undoDelete'),
onClick: async () => {
try {
await restoreNotes(notes.map((note) => note.id), { skipRevalidation: true })
for (const note of notes) {
emitNoteChange({ type: 'created', note: { ...note, trashedAt: null } })
}
onRestored?.()
toast.success(t('trash.noteRestored'))
} catch {
toast.error(t('general.error'))
}
},
},
})
}