Files
Momento/memento-note/lib/use-refresh.ts
Antigravity 91b1201112 refactor: split NoteEditor into focused components + consolidate contexts
Phase 1: NoteEditor Split (64KB → 9 focused components)
- components/note-editor/: types.ts, context, toolbar, title-block,
  content-area, metadata-section, full-page, dialog compositions
- Maintains backwards compatibility via re-export from note-editor.tsx

Phase 2: Context Consolidation (5 → 3 contexts)
- NotebooksContext absorbs LabelContext (labels CRUD)
- EditorUIContext merges HomeViewContext + NotebookDragContext
- Removed: LabelContext, home-view-context, notebook-drag-context

Phase 3: React Query Infrastructure
- Added QueryProvider with @tanstack/react-query
- lib/query-keys.ts: centralized query key definitions
- lib/query-hooks.ts: useNotes, useNotebooksQuery, useLabelsQuery
- lib/use-refresh.ts: hybrid invalidateQueries + triggerRefresh helper
- NotebooksContext: invalidateQueries on mutations (with triggerRefresh fallback)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 14:31:08 +00:00

47 lines
1.5 KiB
TypeScript

'use client'
import { useCallback } from 'react'
import { useQueryClient } from '@tanstack/react-query'
import { useNoteRefresh } from '@/context/NoteRefreshContext'
import { queryKeys, invalidateNotes, invalidateNotebooks, invalidateLabels } from './query-hooks'
/**
* Combined refresh hook that:
* 1. Calls triggerRefresh() for backward compatibility (NoteRefreshContext)
* 2. Invalidates React Query cache for the affected keys
*
* This allows gradual migration from triggerRefresh to pure React Query.
*/
export function useRefresh() {
const queryClient = useQueryClient()
const { triggerRefresh, triggerNotebooksRefresh } = useNoteRefresh()
const refreshNotes = useCallback((notebookId?: string | null) => {
// Invalidate React Query cache
invalidateNotes(queryClient, notebookId)
// Trigger old refresh mechanism
triggerRefresh()
}, [queryClient, triggerRefresh])
const refreshNotebooks = useCallback(() => {
// Invalidate React Query cache
invalidateNotebooks(queryClient)
// Trigger old refresh mechanism
triggerNotebooksRefresh()
}, [queryClient, triggerNotebooksRefresh])
const refreshLabels = useCallback((notebookId?: string | null) => {
invalidateLabels(queryClient, notebookId)
triggerRefresh() // Labels affect note display too
}, [queryClient, triggerRefresh])
return {
refreshNotes,
refreshNotebooks,
refreshLabels,
// For direct query invalidation without triggering refresh
queryClient,
queryKeys,
}
}