diff --git a/apps/web/src/app/api/create/worksheets/addition/preview/route.ts b/apps/web/src/app/api/create/worksheets/addition/preview/route.ts index 83c09618..12d8e335 100644 --- a/apps/web/src/app/api/create/worksheets/addition/preview/route.ts +++ b/apps/web/src/app/api/create/worksheets/addition/preview/route.ts @@ -18,7 +18,7 @@ export async function POST(request: NextRequest) { if (!validation.isValid || !validation.config) { return NextResponse.json( { error: 'Invalid configuration', errors: validation.errors }, - { status: 400 }, + { status: 400 } ) } @@ -30,7 +30,7 @@ export async function POST(request: NextRequest) { config.pAnyStart, config.pAllStart, config.interpolate, - config.seed, + config.seed ) // Generate Typst sources (one per page) @@ -63,7 +63,7 @@ export async function POST(request: NextRequest) { error: `Failed to compile preview (page ${i + 1})`, details: stderr, }, - { status: 500 }, + { status: 500 } ) } } @@ -80,7 +80,7 @@ export async function POST(request: NextRequest) { error: 'Failed to generate preview', message: errorMessage, }, - { status: 500 }, + { status: 500 } ) } } diff --git a/apps/web/src/app/api/create/worksheets/addition/route.ts b/apps/web/src/app/api/create/worksheets/addition/route.ts index f6f4077f..61fcaf14 100644 --- a/apps/web/src/app/api/create/worksheets/addition/route.ts +++ b/apps/web/src/app/api/create/worksheets/addition/route.ts @@ -61,7 +61,7 @@ export async function POST(request: NextRequest) { typstSource: typstSource.split('\n').slice(0, 20).join('\n') + '\n...', }), }, - { status: 500 }, + { status: 500 } ) } diff --git a/apps/web/src/app/create/worksheets/addition/components/ConfigPanel.tsx b/apps/web/src/app/create/worksheets/addition/components/ConfigPanel.tsx index dfb0deec..940b18f9 100644 --- a/apps/web/src/app/create/worksheets/addition/components/ConfigPanel.tsx +++ b/apps/web/src/app/create/worksheets/addition/components/ConfigPanel.tsx @@ -1,5 +1,6 @@ 'use client' +import * as Slider from '@radix-ui/react-slider' import { useTranslations } from 'next-intl' import { css } from '../../../../../../styled-system/css' import { stack } from '../../../../../../styled-system/patterns' @@ -13,517 +14,734 @@ interface ConfigPanelProps { export function ConfigPanel({ formState, onChange }: ConfigPanelProps) { const t = useTranslations('create.worksheets.addition') + // Helper to get default column count for a given problemsPerPage (user can override) + const getDefaultColsForProblemsPerPage = ( + problemsPerPage: number, + orientation: 'portrait' | 'landscape' + ): number => { + if (orientation === 'portrait') { + // Portrait: prefer 2-3 columns + if (problemsPerPage === 6) return 2 + if (problemsPerPage === 8) return 2 + if (problemsPerPage === 10) return 2 + if (problemsPerPage === 12) return 3 + if (problemsPerPage === 15) return 3 + return 2 // default + } else { + // Landscape: prefer 4-5 columns + if (problemsPerPage === 8) return 4 + if (problemsPerPage === 10) return 5 + if (problemsPerPage === 12) return 4 + if (problemsPerPage === 15) return 5 + if (problemsPerPage === 16) return 4 + if (problemsPerPage === 20) return 5 + return 4 // default + } + } + + // Helper to calculate derived state (rows, total) from primary state (problemsPerPage, cols, pages) + const calculateDerivedState = (problemsPerPage: number, cols: number, pages: number) => { + const rowsPerPage = problemsPerPage / cols + const rows = rowsPerPage * pages + const total = problemsPerPage * pages + return { rows, total } + } + + // Get current primary state with defaults + const currentOrientation = formState.orientation || 'portrait' + const currentProblemsPerPage = + formState.problemsPerPage || (currentOrientation === 'portrait' ? 15 : 20) + const currentCols = + formState.cols || getDefaultColsForProblemsPerPage(currentProblemsPerPage, currentOrientation) + const currentPages = formState.pages || 1 + + console.log('=== ConfigPanel Render ===') + console.log('Primary state:', { + problemsPerPage: currentProblemsPerPage, + cols: currentCols, + pages: currentPages, + orientation: currentOrientation, + }) + console.log( + 'Derived state:', + calculateDerivedState(currentProblemsPerPage, currentCols, currentPages) + ) + return ( -
- {t('config.subtitle')} -
-