From 37ace9cab239d88288cf12ccd50f5d47264cc6a8 Mon Sep 17 00:00:00 2001 From: gilles Date: Sun, 13 Sep 2026 16:31:43 +0200 Subject: [PATCH] feat(notes): return to list after saving a note --- src/App.test.tsx | 5 ++--- src/App.tsx | 11 ++++++++--- src/components/NoteList.tsx | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index 7a00161..d181ba8 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -57,9 +57,7 @@ describe('App', () => { fireEvent.change(screen.getByLabelText('Contenu'), { target: { value: 'Lait' } }) fireEvent.click(screen.getByRole('button', { name: 'Enregistrer' })) - expect(screen.getByText('Courses')).toBeInTheDocument() - expect(screen.getByText('Lait')).toBeInTheDocument() - expect(screen.getByRole('button', { name: 'Éditer' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: 'Ouvrir la note Courses' })).toBeInTheDocument() expect(JSON.parse(localStorage.getItem('notes')!)).toEqual([ { id: 1234, title: 'Courses', content: 'Lait' }, ]) @@ -150,6 +148,7 @@ describe('App', () => { fireEvent.change(screen.getByLabelText('Titre'), { target: { value: 'Après' } }) fireEvent.click(screen.getByRole('button', { name: 'Enregistrer' })) + expect(screen.getByRole('button', { name: 'Ouvrir la note Après' })).toBeInTheDocument() expect(JSON.parse(localStorage.getItem('notes')!)).toEqual([ { id: 1, title: 'Après', content: 'x' }, ]) diff --git a/src/App.tsx b/src/App.tsx index 6b431a7..62f66d0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,5 @@ import { useState } from 'react' +import type { Note } from './types' import { useNotes } from './hooks/useNotes' import NoteList from './components/NoteList' import NoteEditor from './components/NoteEditor' @@ -16,9 +17,13 @@ function App() { const cancelCreate = () => setCreating(false) const handleCreate = (title: string, content: string) => { - const note = addNote(title, content) + addNote(title, content) setCreating(false) - setSelectedId(note.id) + } + + const handleUpdate = (id: number, patch: Partial>) => { + updateNote(id, patch) + setSelectedId(null) } const handleDelete = (id: number) => { @@ -64,7 +69,7 @@ function App() { key={selectedNote.id} mode="edit" note={selectedNote} - onUpdate={updateNote} + onUpdate={handleUpdate} onDelete={handleDelete} /> ) : ( diff --git a/src/components/NoteList.tsx b/src/components/NoteList.tsx index 3fc3976..86c57c0 100644 --- a/src/components/NoteList.tsx +++ b/src/components/NoteList.tsx @@ -5,13 +5,13 @@ interface NoteListProps { onSelect: (id: number) => void } -const EMPTY_MESSAGE = 'Aucune note pour le moment. Touchez + pour en créer une.' +const EMPTY_MESSAGE = 'Aucune note pour le moment.\nTouchez + pour en créer une.' function NoteList({ notes, onSelect }: NoteListProps) { if (notes.length === 0) { return (
-

{EMPTY_MESSAGE}

+

{EMPTY_MESSAGE}

) }