Files
Momento/memento-note/components/structured-views/structured-views-container.tsx
Antigravity 0784c94242
Some checks failed
CI / Lint, Test & Build (push) Failing after 57s
CI / Deploy production (on server) (push) Has been skipped
feat(notes): vues structurées tableau/kanban, flashcards et MCP robuste
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>
2026-05-24 23:03:16 +00:00

106 lines
2.9 KiB
TypeScript

'use client'
import { useCallback, useRef } from 'react'
import type { Note } from '@/lib/types'
import type { NotebookSchemaPayload, NotePropertyValues, StructuredViewMode } from '@/lib/structured-views/types'
import { NotesStructuredTable } from './notes-structured-table'
import { NotesKanbanView } from './notes-kanban-view'
import { NotesGalleryView } from './notes-gallery-view'
type StructuredViewsContainerProps = {
mode: StructuredViewMode
notes: Note[]
schema: NotebookSchemaPayload
noteValues: Record<string, NotePropertyValues>
notebookColor?: string | null
onOpen: (note: Note) => void
onNoteValuesPatch: (noteId: string, patch: NotePropertyValues) => void
onCreateNote: (prefill: Record<string, unknown>) => void
onSetKanbanGroupProperty: (propertyId: string) => void
onQuickAddKanbanStatus?: () => void
onDeleteProperty?: (propertyId: string) => Promise<void>
}
export function StructuredViewsContainer({
mode,
notes,
schema,
noteValues,
notebookColor,
onOpen,
onNoteValuesPatch,
onCreateNote,
onSetKanbanGroupProperty,
onQuickAddKanbanStatus,
onDeleteProperty,
}: StructuredViewsContainerProps) {
const timersRef = useRef<Map<string, ReturnType<typeof setTimeout>>>(new Map())
const saveProperty = useCallback(
(noteId: string, propertyId: string, value: unknown) => {
onNoteValuesPatch(noteId, { [propertyId]: value })
const key = `${noteId}:${propertyId}`
const existing = timersRef.current.get(key)
if (existing) clearTimeout(existing)
timersRef.current.set(
key,
setTimeout(async () => {
try {
await fetch(`/api/notes/${noteId}/properties`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ properties: { [propertyId]: value } }),
})
} catch (e) {
console.error(e)
}
timersRef.current.delete(key)
}, 500),
)
},
[onNoteValuesPatch],
)
if (mode === 'table') {
return (
<NotesStructuredTable
notes={notes}
schema={schema}
noteValues={noteValues}
onOpen={onOpen}
onPropertyChange={saveProperty}
onDeleteProperty={onDeleteProperty}
/>
)
}
if (mode === 'kanban') {
return (
<NotesKanbanView
notes={notes}
schema={schema}
noteValues={noteValues}
onOpen={onOpen}
onPropertyChange={saveProperty}
onCreateNote={onCreateNote}
onSetGroupProperty={onSetKanbanGroupProperty}
onQuickAddKanbanStatus={onQuickAddKanbanStatus}
/>
)
}
if (mode === 'gallery') {
return (
<NotesGalleryView
notes={notes}
schema={schema}
noteValues={noteValues}
notebookColor={notebookColor}
onOpen={onOpen}
/>
)
}
return null
}