diff --git a/src/App.tsx b/src/App.tsx index 62f66d0..f580bcd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import type { Note } from './types' +import type { NotePatch } from './types/note' import { useNotes } from './hooks/useNotes' import NoteList from './components/NoteList' import NoteEditor from './components/NoteEditor' @@ -21,7 +21,7 @@ function App() { setCreating(false) } - const handleUpdate = (id: number, patch: Partial>) => { + const handleUpdate = (id: number, patch: NotePatch) => { updateNote(id, patch) setSelectedId(null) } diff --git a/src/components/DeleteModal.tsx b/src/components/DeleteModal.tsx index 96d7bc2..abcd126 100644 --- a/src/components/DeleteModal.tsx +++ b/src/components/DeleteModal.tsx @@ -1,9 +1,4 @@ -interface DeleteModalProps { - open: boolean - title: string - onConfirm: () => void - onCancel: () => void -} +import type { DeleteModalProps } from '../interfaces/delete-modal' function DeleteModal({ open, title, onConfirm, onCancel }: DeleteModalProps) { if (!open) return null diff --git a/src/components/FloatingButton.tsx b/src/components/FloatingButton.tsx index 2ee5002..fc7d9ec 100644 --- a/src/components/FloatingButton.tsx +++ b/src/components/FloatingButton.tsx @@ -1,7 +1,4 @@ -interface FloatingButtonProps { - onClick: () => void - label?: string -} +import type { FloatingButtonProps } from '../interfaces/floating-button' function FloatingButton({ onClick, label = 'Créer une note' }: FloatingButtonProps) { return ( diff --git a/src/components/NoteEditor.test.tsx b/src/components/NoteEditor.test.tsx index 798e97d..bd2e31b 100644 --- a/src/components/NoteEditor.test.tsx +++ b/src/components/NoteEditor.test.tsx @@ -1,7 +1,7 @@ import { fireEvent, render, screen } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' import NoteEditor from './NoteEditor' -import type { Note } from '../types' +import type { Note } from '../types/note' const note: Note = { id: 42, title: 'Courses', content: 'Lait\nOeufs' } diff --git a/src/components/NoteEditor.tsx b/src/components/NoteEditor.tsx index a8d035b..e4e7db7 100644 --- a/src/components/NoteEditor.tsx +++ b/src/components/NoteEditor.tsx @@ -1,33 +1,10 @@ import { useState } from 'react' -import type { Note } from '../types' +import type { + NoteEditorProps, + NoteFormProps, +} from '../interfaces/note-editor' import DeleteModal from './DeleteModal' -interface EditEditorProps { - mode: 'edit' - note: Note - onUpdate: (id: number, patch: Partial>) => void - onDelete: (id: number) => void -} - -interface CreateEditorProps { - mode: 'create' - onCreate: (title: string, content: string) => void - onCancelCreate: () => void -} - -type NoteEditorProps = EditEditorProps | CreateEditorProps - -interface NoteFormProps { - title: string - content: string - titleMissing: boolean - cancelLabel: string - onTitleChange: (value: string) => void - onContentChange: (value: string) => void - onCancel: () => void - onSubmit: () => void -} - const TITLE_REQUIRED_MESSAGE = 'Le titre est obligatoire.' function NoteForm({ diff --git a/src/components/NoteList.test.tsx b/src/components/NoteList.test.tsx index 00894b4..eecbfc5 100644 --- a/src/components/NoteList.test.tsx +++ b/src/components/NoteList.test.tsx @@ -1,7 +1,7 @@ import { fireEvent, render, screen } from '@testing-library/react' import { describe, expect, it, vi } from 'vitest' import NoteList from './NoteList' -import type { Note } from '../types' +import type { Note } from '../types/note' const notes: Note[] = [ { id: 3, title: 'Courses', content: 'Lait' }, diff --git a/src/components/NoteList.tsx b/src/components/NoteList.tsx index 86c57c0..d5ee2b3 100644 --- a/src/components/NoteList.tsx +++ b/src/components/NoteList.tsx @@ -1,9 +1,4 @@ -import type { Note } from '../types' - -interface NoteListProps { - notes: Note[] - onSelect: (id: number) => void -} +import type { NoteListProps } from '../interfaces/note-list' const EMPTY_MESSAGE = 'Aucune note pour le moment.\nTouchez + pour en créer une.' diff --git a/src/hooks/useNotes.test.ts b/src/hooks/useNotes.test.ts index cb76d55..99caac2 100644 --- a/src/hooks/useNotes.test.ts +++ b/src/hooks/useNotes.test.ts @@ -2,7 +2,7 @@ import { act, renderHook } from '@testing-library/react' import { beforeEach, describe, expect, it, vi } from 'vitest' import { useNotes } from './useNotes' import { loadNotes } from '../lib/notesStorage' -import type { Note } from '../types' +import type { Note } from '../types/note' describe('useNotes', () => { beforeEach(() => { diff --git a/src/hooks/useNotes.ts b/src/hooks/useNotes.ts index a327491..5dfbb53 100644 --- a/src/hooks/useNotes.ts +++ b/src/hooks/useNotes.ts @@ -1,5 +1,5 @@ import { useCallback, useEffect, useMemo, useState } from 'react' -import type { Note } from '../types' +import type { Note, NotePatch } from '../types/note' import { loadNotes, saveNotes } from '../lib/notesStorage' export function useNotes() { @@ -15,7 +15,7 @@ export function useNotes() { return note }, []) - const updateNote = useCallback((id: number, patch: Partial>) => { + const updateNote = useCallback((id: number, patch: NotePatch) => { setNotes((current) => current.map((note) => (note.id === id ? { ...note, ...patch } : note))) }, []) diff --git a/src/lib/notesStorage.test.ts b/src/lib/notesStorage.test.ts index 037fa7f..d770b03 100644 --- a/src/lib/notesStorage.test.ts +++ b/src/lib/notesStorage.test.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it } from 'vitest' import { loadNotes, saveNotes } from './notesStorage' -import type { Note } from '../types' +import type { Note } from '../types/note' const STORAGE_KEY = 'notes' diff --git a/src/lib/notesStorage.ts b/src/lib/notesStorage.ts index 214c477..d09d29d 100644 --- a/src/lib/notesStorage.ts +++ b/src/lib/notesStorage.ts @@ -1,4 +1,4 @@ -import type { Note } from '../types' +import type { Note } from '../types/note' const STORAGE_KEY = 'notes' diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index ffb7c55..0000000 --- a/src/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface Note { - id: number - title: string - content: string -}