From 9bdcdb78017ecadd62ed7ab06ac00eeaabf4ab6c Mon Sep 17 00:00:00 2001 From: Anthony RICHARD Date: Tue, 28 Jan 2025 14:20:14 +0100 Subject: [PATCH] Add frequence question --- app/(quiz)/quiz.tsx | 55 ++++++++++++++------------- components/quiz/FrequencyQuestion.tsx | 35 +++++++++++++++++ components/quiz/Question.tsx | 4 +- 3 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 components/quiz/FrequencyQuestion.tsx diff --git a/app/(quiz)/quiz.tsx b/app/(quiz)/quiz.tsx index 7b64827..16501db 100644 --- a/app/(quiz)/quiz.tsx +++ b/app/(quiz)/quiz.tsx @@ -1,35 +1,36 @@ import BackButton from "@/components/BackButton"; import { toBgColor, toTextColor } from "@/components/Constants"; -import AgeQuestion from "@/components/quiz/AgeQuestion"; -import BeginnerQuestion from "@/components/quiz/BeginnerQuestion"; -import HeightQuestion from "@/components/quiz/HeightQuestion"; -import { QuestionChildProps } from "@/components/quiz/Question"; -import WeightQuestion from "@/components/quiz/WeightQuestion"; import Button from "@/components/ui/Button"; import Screen from "@/components/ui/Screen"; import Text from "@/components/ui/Text"; -import React, { ForwardRefExoticComponent, RefAttributes } from "react"; +import React from "react"; import { View } from "react-native"; +import FrequencyQuestion from "@/components/quiz/FrequencyQuestion"; import GoalQuestion from "@/components/quiz/GoalQuestion"; -import LvlQuestion from "@/components/quiz/LvlQuestion"; import GenderQuestion from "@/components/quiz/GenderQuestion"; -import ActivityQuestion from "@/components/quiz/ActivityQuestion"; +import WeightQuestion from "@/components/quiz/WeightQuestion"; +import HeightQuestion from "@/components/quiz/HeightQuestion"; +import AgeQuestion from "@/components/quiz/AgeQuestion"; +import BeginnerQuestion from "@/components/quiz/BeginnerQuestion"; +import LvlQuestion from "@/components/quiz/LvlQuestion"; import SleepQuestion from "@/components/quiz/SleepQuestion"; export default function Quiz() { const [currentQuestionIndex, setCurrentQuestionIndex] = React.useState(0); - const questions: ForwardRefExoticComponent< - QuestionChildProps & RefAttributes - >[] = [ - GoalQuestion, - GenderQuestion, - WeightQuestion, - HeightQuestion, - LvlQuestion, - AgeQuestion, - BeginnerQuestion, - ActivityQuestion, - SleepQuestion + interface Question { + component: React.ForwardRefExoticComponent>; + props: T; + } + const questions: Question[] = [ + { component: GoalQuestion, props: {} }, + { component: GenderQuestion, props: {} }, + { component: WeightQuestion, props: {} }, + { component: HeightQuestion, props: {} }, + { component: AgeQuestion, props: {} }, + { component: BeginnerQuestion, props: {} }, + { component: LvlQuestion, props: {} }, + { component: FrequencyQuestion, props: { isMale: true } }, + { component: SleepQuestion, props: {} }, ]; const goBack = () => { @@ -55,13 +56,13 @@ export default function Quiz() { - {questions.map((QuestionComponent, index) => ( - - {index == currentQuestionIndex && ( - - )} - - ))} + {questions.map((question, index) => + React.createElement(question.component, { + isVisible: index === currentQuestionIndex, + key: index, + ...question.props, + }) + )} diff --git a/components/quiz/FrequencyQuestion.tsx b/components/quiz/FrequencyQuestion.tsx new file mode 100644 index 0000000..3b8d5a1 --- /dev/null +++ b/components/quiz/FrequencyQuestion.tsx @@ -0,0 +1,35 @@ +import React from "react"; +import Question, { QuestionChildProps } from "./Question"; +import Text from "../ui/Text"; +import SegmentedControl from "../ui/SegmentedControl"; +import { View } from "react-native"; + +export interface FrequencyQuestionProps extends QuestionChildProps { + isMale: boolean; +} + +export default React.forwardRef( + (props, ref): React.ReactElement => { + const { isMale, ...rest } = props; + const ANSWERS = ["1", "2", "3", "4", "5"]; + const [answer, setAnswer] = React.useState("1"); + return ( + + + + Je suis {isMale ? "prêt" : "prête"} à m'entraîner + + + {answer} + + fois par semaine ! + + + + ); + } +); diff --git a/components/quiz/Question.tsx b/components/quiz/Question.tsx index 6b1ba0b..1dea95d 100644 --- a/components/quiz/Question.tsx +++ b/components/quiz/Question.tsx @@ -3,7 +3,7 @@ import React from "react"; import { View, ViewProps } from "react-native"; export interface QuestionChildProps extends ViewProps { - isVisible: boolean; + isVisible?: boolean; } interface QuestionProps extends QuestionChildProps { @@ -26,4 +26,4 @@ export default React.forwardRef( ); } -); \ No newline at end of file +);