'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, } }