diff --git a/src/app/questions-list/questions-list-client.tsx b/src/app/questions-list/questions-list-client.tsx index d8e08c2..cdeca38 100644 --- a/src/app/questions-list/questions-list-client.tsx +++ b/src/app/questions-list/questions-list-client.tsx @@ -18,8 +18,8 @@ import QuestionCard from "@/components/Componentes/question-card"; import RequiredStepsCard from "@/components/Componentes/required-steps-card"; import type { MarriageField } from "@/hooks/marriage/types"; import { marriageQueryKeys } from "@/hooks/marriage/query-keys"; -import { getCattellQuestions } from "@/hooks/marriage/use-cattell"; -import { getGlasserQuestions } from "@/hooks/marriage/use-glasser"; +import { getCattellQuestions, useCattellResultQuery } from "@/hooks/marriage/use-cattell"; +import { getGlasserQuestions, useGlasserResultQuery } from "@/hooks/marriage/use-glasser"; import { getFormSection, useFormOverviewQuery, @@ -97,6 +97,14 @@ export default function QuestionsListClient() { "profile", locale, ); + const { data: glasserResult } = useGlasserResultQuery(locale, { + enabled: Boolean(profile?.id), + retry: false, + }); + const { data: cattellResult } = useCattellResultQuery(locale, { + enabled: Boolean(profile?.id), + retry: false, + }); const isSectionsLoading = false; @@ -205,11 +213,46 @@ export default function QuestionsListClient() { const profileId = profile?.id; for (const slug of ["personality_test", "glasser_5_needs_test"]) { try { + // 1. Check backend test results + if ( + (slug === "glasser_5_needs_test" && Boolean(glasserResult)) || + (slug === "personality_test" && Boolean(cattellResult)) + ) { + next.set(slug, 100); + continue; + } + + // 2. Check local completion flag + if (typeof window !== "undefined") { + const completionKeys = [ + profileId ? `marriage:user:${profileId}:sections:${slug}:completed` : null, + `marriage:sections:${slug}:completed`, + `marriage:sections:${slug}:answers`, + ].filter(Boolean) as string[]; + + let isLocalCompleted = false; + for (const key of completionKeys) { + const raw = window.localStorage.getItem(key); + if (raw) { + try { + const parsed = JSON.parse(raw); + if (parsed?.completed === true) { + next.set(slug, 100); + isLocalCompleted = true; + break; + } + } catch {} + } + } + if (isLocalCompleted) continue; + } + + // 3. If not completed, read draft progress let draft: any = null; if (profileId) { draft = readScopedAssessmentDraft(profileId, slug); } - if (!draft) { + if (!draft && typeof window !== "undefined") { const raw = window.localStorage.getItem(`marriage:tests:${slug}:draft`); draft = raw ? JSON.parse(raw) : null; } @@ -220,7 +263,7 @@ export default function QuestionsListClient() { } } setLocalAssessmentProgress(next); - }, [overview, profile?.id]); + }, [overview, profile?.id, glasserResult, cattellResult]); const sectionProgressBySlug = useMemo(() => { const progressBySlug = new Map(); @@ -236,8 +279,7 @@ export default function QuestionsListClient() { ); } localAssessmentProgress.forEach((progress, slug) => { - if ((progressBySlug.get(slug) ?? 0) < 100) - progressBySlug.set(slug, progress); + progressBySlug.set(slug, progress); }); // Add fallback for combined section from the schema adapter which attaches it to questionListItems directly