diff --git a/app/api/add-page/route.ts b/app/api/add-page/route.ts index 6bdcc21..08508ed 100644 --- a/app/api/add-page/route.ts +++ b/app/api/add-page/route.ts @@ -10,7 +10,6 @@ import { getNextPageNumber, getStoryWithPagesBySlug, getLastPageImage, - getStoryCharacterImages, } from "@/lib/db-actions"; import { freeTierRateLimit } from "@/lib/rate-limit"; import { uploadImageToS3 } from "@/lib/s3-upload"; @@ -134,11 +133,8 @@ export async function POST(request: NextRequest) { } } - // Get story character images (up to 2 most recent) - const storyCharacterImages = await getStoryCharacterImages(story.id); - referenceImages.push(...storyCharacterImages.slice(-2)); // Take last 2 - - // Add current character images to references + // Use only the character images sent from the frontend (user's selection) + // These are already the most recent/relevant characters the user wants to use referenceImages.push(...characterImages); // Build the prompt with continuation context diff --git a/app/api/generate-comic/route.ts b/app/api/generate-comic/route.ts index 6f71c9f..522fe64 100644 --- a/app/api/generate-comic/route.ts +++ b/app/api/generate-comic/route.ts @@ -119,9 +119,8 @@ export async function POST(request: NextRequest) { } } - // Get story character images (up to 2 most recent) - const storyCharacterImages = await getStoryCharacterImages(storyId); - referenceImages.push(...storyCharacterImages.slice(-2)); // Take last 2 + // For continuation pages, character images are sent from frontend + // No need to fetch separately - frontend handles selection } else { // New story: no previous page reference // Create story with temporary title, will update with generated title @@ -140,7 +139,7 @@ export async function POST(request: NextRequest) { }); } - // Add current character images to references + // Use only the character images sent from the frontend referenceImages.push(...characterImages); const dimensions = FIXED_DIMENSIONS; diff --git a/app/api/stories/route.ts b/app/api/stories/route.ts index 11364a1..8d7d7c3 100644 --- a/app/api/stories/route.ts +++ b/app/api/stories/route.ts @@ -21,6 +21,7 @@ export async function GET() { id: stories.id, title: stories.title, slug: stories.slug, + style: stories.style, createdAt: stories.createdAt, pageCount: pages.pageNumber, coverImage: pages.generatedImageUrl, @@ -41,6 +42,7 @@ export async function GET() { id: row.id, title: row.title, slug: row.slug, + style: row.style, createdAt: row.createdAt, pageCount: 0, coverImage: null, diff --git a/app/editor/[storySlug]/story-editor-client.tsx b/app/editor/[storySlug]/story-editor-client.tsx index 4b8cee4..d2ac2dc 100644 --- a/app/editor/[storySlug]/story-editor-client.tsx +++ b/app/editor/[storySlug]/story-editor-client.tsx @@ -319,6 +319,15 @@ export function StoryEditorClient() { const result = await response.json(); + // Update character images list with new ones + const newCharacterUrls = data.characterUrls || []; + setExistingCharacterImages((prev) => { + const combined = [...prev, ...newCharacterUrls]; + // Remove duplicates while preserving order + const unique = Array.from(new Set(combined)); + return unique; + }); + setPages((prevPages) => [ ...prevPages, { @@ -400,6 +409,17 @@ export function StoryEditorClient() { onClose={() => setShowGenerateModal(false)} onGenerate={handleGeneratePage} pageNumber={pages.length + 1} + existingCharacters={existingCharacterImages} + lastPageCharacters={ + pages.length > 0 && pages[pages.length - 1]?.characterUploads + ? pages[pages.length - 1].characterUploads || [] + : [] + } + previousPageCharacters={ + pages.length > 1 && pages[pages.length - 2]?.characterUploads + ? pages[pages.length - 2].characterUploads || [] + : [] + } /> Delete Page - Are you sure you want to delete page {pageToDelete !== null ? pageToDelete + 1 : ""}? - This action cannot be undone. + Are you sure you want to delete page{" "} + {pageToDelete !== null ? pageToDelete + 1 : ""}? This action + cannot be undone. @@ -430,4 +451,3 @@ export function StoryEditorClient() { ); } - diff --git a/app/stories/page.tsx b/app/stories/page.tsx index b50ed79..0df4a58 100644 --- a/app/stories/page.tsx +++ b/app/stories/page.tsx @@ -6,11 +6,13 @@ import { Button } from "@/components/ui/button"; import { Plus, Loader2 } from "lucide-react"; import { Navbar } from "@/components/landing/navbar"; import { StoryLoader } from "@/components/ui/story-loader"; +import { COMIC_STYLES } from "@/lib/constants"; interface Story { id: string; title: string; slug: string; + style: string; createdAt: string; pageCount: number; coverImage: string | null; @@ -131,7 +133,7 @@ export default function StoriesPage() { - + + {/* Remove button (only for new uploads) */} + {char.isNew && ( + + )} - ))} - {uploadedFiles.length < 2 && ( - - )} - - ) : ( - - )} - + ); + })} + + )} + + {/* Upload new character button */} + {isRedrawMode ? "This will replace the current page with a new version. Previous pages and characters are automatically referenced." - : "Automatically references previous pages and existing characters from your story."} + : selectedCharacterIndices.size > 0 + ? `${selectedCharacterIndices.size} character(s) selected. Click to toggle selection.` + : "No characters selected. Click on characters above to select them, or upload new ones."} Character preview