- Fix createNotebookOptimistic to call loadNotebooks() + triggerRefresh() after POST, so new notebooks appear immediately without page reload - Remove window.location.reload() from delete-notebook-dialog (context already handles state refresh) - Rewrite edit-notebook-dialog to use updateNotebook() from context instead of raw fetch + full page reload - Fix NoteRefreshContext: remove refreshKey from useCallback deps to prevent unstable triggerRefresh callback cascade - Fix notebook actions menu visibility: consolidate NotebookActions and expand button into single positioned container with proper z-index - Add actions menu to active/selected notebook (was previously missing) - Use proper Notebook type instead of any in sidebar components - Increase button pr-20 to pr-24 to reserve space for actions - Remove redundant router.refresh() from create-notebook-dialog Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
33 lines
836 B
TypeScript
33 lines
836 B
TypeScript
'use client'
|
|
|
|
import { createContext, useContext, useState, useCallback } from 'react'
|
|
|
|
interface NoteRefreshContextType {
|
|
refreshKey: number
|
|
triggerRefresh: () => void
|
|
}
|
|
|
|
const NoteRefreshContext = createContext<NoteRefreshContextType | undefined>(undefined)
|
|
|
|
export function NoteRefreshProvider({ children }: { children: React.ReactNode }) {
|
|
const [refreshKey, setRefreshKey] = useState(0)
|
|
|
|
const triggerRefresh = useCallback(() => {
|
|
setRefreshKey(prev => prev + 1)
|
|
}, [])
|
|
|
|
return (
|
|
<NoteRefreshContext.Provider value={{ refreshKey, triggerRefresh }}>
|
|
{children}
|
|
</NoteRefreshContext.Provider>
|
|
)
|
|
}
|
|
|
|
export function useNoteRefresh() {
|
|
const context = useContext(NoteRefreshContext)
|
|
if (!context) {
|
|
throw new Error('useNoteRefresh must be used within NoteRefreshProvider')
|
|
}
|
|
return context
|
|
}
|