diff --git a/app/src/app/api/projects/route.ts b/app/src/app/api/projects/route.ts index ac22a72..95db0c0 100644 --- a/app/src/app/api/projects/route.ts +++ b/app/src/app/api/projects/route.ts @@ -7,7 +7,9 @@ export async function GET() { const { data, error } = await supabase .from('projects') - .select('*, style:styles(*)') + // Ids only, and in one round trip: the dashboard badge reports progress + // from these rows rather than from a status column nothing ever wrote. + .select('*, style:styles(*), figures(id), surfaces(id), compositions(id)') .eq('user_id', userId) .order('updated_at', { ascending: false }) diff --git a/app/src/components/layout/ProjectStepNav.tsx b/app/src/components/layout/ProjectStepNav.tsx index 6e3825d..be632df 100644 --- a/app/src/components/layout/ProjectStepNav.tsx +++ b/app/src/components/layout/ProjectStepNav.tsx @@ -7,28 +7,36 @@ import { Users, Palette, Ruler, Layers, Download, Check, ArrowLeft } from 'lucid import { useProject } from '@/hooks/useProject' import { useFigures } from '@/hooks/useFigures' import { useSurface } from '@/hooks/useSurface' +import { useComposition } from '@/hooks/useComposition' +import { PROJECT_STEPS, type ProjectStepId } from '@/lib/config/project-steps' +import { deriveProjectProgress } from '@/lib/domain/project-progress' -const STEPS = [ - { id: 'figures', label: 'Figures', icon: Users, href: 'figures' }, - { id: 'style', label: 'Style', icon: Palette, href: 'style' }, - { id: 'surface', label: 'Surface', icon: Ruler, href: 'surface' }, - { id: 'compose', label: 'Compose', icon: Layers, href: 'compose' }, - { id: 'export', label: 'Export', icon: Download, href: 'export' }, -] +/** Icons are the only per-step thing the nav owns; the steps themselves are config. */ +const STEP_ICONS: Record = { + figures: Users, + style: Palette, + surface: Ruler, + compose: Layers, + export: Download, +} export function ProjectStepNav({ projectId }: { projectId: string }) { const pathname = usePathname() const { data: project } = useProject(projectId) const { data: figures } = useFigures(projectId) const { data: surface } = useSurface(projectId) + const { data: composition } = useComposition(projectId) - const completedSteps = new Set() - if (figures && figures.length > 0) completedSteps.add('figures') - if (project?.style_id) completedSteps.add('style') - if (surface) completedSteps.add('surface') - if (figures?.some(f => f.styled_url)) completedSteps.add('compose') + // Same derivation the dashboard badge uses, so the two cannot disagree. + const { completed } = deriveProjectProgress({ + figureCount: figures?.length ?? 0, + hasStyle: !!project?.style_id, + hasSurface: !!surface, + hasComposition: !!composition, + }) + const completedSteps = new Set(completed) - const activeIndex = STEPS.findIndex(s => pathname.endsWith(`/${s.href}`)) + const activeIndex = PROJECT_STEPS.findIndex(s => pathname.endsWith(`/${s.href}`)) return (