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

@@ -1,6 +1,6 @@
'use client'
import { useCallback, useEffect, useMemo, useState, useTransition } from 'react'
import { useCallback, useEffect, useMemo, useState, useTransition, useRef } from 'react'
import { useNoteRefreshOptional } from '@/context/NoteRefreshContext'
import {
DndContext,
@@ -641,34 +641,48 @@ export function NotesTabsView({
const [sortOrder, setSortOrder] = useState<SortOrder>('date-desc')
const [sidebarOpen, setSidebarOpen] = useState(true)
useEffect(() => {
setItems((prev) => {
const prevIds = prev.map((n) => n.id).join(',')
const incomingIds = notes.map((n) => n.id).join(',')
const merge = (fresh: Note, local: Note) => {
const labelsChanged = JSON.stringify(fresh.labels?.sort()) !== JSON.stringify(local.labels?.sort())
return {
...fresh,
title: local.title || fresh.title,
content: local.content,
checkItems: local.checkItems,
labels: labelsChanged ? fresh.labels : local.labels
}
const prevNotesRef = useRef<Note[]>(notes)
if (notes !== prevNotesRef.current) {
const prevIds = items.map((n) => n.id).join(',')
const incomingIds = notes.map((n) => n.id).join(',')
const merge = (fresh: Note, local: Note, oldFresh?: Note) => {
const labelsChanged = JSON.stringify(fresh.labels?.sort()) !== JSON.stringify(local.labels?.sort())
const contentChangedOnServer = oldFresh && oldFresh.content !== fresh.content
const titleChangedOnServer = oldFresh && oldFresh.title !== fresh.title
const checkItemsChangedOnServer = oldFresh && JSON.stringify(oldFresh.checkItems) !== JSON.stringify(fresh.checkItems)
return {
...fresh,
title: titleChangedOnServer ? fresh.title : (local.title || fresh.title),
content: contentChangedOnServer ? fresh.content : local.content,
checkItems: checkItemsChangedOnServer ? fresh.checkItems : local.checkItems,
labels: labelsChanged ? fresh.labels : local.labels
}
if (prevIds === incomingIds) {
return prev.map((p) => {
const fresh = notes.find((n) => n.id === p.id)
if (!fresh) return p
return merge(fresh, p)
})
}
return notes.map((fresh) => {
const local = prev.find((p) => p.id === fresh.id)
if (!local) return fresh
return merge(fresh, local)
}
let newItems: Note[]
if (prevIds === incomingIds) {
newItems = items.map((local) => {
const fresh = notes.find((n) => n.id === local.id)
if (!fresh) return local
const oldFresh = prevNotesRef.current.find((n) => n.id === local.id)
return merge(fresh, local, oldFresh)
})
})
}, [notes])
} else {
newItems = notes.map((fresh) => {
const local = items.find((p) => p.id === fresh.id)
if (!local) return fresh
const oldFresh = prevNotesRef.current.find((n) => n.id === fresh.id)
return merge(fresh, local, oldFresh)
})
}
setItems(newItems)
prevNotesRef.current = notes
}
useEffect(() => {
if (items.length === 0) {
@@ -932,7 +946,7 @@ export function NotesTabsView({
)}
>
<NoteInlineEditor
key={selected.id}
key={`${selected.id}-${String(selected.updatedAt)}`}
note={selected}
noteHistoryMode={noteHistoryMode}
onOpenHistory={onOpenHistory}