feat(notes): wire app with floating add button

This commit is contained in:
devcodetools committed 2026-09-13 15:34:50 +02:00
1 parent 0af0cdc405
commit 9a086cbe7b
5 files changed
+213 -7

No files matched your search

+64 -1
View File
@@ -1,5 +1,68 @@
import { useState } from 'react'
import { useNotes } from './hooks/useNotes'
import NoteList from './components/NoteList'
import NoteEditor from './components/NoteEditor'
import FloatingButton from './components/FloatingButton'
function App() {
return <main></main>
const { notes, addNote, updateNote, deleteNote } = useNotes()
const [selectedId, setSelectedId] = useState<number | null>(null)
const [createdId, setCreatedId] = useState<number | null>(null)
const selectedNote = notes.find((note) => note.id === selectedId) ?? null
const createNote = () => {
const note = addNote()
setSelectedId(note.id)
setCreatedId(note.id)
}
const handleUpdate = (id: number, patch: Parameters<typeof updateNote>[1]) => {
updateNote(id, patch)
if (id === createdId) setCreatedId(null)
}
const handleDelete = (id: number) => {
deleteNote(id)
setSelectedId(null)
}
return (
<main className="mx-auto w-full max-w-2xl flex flex-col min-h-screen">
<header className="sticky top-0 bg-white border-b border-gray-200 px-4 py-3">
{selectedNote ? (
<div className="flex items-center gap-2">
<button
type="button"
onClick={() => setSelectedId(null)}
aria-label="Retour"
className="w-10 h-10 rounded-full text-xl hover:bg-gray-100"
>
←
</button>
<h1 className="text-lg font-semibold">Notes</h1>
</div>
) : (
<h1 className="text-lg font-semibold">Notes</h1>
)}
</header>
<section className="flex-1 px-4 py-4">
{selectedNote ? (
<NoteEditor
note={selectedNote}
onUpdate={handleUpdate}
onDelete={handleDelete}
autoEdit={selectedId === createdId}
/>
) : (
<NoteList notes={notes} onSelect={setSelectedId} />
)}
</section>
<FloatingButton onClick={createNote} />
</main>
)
}
export default App