Files
Momento/memento-note/components/archive-client.tsx
Antigravity e2672cd2c2
Some checks failed
CI / Lint, Test & Build (push) Failing after 1m19s
CI / Deploy production (on server) (push) Has been skipped
feat(notes): liens internes, onglet Réseau, living blocks et consentement IA
Rend les liens entre notes visibles et persistants (sync NoteLink au save, auto-save, graphe réseau rafraîchi), ajoute living blocks, Memory Echo, recherche globale, consentement IA explicite et consolide les prototypes design en architectural-grid.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 14:27:29 +00:00

89 lines
2.7 KiB
TypeScript

'use client'
import { useState, useCallback } from 'react'
import dynamic from 'next/dynamic'
import type { Note } from '@/lib/types'
import { NotesEditorialView } from '@/components/notes-editorial-view'
import { getNoteById, deleteNote, toggleArchive } from '@/app/actions/notes'
import { emitNoteChange } from '@/lib/note-change-sync'
import { toast } from 'sonner'
import { useLanguage } from '@/lib/i18n'
const NoteEditor = dynamic(
() => import('@/components/note-editor').then(m => ({ default: m.NoteEditor })),
{ ssr: false }
)
interface ArchiveClientProps {
notes: Note[]
}
export function ArchiveClient({ notes: initialNotes }: ArchiveClientProps) {
const { t } = useLanguage()
const [notes, setNotes] = useState<Note[]>(initialNotes)
const [editingNote, setEditingNote] = useState<{ note: Note; readOnly: boolean } | null>(null)
const handleOpen = useCallback(async (note: Note, readOnly = false) => {
const fresh = await getNoteById(note.id)
if (fresh) setEditingNote({ note: fresh, readOnly })
}, [])
const handleClose = useCallback(() => {
setEditingNote(null)
}, [])
const handleArchiveNote = useCallback(async (note: Note) => {
const nextArchived = !note.isArchived
if (nextArchived) {
setNotes((prev) => prev.filter((n) => n.id !== note.id))
}
try {
await toggleArchive(note.id, nextArchived, { skipRevalidation: true })
emitNoteChange({ type: 'updated', note: { ...note, isArchived: nextArchived } })
toast.success(
nextArchived ? (t('notes.archived') || 'Archivée') : (t('notes.unarchived') || 'Désarchivée')
)
} catch {
if (nextArchived) setNotes((prev) => [note, ...prev])
toast.error(t('general.error'))
}
}, [t])
const handleDeleteNote = useCallback(async (note: Note) => {
setNotes((prev) => prev.filter((n) => n.id !== note.id))
try {
await deleteNote(note.id, { skipRevalidation: true })
emitNoteChange({ type: 'deleted', noteId: note.id, notebookId: note.notebookId })
toast.success(t('notes.deleted') || 'Note supprimée')
} catch {
setNotes((prev) => [note, ...prev])
toast.error(t('general.error'))
}
}, [t])
if (editingNote) {
return (
<NoteEditor
note={editingNote.note}
readOnly={editingNote.readOnly}
onClose={handleClose}
onNoteSaved={(saved) => {
setNotes((prev) => prev.map((n) => (n.id === saved.id ? { ...n, ...saved } : n)))
emitNoteChange({ type: 'updated', note: saved })
}}
fullPage
/>
)
}
return (
<NotesEditorialView
notes={notes}
onOpen={handleOpen}
onArchiveNote={handleArchiveNote}
onDeleteNote={handleDeleteNote}
/>
)
}