fix: update masonry grid sizing logic and notebook list padding

This commit is contained in:
Sepehr Ramezani
2026-02-14 14:20:32 +01:00
parent a0ffc9043b
commit 8f9031f076
580 changed files with 9789 additions and 42619 deletions

View File

@@ -3,6 +3,7 @@
import { createContext, useContext, useState, useEffect, useMemo, useCallback } from 'react'
import type { Notebook, Label, Note } from '@/lib/types'
import { useNoteRefresh } from './NoteRefreshContext'
import { toast } from 'sonner'
// ===== INPUT TYPES =====
export interface CreateNotebookInput {
@@ -35,6 +36,7 @@ export interface NotebooksContextValue {
currentNotebook: Notebook | null // null = "Notes générales"
currentLabels: Label[] // Labels du notebook actuel
isLoading: boolean
isMovingNote: boolean
error: string | null
// Actions: Notebooks
@@ -77,6 +79,7 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
const [notebooks, setNotebooks] = useState<Notebook[]>(initialNotebooks)
const [currentNotebook, setCurrentNotebook] = useState<Notebook | null>(null)
const [isLoading, setIsLoading] = useState(true)
const [isMovingNote, setIsMovingNote] = useState(false)
const [error, setError] = useState<string | null>(null)
const { triggerRefresh } = useNoteRefresh() // Get triggerRefresh from context
@@ -137,9 +140,9 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
throw new Error('Failed to update notebook')
}
// Recharger les notebooks après mise à jour
window.location.reload()
}, [])
await loadNotebooks()
triggerRefresh()
}, [loadNotebooks, triggerRefresh])
const deleteNotebook = useCallback(async (notebookId: string) => {
const response = await fetch(`/api/notebooks/${notebookId}`, {
@@ -150,9 +153,9 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
throw new Error('Failed to delete notebook')
}
// Recharger les notebooks après suppression
window.location.reload()
}, [])
await loadNotebooks()
triggerRefresh()
}, [loadNotebooks, triggerRefresh])
const updateNotebookOrderOptimistic = useCallback(async (notebookIds: string[]) => {
const response = await fetch('/api/notebooks/reorder', {
@@ -165,9 +168,9 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
throw new Error('Failed to update notebook order')
}
// Recharger les notebooks après mise à jour
window.location.reload()
}, [])
await loadNotebooks()
triggerRefresh()
}, [loadNotebooks, triggerRefresh])
// ===== ACTIONS: LABELS =====
const createLabel = useCallback(async (data: CreateLabelInput) => {
@@ -209,21 +212,26 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
// ===== ACTIONS: NOTES =====
const moveNoteToNotebookOptimistic = useCallback(async (noteId: string, notebookId: string | null) => {
const response = await fetch(`/api/notes/${noteId}/move`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId }),
})
setIsMovingNote(true)
try {
const response = await fetch(`/api/notes/${noteId}/move`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ notebookId }),
})
if (!response.ok) {
throw new Error('Failed to move note')
if (!response.ok) {
throw new Error('Failed to move note')
}
await loadNotebooks()
triggerRefresh()
} catch (error) {
toast.error('Failed to move note. Please try again.')
throw error
} finally {
setIsMovingNote(false)
}
// Reload notebooks to update note counts
await loadNotebooks()
// CRITICAL: Trigger UI refresh to update notes display
triggerRefresh()
}, [loadNotebooks, triggerRefresh])
// ===== ACTIONS: AI (STUBS) =====
@@ -243,6 +251,7 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
currentNotebook,
currentLabels,
isLoading,
isMovingNote,
error,
createNotebookOptimistic,
updateNotebook,
@@ -260,6 +269,7 @@ export function NotebooksProvider({ children, initialNotebooks = [] }: Notebooks
currentNotebook,
currentLabels,
isLoading,
isMovingNote,
error,
createNotebookOptimistic,
updateNotebook,