feat(notes): vues structurées tableau/kanban, flashcards et MCP robuste
Some checks failed
CI / Lint, Test & Build (push) Failing after 57s
CI / Deploy production (on server) (push) Has been skipped

Ajoute la base organisable par carnet (schéma, champs partagés, valeurs par note)
avec activation guidée, tableau éditable, kanban et suppression de colonnes.
Corrige le multiselect en vue tableau et enrichit sidebar, grille et i18n FR/EN.
Inclut aussi les améliorations flashcards SM-2, l'audit consentement IA et la
robustesse du serveur MCP (config, validation, rate-limit, métriques).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Antigravity
2026-05-24 23:03:16 +00:00
parent ecd7e57c2e
commit 0784c94242
63 changed files with 10133 additions and 619 deletions

View File

@@ -0,0 +1,139 @@
'use client'
import { useCallback, useEffect, useState } from 'react'
import type { NotebookSchemaPayload, NotePropertyValues } from '@/lib/structured-views/types'
type SchemaState = {
schema: NotebookSchemaPayload | null
noteValues: Record<string, NotePropertyValues>
loading: boolean
error: string | null
}
export function useNotebookSchema(notebookId: string | null | undefined) {
const [state, setState] = useState<SchemaState>({
schema: null,
noteValues: {},
loading: false,
error: null,
})
const reload = useCallback(async () => {
if (!notebookId) {
setState({ schema: null, noteValues: {}, loading: false, error: null })
return
}
setState((s) => ({ ...s, loading: true, error: null }))
try {
const res = await fetch(`/api/notebooks/${notebookId}/schema`)
const json = await res.json()
if (!res.ok || !json.success) {
throw new Error(json.error || 'Failed to load schema')
}
setState({
schema: json.data.schema,
noteValues: json.data.noteValues ?? {},
loading: false,
error: null,
})
} catch (e) {
setState((s) => ({
...s,
loading: false,
error: e instanceof Error ? e.message : 'Error',
}))
}
}, [notebookId])
useEffect(() => {
void reload()
}, [reload])
const enableStructuredMode = useCallback(async () => {
if (!notebookId) return null
const res = await fetch(`/api/notebooks/${notebookId}/schema`, { method: 'POST' })
const json = await res.json()
if (!res.ok || !json.success) throw new Error(json.error || 'Failed')
await reload()
return json.data.schema as NotebookSchemaPayload
}, [notebookId, reload])
const disableStructuredMode = useCallback(async () => {
if (!notebookId) return
const res = await fetch(`/api/notebooks/${notebookId}/schema`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'disable' }),
})
const json = await res.json()
if (!res.ok || !json.success) throw new Error(json.error || 'Failed')
await reload()
}, [notebookId, reload])
const addProperty = useCallback(
async (name: string, type: string, options?: string[]) => {
if (!notebookId) return null
const res = await fetch(`/api/notebooks/${notebookId}/schema`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'addProperty', name, type, options }),
})
const json = await res.json()
if (!res.ok || !json.success) throw new Error(json.error || 'Failed')
await reload()
return json.data.schema as NotebookSchemaPayload
},
[notebookId, reload],
)
const deleteProperty = useCallback(
async (propertyId: string) => {
if (!notebookId) return
const res = await fetch(`/api/notebooks/${notebookId}/schema`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'deleteProperty', propertyId }),
})
const json = await res.json()
if (!res.ok || !json.success) throw new Error(json.error || 'Failed')
await reload()
},
[notebookId, reload],
)
const setKanbanGroupProperty = useCallback(
async (propertyId: string | null) => {
if (!notebookId) return
const res = await fetch(`/api/notebooks/${notebookId}/schema`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'updateViewSettings', kanbanGroupPropertyId: propertyId }),
})
const json = await res.json()
if (!res.ok || !json.success) throw new Error(json.error || 'Failed')
await reload()
},
[notebookId, reload],
)
const patchNoteValuesLocal = useCallback((noteId: string, patch: NotePropertyValues) => {
setState((s) => ({
...s,
noteValues: {
...s.noteValues,
[noteId]: { ...(s.noteValues[noteId] ?? {}), ...patch },
},
}))
}, [])
return {
...state,
reload,
enableStructuredMode,
disableStructuredMode,
addProperty,
deleteProperty,
setKanbanGroupProperty,
patchNoteValuesLocal,
}
}