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>
58 lines
1.5 KiB
TypeScript
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'))
|
|
}
|
|
},
|
|
},
|
|
})
|
|
}
|