diff --git a/apps/web/app/[lang]/otazka/page.tsx b/apps/web/app/[lang]/otazka/page.tsx index 283a115..a5a78e9 100644 --- a/apps/web/app/[lang]/otazka/page.tsx +++ b/apps/web/app/[lang]/otazka/page.tsx @@ -22,7 +22,7 @@ type Steps = { export default function Page() { const [questions, setQuestions] = useState([]); const [isLoading, setIsLoading] = useState(true); - const [currentQuestion, setCurrentQuestion] = useState(1); + const [currentQuestion, setCurrentQuestion] = useState(0); // steps for progress bar const [steps, setSteps] = useState({ answers: [], @@ -33,7 +33,6 @@ export default function Page() { function handleClick(button: string) { switch (button) { case "inFavour": - setCurrentQuestion((prevState) => prevState + 1); // fix glitch, styling of the status bar should be permanent setSteps((prevSteps) => { const updatedAnswer = prevSteps.answers.map((answer, index) => { @@ -45,9 +44,9 @@ export default function Page() { return { ...prevSteps, answers: updatedAnswer }; }); + setCurrentQuestion((prevState) => prevState + 1); break; case "against": - setCurrentQuestion((prevState) => prevState + 1); setSteps((prevSteps) => { const updatedAnswer = prevSteps.answers.map((answer, index) => { if (index === currentQuestion - 1) { @@ -58,6 +57,7 @@ export default function Page() { return { ...prevSteps, answers: updatedAnswer }; }); + setCurrentQuestion((prevState) => prevState + 1); break; case "prev": setCurrentQuestion((prevState) => prevState - 1); @@ -66,18 +66,19 @@ export default function Page() { currentQuestion: currentQuestion, }); break; - // fix button naming and args to "skip" + // fix button naming and args to "skip" and null set case "next": setCurrentQuestion((prevState) => prevState + 1); - setSteps((prevSteps) => { - const updatedAnswer = prevSteps.answers.map((answer, index) => { - if (index === currentQuestion - 1) { - return { ...answer, status: null }; - } - return answer; - }); - - return { ...prevSteps, answers: updatedAnswer }; + setSteps({ + ...steps, + currentQuestion: currentQuestion, + }); + break; + case "guide": + setCurrentQuestion((prevState) => prevState + 1); + setSteps({ + ...steps, + currentQuestion: currentQuestion, }); break; } @@ -115,7 +116,13 @@ export default function Page() { return (
- {isLoading && } + {currentQuestion === 0 ? : null} + {/* // fix glitch beginning */} + {currentQuestion > questions.length && currentQuestion !== 0 ? ( + + ) : null} + {/* loader needed? */} + {/* {isLoading && } */} {/* find better approach than map */} {questions.map((question: Question, index) => { const questionNumber = index + 1; @@ -131,8 +138,10 @@ export default function Page() { ); } })} - - + {/* Bottom bar */} + {currentQuestion <= questions.length && currentQuestion > 0 ? ( + + ) : null}
); } diff --git a/packages/design-system/src/ui/questionCard/questionGuide.tsx b/packages/design-system/src/ui/questionCard/questionGuide.tsx index 2490bf6..636b613 100644 --- a/packages/design-system/src/ui/questionCard/questionGuide.tsx +++ b/packages/design-system/src/ui/questionCard/questionGuide.tsx @@ -1,3 +1,35 @@ -export function QuestionGuide() { - return

Question guide

; +import { Button } from "@repo/design-system/ui"; + +type Props = { + onClick: (button: ButtonType) => void; +}; + +export function QuestionGuide({ onClick }: Props) { + return ( + <> +
+ + Krajské volby + + Jihomoravský kraj + + +

+ Vítejte ve Volební kalkulačce pro krajské volby 2024 pro Jihomoravský + kraj. Čeká vás 25 otázek. Stejné otázky dostaly všechny kandidující + strany. Zodpovězení otázek zabere zhruba 10 minut a na konci se + dozvíte, jak se jednotlivé strany shodují s vašimi názory. +

+

+ Oslovili jsme všechny strany bez výjimky. Pokud se některá neobjeví ve + výsledcích, je to proto, že (zatím) neposlala svoje odpovědi. +

+
+
+ +
+ + ); } diff --git a/packages/design-system/src/ui/questionCard/questionResults.tsx b/packages/design-system/src/ui/questionCard/questionResults.tsx index 41685c8..ad60112 100644 --- a/packages/design-system/src/ui/questionCard/questionResults.tsx +++ b/packages/design-system/src/ui/questionCard/questionResults.tsx @@ -1,3 +1,3 @@ export function QuestionResults() { - return

Question results

; + return

Rekapitulace

; }