refactor: note-editor-context uses invalidateQueries on save/copy

Replace triggerRefresh() with targeted invalidateQueries() for:
- handleSave: invalidate note + notes list for notebookId
- handleSaveInPlace: invalidate note + notes list for notebookId
- handleMakeCopy: invalidate notes list for current notebook

Keeps triggerRefresh() for backward compat until fully migrated.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Antigravity
2026-05-08 14:32:30 +00:00
parent 91b1201112
commit def683982c

View File

@@ -1,6 +1,7 @@
'use client'
import { createContext, useContext, useState, useEffect, useRef, useMemo, useCallback, ReactNode } from 'react'
import { useQueryClient } from '@tanstack/react-query'
import { Note, CheckItem, NOTE_COLORS, NoteColor, LinkMetadata, NoteType, NoteSize } from '@/lib/types'
import { updateNote, createNote, cleanupOrphanedImages, leaveSharedNote, deleteNote } from '@/app/actions/notes'
import { fetchLinkMetadata } from '@/app/actions/scrape'
@@ -13,6 +14,7 @@ import { useLanguage } from '@/lib/i18n'
import { useSession } from 'next-auth/react'
import { getAISettings } from '@/app/actions/ai-settings'
import { extractImagesFromHTML } from '@/lib/utils'
import { queryKeys } from '@/lib/query-keys'
import type { TitleSuggestion } from '@/hooks/use-title-suggestions'
import type { TagSuggestion } from '@/lib/ai/types'
import type { NoteEditorState, NoteEditorActions, NoteEditorContextValue } from './types'
@@ -29,6 +31,7 @@ interface NoteEditorProviderProps {
export function NoteEditorProvider({ note, readOnly = false, fullPage = false, children }: NoteEditorProviderProps) {
const { data: session } = useSession()
const { t } = useLanguage()
const queryClient = useQueryClient()
const { labels: globalLabels, addLabel, refreshLabels, setNotebookId: setContextNotebookId, notebooks } = useNotebooks()
const { triggerRefresh } = useNoteRefresh()
@@ -539,6 +542,9 @@ export function NoteEditorProvider({ note, readOnly = false, fullPage = false, c
}
await refreshLabels()
// Invalidate note and notes list cache
queryClient.invalidateQueries({ queryKey: queryKeys.note(note.id) })
queryClient.invalidateQueries({ queryKey: queryKeys.notes(note.notebookId) })
triggerRefresh()
// Note: onClose is handled by the composition component
@@ -615,6 +621,8 @@ export function NoteEditorProvider({ note, readOnly = false, fullPage = false, c
size: size,
})
toast.success(t('notes.copySuccess'))
// Invalidate notes list cache for current notebook
queryClient.invalidateQueries({ queryKey: queryKeys.notes(note.notebookId) })
triggerRefresh()
// Note: onClose is handled by the composition component
} catch (error) {
@@ -644,6 +652,9 @@ export function NoteEditorProvider({ note, readOnly = false, fullPage = false, c
cleanupOrphanedImages(removedImageUrls, note.id).catch(() => {})
}
await refreshLabels()
// Invalidate note and notes list cache
queryClient.invalidateQueries({ queryKey: queryKeys.note(note.id) })
queryClient.invalidateQueries({ queryKey: queryKeys.notes(note.notebookId) })
triggerRefresh()
setIsDirty(false)
toast.success('Note sauvegardée !')