diff --git a/memento-note/components/note-editor/note-editor-context.tsx b/memento-note/components/note-editor/note-editor-context.tsx index ca4a6fd..52cb4c7 100644 --- a/memento-note/components/note-editor/note-editor-context.tsx +++ b/memento-note/components/note-editor/note-editor-context.tsx @@ -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 !')