refactor: migrate remaining components to useRefresh hook

Replace triggerRefresh() with useRefresh() in:
- notes-tabs-view.tsx (5 calls → refreshNotes)
- label-management-dialog.tsx (3 calls → refreshLabels)
- note-inline-editor.tsx (3 calls → refreshNotes)
- note-card.tsx (7 calls → refreshNotes)
- recent-notes-section.tsx (3 calls → refreshNotes)
- notification-panel.tsx (2 calls → refreshNotes(null))
- notes-editorial-view.tsx (4 calls → refreshNotes)

NoteRefreshContext marked as @deprecated with JSDoc migration guide.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Antigravity
2026-05-08 14:45:50 +00:00
parent 9b8df398dc
commit 574c8b3166
8 changed files with 151 additions and 59 deletions

View File

@@ -2,6 +2,7 @@
import { useCallback, useEffect, useMemo, useState, useTransition, useRef } from 'react'
import { useNoteRefreshOptional } from '@/context/NoteRefreshContext'
import { useRefresh } from '@/lib/use-refresh'
import {
DndContext,
type DragEndEvent,
@@ -635,7 +636,7 @@ export function NotesTabsView({
onNoteCreated,
}: NotesTabsViewProps) {
const { t, language } = useLanguage()
const { triggerRefresh } = useNoteRefreshOptional()
const { refreshNotes } = useRefresh()
const [items, setItems] = useState<Note[]>(notes)
const [selectedId, setSelectedId] = useState<string | null>(null)
const [isCreating, startCreating] = useTransition()
@@ -796,8 +797,8 @@ export function NotesTabsView({
})
setSelectedId(newNote.id)
onNoteCreated?.(newNote)
// NOTE: No triggerRefresh() here — the note is already added to items above.
// triggerRefresh() would call getAllNotes() which may return stale cache
// NOTE: No refreshNotes(note.notebookId) here — the note is already added to items above.
// refreshNotes(note.notebookId) would call getAllNotes() which may return stale cache
// in production (skipRevalidation:true skips cache invalidation).
} catch {
toast.error(t('notes.createFailed') || 'Impossible de créer la note')
@@ -810,7 +811,7 @@ export function NotesTabsView({
setItems((prev) => prev.map((n) => n.id === note.id ? { ...n, isPinned: next } : n))
try {
await updateNote(note.id, { isPinned: next }, { skipRevalidation: true })
triggerRefresh()
refreshNotes(note.notebookId)
toast.success(next ? (t('notes.pinned') || 'Épinglée') : (t('notes.unpinned') || 'Désépinglée'))
} catch {
setItems((prev) => prev.map((n) => n.id === note.id ? { ...n, isPinned: note.isPinned } : n))
@@ -823,7 +824,7 @@ export function NotesTabsView({
await toggleArchive(note.id, true)
setItems((prev) => prev.filter((n) => n.id !== note.id))
setSelectedId((prev) => (prev === note.id ? null : prev))
triggerRefresh()
refreshNotes(note.notebookId)
toast.success(t('notes.archived') || 'Note archivée')
} catch {
toast.error(t('notes.archiveFailed') || 'Archivage échoué')
@@ -1022,7 +1023,7 @@ export function NotesTabsView({
onArchive={(noteId) => {
setItems((prev) => prev.filter((n) => n.id !== noteId))
setSelectedId((prev) => (prev === noteId ? null : prev))
triggerRefresh()
refreshNotes(selected?.notebookId)
}}
/>
{/* Toggle sidebar button — top-right of editor, always visible */}
@@ -1057,7 +1058,7 @@ export function NotesTabsView({
} else {
toast.info(t('reminder.removeReminder'))
}
triggerRefresh()
refreshNotes(items.find(n => n.id === noteId)?.notebookId)
} catch {
toast.error(t('general.error'))
}
@@ -1110,7 +1111,7 @@ export function NotesTabsView({
setItems((prev) => prev.filter((n) => n.id !== noteToDelete.id))
setSelectedId((prev) => (prev === noteToDelete.id ? null : prev))
setNoteToDelete(null)
triggerRefresh()
refreshNotes(noteToDelete.notebookId)
toast.success(t('notes.deleted'))
} catch {
toast.error(t('notes.deleteFailed'))