feat(notes): return to list after saving a note

This commit is contained in:
devcodetools committed 2026-09-13 16:31:43 +02:00
1 parent c52705ca01
commit 37ace9cab2
3 files changed
+12 -8

No files matched your search

+2 -3
View File
@@ -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' },
])
+8 -3
View File
@@ -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<Pick<Note, 'title' | 'content'>>) => {
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}
/>
) : (
+2 -2
View File
@@ -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 (
<div className="flex flex-col items-center justify-center gap-2 py-16 text-center">
<p className="text-gray-500">{EMPTY_MESSAGE}</p>
<p className="whitespace-pre-line text-gray-500">{EMPTY_MESSAGE}</p>
</div>
)
}