feat(notes): add note deletion with confirmation
This commit is contained in:
1 parent
0976c51cc1
commit
0af0cdc405
4 files changed
+142
-4
No files matched your search
@@ -1,13 +1,16 @@
|
||||
import { useState } from 'react'
|
||||
import type { Note } from '../types'
|
||||
import DeleteModal from './DeleteModal'
|
||||
|
||||
interface NoteEditorProps {
|
||||
note: Note
|
||||
onUpdate: (id: number, patch: Partial<Pick<Note, 'title' | 'content'>>) => void
|
||||
onDelete: (id: number) => void
|
||||
}
|
||||
|
||||
function NoteEditor({ note, onUpdate }: NoteEditorProps) {
|
||||
function NoteEditor({ note, onUpdate, onDelete }: NoteEditorProps) {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [confirmDelete, setConfirmDelete] = useState(false)
|
||||
const [title, setTitle] = useState(note.title)
|
||||
const [content, setContent] = useState(note.content)
|
||||
|
||||
@@ -71,7 +74,17 @@ function NoteEditor({ note, onUpdate }: NoteEditorProps) {
|
||||
|
||||
return (
|
||||
<article className="flex flex-col gap-4">
|
||||
<h2 className="text-2xl font-semibold">{note.title || 'Sans titre'}</h2>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<h2 className="text-2xl font-semibold">{note.title || 'Sans titre'}</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setConfirmDelete(true)}
|
||||
aria-label="Supprimer la note"
|
||||
className="px-2 py-1 rounded text-gray-600 hover:text-red-600"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<p className="whitespace-pre-wrap">
|
||||
{note.content || <span className="text-gray-400 italic">Note vide</span>}
|
||||
</p>
|
||||
@@ -84,6 +97,15 @@ function NoteEditor({ note, onUpdate }: NoteEditorProps) {
|
||||
Éditer
|
||||
</button>
|
||||
</div>
|
||||
<DeleteModal
|
||||
open={confirmDelete}
|
||||
title={note.title}
|
||||
onConfirm={() => {
|
||||
setConfirmDelete(false)
|
||||
onDelete(note.id)
|
||||
}}
|
||||
onCancel={() => setConfirmDelete(false)}
|
||||
/>
|
||||
</article>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user