fix(sidebar): eliminate full page reloads and fix notebook actions visibility

- 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>
This commit is contained in:
Sepehr Ramezani
2026-03-29 22:23:25 +02:00
parent 8daf50ac3f
commit 806f4c4eeb
7 changed files with 106 additions and 114 deletions

View File

@@ -14,7 +14,7 @@ export function NoteRefreshProvider({ children }: { children: React.ReactNode })
const triggerRefresh = useCallback(() => {
setRefreshKey(prev => prev + 1)
}, [refreshKey])
}, [])
return (
<NoteRefreshContext.Provider value={{ refreshKey, triggerRefresh }}>

View File

@@ -40,7 +40,7 @@ export interface NotebooksContextValue {
error: string | null
// Actions: Notebooks
createNotebookOptimistic: (data: CreateNotebookInput) => Promise<Notebook>
createNotebookOptimistic: (data: CreateNotebookInput) => Promise<void>
updateNotebook: (notebookId: string, data: UpdateNotebookInput) => Promise<void>
deleteNotebook: (notebookId: string) => Promise<void>
updateNotebookOrderOptimistic: (notebookIds: string[]) => Promise<void>
@@ -114,7 +114,6 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
// ===== ACTIONS: NOTEBOOKS =====
const createNotebookOptimistic = useCallback(async (data: CreateNotebookInput) => {
// Server action sera implémenté plus tard
const response = await fetch('/api/notebooks', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -125,9 +124,10 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
throw new Error('Failed to create notebook')
}
const result = await response.json()
return result
}, [])
// Reload notebooks from server to update sidebar state
await loadNotebooks()
triggerRefresh()
}, [loadNotebooks, triggerRefresh])
const updateNotebook = useCallback(async (notebookId: string, data: UpdateNotebookInput) => {
const response = await fetch(`/api/notebooks/${notebookId}`, {