diff --git a/.next/dev/cache/turbopack/23c46498/CURRENT b/.next/dev/cache/turbopack/23c46498/CURRENT index 187cfc9..8ddf084 100644 Binary files a/.next/dev/cache/turbopack/23c46498/CURRENT and b/.next/dev/cache/turbopack/23c46498/CURRENT differ diff --git a/.next/dev/cache/turbopack/23c46498/LOG b/.next/dev/cache/turbopack/23c46498/LOG index 5538d19..9d93da8 100644 --- a/.next/dev/cache/turbopack/23c46498/LOG +++ b/.next/dev/cache/turbopack/23c46498/LOG @@ -6122,3 +6122,9 @@ FAM | META SEQ | SST SEQ | RANGE 0 | 00014933 | 00014932 SST | [=======================================================================] | 3aefa6fd5cf2deb4-f42f94001fcb5351 (0 MiB, fresh) 1 | 00014934 | 00014930 SST | O | 3ffdfb3b7d50fcf1-3ffdfb3b7d50fcf1 (0 MiB, fresh) 2 | 00014935 | 00014931 SST | O | 3ffdfb3b7d50fcf1-3ffdfb3b7d50fcf1 (0 MiB, fresh) +Time 2026-03-06T10:28:56.8886436Z +Commit 00015705 4 keys in 7ms 974µs 900ns +FAM | META SEQ | SST SEQ | RANGE + 0 | 00015703 | 00015702 SST | [=======================================================================] | 3aefa6fd5cf2deb4-f42f94001fcb5351 (0 MiB, fresh) + 1 | 00015704 | 00015700 SST | O | 3ffdfb3b7d50fcf1-3ffdfb3b7d50fcf1 (0 MiB, fresh) + 2 | 00015705 | 00015701 SST | O | 3ffdfb3b7d50fcf1-3ffdfb3b7d50fcf1 (0 MiB, fresh) diff --git a/next-env.d.ts b/next-env.d.ts index 9edff1c..c4b7818 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,6 +1,6 @@ /// /// -import "./.next/types/routes.d.ts"; +import "./.next/dev/types/routes.d.ts"; // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/src/app/api/chapters/[id]/route.ts b/src/app/api/chapters/[id]/route.ts index 8df77fa..1f06f66 100644 --- a/src/app/api/chapters/[id]/route.ts +++ b/src/app/api/chapters/[id]/route.ts @@ -36,6 +36,13 @@ export async function PUT( }, }); + // Update writing streak if content was explicitly updated + if (body.content !== undefined) { + import('@/lib/streak').then(({ updateWritingStreak }) => { + updateWritingStreak(session.user.id).catch(console.error); + }); + } + return NextResponse.json(updated); } diff --git a/src/app/api/chapters/route.ts b/src/app/api/chapters/route.ts index 943e7ca..70e183a 100644 --- a/src/app/api/chapters/route.ts +++ b/src/app/api/chapters/route.ts @@ -34,5 +34,10 @@ export async function POST(request: NextRequest) { }, }); + // Update writing streak + import('@/lib/streak').then(({ updateWritingStreak }) => { + updateWritingStreak(session.user.id).catch(console.error); + }); + return NextResponse.json(chapter, { status: 201 }); } \ No newline at end of file diff --git a/src/components/BookSettings.tsx b/src/components/BookSettings.tsx index 563d414..0fc2451 100644 --- a/src/components/BookSettings.tsx +++ b/src/components/BookSettings.tsx @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react'; import { BookProject, BookSettings } from '@/lib/types'; import { GENRES, TONES, POV_OPTIONS, TENSE_OPTIONS } from '@/lib/constants'; -import { Settings, Book, Feather, Users, Clock, Target, Hash } from 'lucide-react'; +import { Settings, Book, Feather, Users, Clock, Target, Hash, Save, Check } from 'lucide-react'; import { useLanguage } from '@/providers/LanguageProvider'; import { TranslationKey } from '@/lib/i18n/translations'; @@ -26,37 +26,73 @@ const DEFAULT_SETTINGS: BookSettings = { const BookSettingsComponent: React.FC = ({ project, onUpdate, onDeleteProject }) => { const { t } = useLanguage(); - const [settings, setSettings] = useState(project.settings || DEFAULT_SETTINGS); + + // Local state for all editable fields to prevent excessive API calls + const [localTitle, setLocalTitle] = useState(project.title); + const [localAuthor, setLocalAuthor] = useState(project.author); + const [localStyleGuide, setLocalStyleGuide] = useState(project.styleGuide || ''); + const [localSettings, setLocalSettings] = useState(project.settings || DEFAULT_SETTINGS); + const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); + const [isSaving, setIsSaving] = useState(false); + const [showSavedFeedback, setShowSavedFeedback] = useState(false); useEffect(() => { + setLocalTitle(project.title); + setLocalAuthor(project.author); + setLocalStyleGuide(project.styleGuide || ''); if (project.settings) { - setSettings(project.settings); + setLocalSettings(project.settings); } - }, [project.settings]); + }, [project.title, project.author, project.styleGuide, project.settings]); const handleChange = (key: keyof BookSettings, value: string) => { - const newSettings = { ...settings, [key]: value }; - setSettings(newSettings); - onUpdate({ ...project, settings: newSettings }); + setLocalSettings(prev => ({ ...prev, [key]: value })); }; - const handleStyleGuideChange = (value: string) => { - onUpdate({ ...project, styleGuide: value }); + const handleSave = () => { + setIsSaving(true); + onUpdate({ + ...project, + title: localTitle, + author: localAuthor, + styleGuide: localStyleGuide, + settings: localSettings + }); + + // Simulate save delay for UI feedback + setTimeout(() => { + setIsSaving(false); + setShowSavedFeedback(true); + setTimeout(() => setShowSavedFeedback(false), 2000); + }, 500); }; return (
-
+
-
-
- -
-
-

{t('book_settings.title')}

-

{t('book_settings.subtitle')}

+
+
+
+ +
+
+

{t('book_settings.title')}

+

{t('book_settings.subtitle')}

+
+
@@ -69,8 +105,8 @@ const BookSettingsComponent: React.FC = ({ project, onUpdate, onUpdate({ ...project, title: e.target.value })} + value={localTitle} + onChange={(e) => setLocalTitle(e.target.value)} className="w-full p-2.5 bg-theme-bg text-theme-text border border-theme-border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none font-serif font-bold text-lg transition-colors duration-300" />
@@ -78,8 +114,8 @@ const BookSettingsComponent: React.FC = ({ project, onUpdate, onUpdate({ ...project, author: e.target.value })} + value={localAuthor} + onChange={(e) => setLocalAuthor(e.target.value)} className="w-full p-2.5 bg-theme-bg text-theme-text border border-theme-border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none transition-colors duration-300" />
@@ -87,7 +123,7 @@ const BookSettingsComponent: React.FC = ({ project, onUpdate,