From ad950be46447a74e523eeb2bd278641600dff2fb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 31 Dec 2025 13:40:59 +0900 Subject: feat(client): group cards by note in DeckDetailPage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Display note-based cards as grouped items showing all cards generated from the same note, with note-level edit/delete actions. Legacy cards without note association are shown separately with a "Legacy" badge. - Add NoteGroupCard component for displaying note groups with card stats - Add LegacyCardItem component for backward-compatible card display - Add DeleteNoteModal for deleting notes and their cards - Show Normal/Reversed badges for cards within note groups 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/client/components/DeleteNoteModal.tsx | 152 ++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/client/components/DeleteNoteModal.tsx (limited to 'src/client/components/DeleteNoteModal.tsx') diff --git a/src/client/components/DeleteNoteModal.tsx b/src/client/components/DeleteNoteModal.tsx new file mode 100644 index 0000000..8eec124 --- /dev/null +++ b/src/client/components/DeleteNoteModal.tsx @@ -0,0 +1,152 @@ +import { useState } from "react"; +import { ApiClientError, apiClient } from "../api"; + +interface DeleteNoteModalProps { + isOpen: boolean; + deckId: string; + noteId: string | null; + onClose: () => void; + onNoteDeleted: () => void; +} + +export function DeleteNoteModal({ + isOpen, + deckId, + noteId, + onClose, + onNoteDeleted, +}: DeleteNoteModalProps) { + const [error, setError] = useState(null); + const [isDeleting, setIsDeleting] = useState(false); + + const handleClose = () => { + setError(null); + onClose(); + }; + + const handleDelete = async () => { + if (!noteId) return; + + setError(null); + setIsDeleting(true); + + try { + const authHeader = apiClient.getAuthHeader(); + if (!authHeader) { + throw new ApiClientError("Not authenticated", 401); + } + + const res = await fetch(`/api/decks/${deckId}/notes/${noteId}`, { + method: "DELETE", + headers: authHeader, + }); + + if (!res.ok) { + const errorBody = await res.json().catch(() => ({})); + throw new ApiClientError( + (errorBody as { error?: string }).error || + `Request failed with status ${res.status}`, + res.status, + ); + } + + onNoteDeleted(); + onClose(); + } catch (err) { + if (err instanceof ApiClientError) { + setError(err.message); + } else { + setError("Failed to delete note. Please try again."); + } + } finally { + setIsDeleting(false); + } + }; + + if (!isOpen || !noteId) { + return null; + } + + return ( +
{ + if (e.target === e.currentTarget) { + handleClose(); + } + }} + onKeyDown={(e) => { + if (e.key === "Escape") { + handleClose(); + } + }} + > +
+
+
+ +
+ +

+ Delete Note +

+ + {error && ( +
+ {error} +
+ )} + +

+ Are you sure you want to delete this note? +

+

+ This will delete all cards generated from this note. This action + cannot be undone. +

+ +
+ + +
+
+
+
+ ); +} -- cgit v1.2.3-70-g09d2