feat: note history modal with restore, diff comparison, and dynamic UI updates
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m14s

- Complete rewrite of note-history-modal: version list with inline restore/delete,
  split diff view with synced scrolling, rich preview for markdown/richtext/checklist
- Fix restore not updating editor: use key={id-updatedAt} on NoteInlineEditor to
  force remount on restore, and add sync useEffect to reset local state on prop changes
- Add sync useEffect in NoteEditor for external note updates
- Add historyEnabled to NOTE_LIST_SELECT (no more 'Activer' on every modal open)
- Replace browser confirm() with shadcn AlertDialog for delete confirmation
- Add i18n keys: currentVersion, compareVersions, diffTitle, diffSelectHint, deleteVersionDesc
- Install diff + @types/diff for visual line diffing
- Fix MasonryGrid render-phase sync to preserve local sizes
- Update notes-tabs-view merge logic for restored note propagation
- Remove debug console.log from restoreNoteVersion
This commit is contained in:
2026-05-02 16:51:12 +02:00
parent bd4dd0e9eb
commit 3818eb8237
13 changed files with 1012 additions and 302 deletions

View File

@@ -57,7 +57,7 @@ const NOTE_LIST_SELECT = {
language: true,
languageConfidence: true,
lastAiAnalysis: true,
// embedding: false — volontairement omis (économise ~6KB JSON/note)
historyEnabled: true,
} as const
// Wrapper for parseNote (embedding validation removed - embeddings are now in NoteEmbedding table)
@@ -382,7 +382,7 @@ export async function getNoteHistory(noteId: string, limit = 30) {
})
if (!note) return []
const entries = await (prisma as any).noteHistory.findMany({
const entries = await prisma.noteHistory.findMany({
where: { noteId: note.id, userId: session.user.id },
orderBy: { createdAt: 'desc' },
take: clampedLimit,
@@ -403,7 +403,7 @@ export async function restoreNoteVersion(noteId: string, historyEntryId: string)
where: { id: noteId, userId: session.user.id },
select: { id: true, notebookId: true },
}),
(prisma as any).noteHistory.findFirst({
prisma.noteHistory.findFirst({
where: {
id: historyEntryId,
noteId,
@@ -416,8 +416,10 @@ export async function restoreNoteVersion(noteId: string, historyEntryId: string)
throw new Error('History entry not found')
}
const userId = session.user.id
const restored = await prisma.note.update({
where: { id: note.id, userId: session.user.id },
where: { id: note.id, userId },
data: {
title: historyEntry.title,
content: historyEntry.content,
@@ -436,23 +438,7 @@ export async function restoreNoteVersion(noteId: string, historyEntryId: string)
},
})
try {
await createNoteHistorySnapshot({
noteId: note.id,
userId: session.user.id,
reason: `restore:v${historyEntry.version}`,
})
} catch (snapshotError) {
console.error('[HISTORY] Failed to create snapshot after restore:', snapshotError)
}
revalidatePath('/')
revalidatePath(`/note/${note.id}`)
revalidatePath('/archive')
if (note.notebookId) revalidatePath(`/notebook/${note.notebookId}`)
if (historyEntry.notebookId && historyEntry.notebookId !== note.notebookId) {
revalidatePath(`/notebook/${historyEntry.notebookId}`)
}
return parseNote(restored)
}
@@ -479,12 +465,12 @@ export async function deleteNoteHistoryEntry(noteId: string, historyEntryId: str
const session = await auth()
if (!session?.user?.id) throw new Error('Unauthorized')
const entry = await (prisma as any).noteHistory.findFirst({
const entry = await prisma.noteHistory.findFirst({
where: { id: historyEntryId, noteId, userId: session.user.id },
})
if (!entry) throw new Error('History entry not found')
await (prisma as any).noteHistory.delete({
await prisma.noteHistory.delete({
where: { id: historyEntryId },
})
}