From 38b8fc0e9927c4146b4c8b309b2bcc644abd63d0 Mon Sep 17 00:00:00 2001
From: nsfisis <nsfisis@gmail.com>
Date: Wed, 25 Feb 2026 23:02:35 +0900
Subject: feat(decks): add default note type setting per deck

Allow each deck to specify a default note type that is auto-selected
when creating new notes. Includes DB schema migration, server API
updates, sync layer support, and UI for editing the default in the
deck settings modal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---
 src/client/components/CreateNoteModal.tsx | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

(limited to 'src/client/components/CreateNoteModal.tsx')

diff --git a/src/client/components/CreateNoteModal.tsx b/src/client/components/CreateNoteModal.tsx
index 912aea8..cc39bf6 100644
--- a/src/client/components/CreateNoteModal.tsx
+++ b/src/client/components/CreateNoteModal.tsx
@@ -27,6 +27,7 @@ interface NoteTypeSummary {
 interface CreateNoteModalProps {
 	isOpen: boolean;
 	deckId: string;
+	defaultNoteTypeId?: string | null;
 	onClose: () => void;
 	onNoteCreated: () => void;
 }
@@ -34,6 +35,7 @@ interface CreateNoteModalProps {
 export function CreateNoteModal({
 	isOpen,
 	deckId,
+	defaultNoteTypeId,
 	onClose,
 	onNoteCreated,
 }: CreateNoteModalProps) {
@@ -88,10 +90,13 @@ export function CreateNoteModal({
 			setNoteTypes(data.noteTypes);
 			setHasLoadedNoteTypes(true);
 
-			// Auto-select first note type if available
-			const firstNoteType = data.noteTypes[0];
-			if (firstNoteType) {
-				await fetchNoteTypeDetails(firstNoteType.id);
+			// Auto-select default note type if specified, otherwise first
+			const targetNoteType =
+				(defaultNoteTypeId &&
+					data.noteTypes.find((nt) => nt.id === defaultNoteTypeId)) ||
+				data.noteTypes[0];
+			if (targetNoteType) {
+				await fetchNoteTypeDetails(targetNoteType.id);
 			}
 		} catch (err) {
 			if (err instanceof ApiClientError) {
@@ -102,7 +107,7 @@ export function CreateNoteModal({
 		} finally {
 			setIsLoadingNoteTypes(false);
 		}
-	}, [fetchNoteTypeDetails]);
+	}, [fetchNoteTypeDetails, defaultNoteTypeId]);
 
 	useEffect(() => {
 		if (isOpen && !hasLoadedNoteTypes) {
-- 
cgit v1.3-1-g0d28

