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>
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
'use client'
|
|
|
|
import { createContext, useContext, useState, useCallback, useMemo, type ReactNode } from 'react'
|
|
|
|
export type HomeUiControls = {
|
|
isTabsMode: boolean
|
|
openNoteComposer: () => void
|
|
}
|
|
|
|
interface EditorUIContextValue {
|
|
// HomeView controls
|
|
controls: HomeUiControls | null
|
|
setControls: (c: HomeUiControls | null) => void
|
|
|
|
// NotebookDrag controls
|
|
draggedNoteId: string | null
|
|
dragOverNotebookId: string | null
|
|
startDrag: (noteId: string) => void
|
|
endDrag: () => void
|
|
dragOver: (notebookId: string | null) => void
|
|
isDragging: boolean
|
|
isDragOver: boolean
|
|
}
|
|
|
|
const EditorUIContext = createContext<EditorUIContextValue | null>(null)
|
|
|
|
export function EditorUIProvider({ children }: { children: ReactNode }) {
|
|
// HomeView state
|
|
const [controls, setControls] = useState<HomeUiControls | null>(null)
|
|
|
|
// NotebookDrag state
|
|
const [draggedNoteId, setDraggedNoteId] = useState<string | null>(null)
|
|
const [dragOverNotebookId, setDragOverNotebookId] = useState<string | null>(null)
|
|
|
|
const startDrag = useCallback((noteId: string) => {
|
|
setDraggedNoteId(noteId)
|
|
}, [])
|
|
|
|
const endDrag = useCallback(() => {
|
|
setDraggedNoteId(null)
|
|
setDragOverNotebookId(null)
|
|
}, [])
|
|
|
|
const dragOver = useCallback((notebookId: string | null) => {
|
|
setDragOverNotebookId(notebookId)
|
|
}, [])
|
|
|
|
const isDragging = draggedNoteId !== null
|
|
const isDragOver = dragOverNotebookId !== null
|
|
|
|
const value = useMemo<EditorUIContextValue>(() => ({
|
|
controls,
|
|
setControls,
|
|
draggedNoteId,
|
|
dragOverNotebookId,
|
|
startDrag,
|
|
endDrag,
|
|
dragOver,
|
|
isDragging,
|
|
isDragOver,
|
|
}), [controls, draggedNoteId, dragOverNotebookId, startDrag, endDrag, dragOver, isDragging, isDragOver])
|
|
|
|
return <EditorUIContext.Provider value={value}>{children}</EditorUIContext.Provider>
|
|
}
|
|
|
|
export function useEditorUI() {
|
|
const ctx = useContext(EditorUIContext)
|
|
if (!ctx) throw new Error('useEditorUI must be used within EditorUIProvider')
|
|
return ctx
|
|
}
|
|
|
|
export function useEditorUIOptional(): EditorUIContextValue | null {
|
|
return useContext(EditorUIContext)
|
|
} |