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>
This commit is contained in:
@@ -64,6 +64,57 @@ export async function restoreNote(id: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_BULK_NOTES = 200
|
||||
|
||||
function uniqueNoteIds(ids: string[]) {
|
||||
return [...new Set(ids.filter((id) => typeof id === 'string' && id.length > 0))].slice(0, MAX_BULK_NOTES)
|
||||
}
|
||||
|
||||
export async function bulkTrashNotes(ids: string[], options?: { skipRevalidation?: boolean }) {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) throw new Error('Unauthorized')
|
||||
|
||||
const unique = uniqueNoteIds(ids)
|
||||
if (unique.length === 0) return { success: true, count: 0 }
|
||||
|
||||
try {
|
||||
const result = await prisma.note.updateMany({
|
||||
where: { id: { in: unique }, userId: session.user.id, trashedAt: null },
|
||||
data: { trashedAt: new Date() },
|
||||
})
|
||||
if (!options?.skipRevalidation) {
|
||||
revalidatePath('/home')
|
||||
}
|
||||
return { success: true, count: result.count }
|
||||
} catch (error) {
|
||||
console.error('Error bulk-trashing notes:', error)
|
||||
throw new Error('Failed to trash notes')
|
||||
}
|
||||
}
|
||||
|
||||
export async function restoreNotes(ids: string[], options?: { skipRevalidation?: boolean }) {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) throw new Error('Unauthorized')
|
||||
|
||||
const unique = uniqueNoteIds(ids)
|
||||
if (unique.length === 0) return { success: true, count: 0 }
|
||||
|
||||
try {
|
||||
const result = await prisma.note.updateMany({
|
||||
where: { id: { in: unique }, userId: session.user.id, trashedAt: { not: null } },
|
||||
data: { trashedAt: null },
|
||||
})
|
||||
if (!options?.skipRevalidation) {
|
||||
revalidatePath('/home')
|
||||
revalidatePath('/trash')
|
||||
}
|
||||
return { success: true, count: result.count }
|
||||
} catch (error) {
|
||||
console.error('Error restoring notes:', error)
|
||||
throw new Error('Failed to restore notes')
|
||||
}
|
||||
}
|
||||
|
||||
export async function getTrashedNotes() {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) return []
|
||||
|
||||
Reference in New Issue
Block a user