diff --git a/app/(quiz)/_layout.tsx b/app/(quiz)/_layout.tsx
new file mode 100644
index 0000000..b4ef1de
--- /dev/null
+++ b/app/(quiz)/_layout.tsx
@@ -0,0 +1,9 @@
+import { Stack } from "expo-router";
+
+export default function QuizLayout() {
+ return (
+
+
+
+ );
+}
diff --git a/app/(quiz)/quiz.tsx b/app/(quiz)/quiz.tsx
new file mode 100644
index 0000000..2de710c
--- /dev/null
+++ b/app/(quiz)/quiz.tsx
@@ -0,0 +1,144 @@
+import BackButton from "@/components/BackButton";
+import { toBgColor, toTextColor } from "@/components/Constants";
+import ActivityQuestion, {
+ ActivityQuestionRef,
+} from "@/components/quiz/ActivityQuestion";
+import AgeQuestion, { AgeQuestionRef } from "@/components/quiz/AgeQuestion";
+import BeginnerQuestion, {
+ BeginnerQuestionRef,
+} from "@/components/quiz/BeginnerQuestion";
+import FrequencyQuestion, {
+ FrequencyQuestionRef,
+} from "@/components/quiz/FrequencyQuestion";
+import GenderQuestion, {
+ GenderQuestionRef,
+} from "@/components/quiz/GenderQuestion";
+import GoalQuestion, { GoalQuestionRef } from "@/components/quiz/GoalQuestion";
+import HeightQuestion, {
+ HeightQuestionRef,
+} from "@/components/quiz/HeightQuestion";
+import SleepQuestion, {
+ SleepQuestionRef,
+} from "@/components/quiz/SleepQuestion";
+import SportQuestion, {
+ SportQuestionRef,
+} from "@/components/quiz/SportQuestion";
+import WeightQuestion, {
+ WeightQuestionRef,
+} from "@/components/quiz/WeightQuestion";
+import Button from "@/components/ui/Button";
+import Screen from "@/components/ui/Screen";
+import Text from "@/components/ui/Text";
+import { useSession } from "@/ctx";
+import { useRouter } from "expo-router";
+import React, { useRef, useState } from "react";
+import { View } from "react-native";
+
+export default function Quiz() {
+ const { signIn, session } = useSession();
+ const router = useRouter();
+
+ const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
+ const goalRef = useRef(null);
+ const genderRef = useRef(null);
+ const weightRef = useRef(null);
+ const heightRef = useRef(null);
+ const ageRef = useRef(null);
+ const beginnerRef = useRef(null);
+ const activityRef = useRef(null);
+ const frequencyRef = useRef(null);
+ const sportQuestionRef = useRef(null);
+ const sleepQuestionRef = useRef(null);
+
+ interface Question {
+ component: React.ForwardRefExoticComponent>;
+ props: T;
+ }
+
+ const questions: Question[] = [
+ { component: GoalQuestion, props: { ref: goalRef } },
+ { component: GenderQuestion, props: { ref: genderRef } },
+ {
+ component: WeightQuestion,
+ props: { ref: weightRef },
+ },
+ { component: HeightQuestion, props: { ref: heightRef } },
+ { component: AgeQuestion, props: { ref: ageRef } },
+ { component: BeginnerQuestion, props: { ref: beginnerRef } },
+ { component: ActivityQuestion, props: { ref: activityRef } },
+ //{ component: IllnessQuestion, props: {} },
+ {
+ component: FrequencyQuestion,
+ props: { ref: frequencyRef, isMale: genderRef.current?.getAnswer() },
+ },
+ { component: SportQuestion, props: { ref: sportQuestionRef } },
+ { component: SleepQuestion, props: { ref: sleepQuestionRef } },
+ ];
+
+ const goNext = () => {
+ if (currentQuestionIndex < questions.length - 1) {
+ setCurrentQuestionIndex(currentQuestionIndex + 1);
+ } else {
+ Collect();
+ }
+ };
+
+ function Collect() {
+ if (session) {
+ session.healthProblems = [];
+
+ session.goals = goalRef.current?.getAnswer();
+ session.sexe = genderRef.current?.getAnswer();
+ session.weight = weightRef.current?.getAnswer();
+ session.height = heightRef.current?.getAnswer();
+ session.age = ageRef.current?.getAnswer();
+ session.sportLevel = activityRef.current?.getAnswer();
+ session.nbSessionPerWeek = frequencyRef.current?.getAnswer();
+ session.sports = sportQuestionRef.current?.getAnswer();
+ session.sleepLevel = sleepQuestionRef.current?.getAnswer();
+ signIn(session);
+ }
+
+ router.replace("/(tabs)/(home)/HomeScreen");
+ }
+
+ return (
+
+
+
+ {
+ if (currentQuestionIndex === 0) {
+ router.replace("/(auth)/log-in");
+ } else {
+ setCurrentQuestionIndex((i) => Math.max(i - 1, 0));
+ }
+ }}
+ icon={currentQuestionIndex === 0 ? "close" : "arrowleft"}
+ />
+
+ Questionnaire
+
+
+
+ {currentQuestionIndex + 1} sur {questions.length}
+
+
+
+ {questions.map((question, index) =>
+ React.createElement(question.component, {
+ isVisible: index === currentQuestionIndex,
+ key: index,
+ ...question.props,
+ })
+ )}
+
+
+
+ );
+}
diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx
index f6ff288..cd8fd2d 100644
--- a/app/(tabs)/_layout.tsx
+++ b/app/(tabs)/_layout.tsx
@@ -1,26 +1,26 @@
-import {Redirect, Tabs, useRouter} from "expo-router";
import { useSession } from "@/ctx";
-import React from "react";
import { AntDesign, Ionicons, MaterialIcons } from "@expo/vector-icons";
+import { Redirect, Tabs, useRouter } from "expo-router";
+import React from "react";
import Loading from "../loading";
export default function TabBarLayout() {
const { session, isLoading } = useSession();
- const router = useRouter()
+ const router = useRouter();
const sizeIcon = 24;
- // You can keep the splash screen open, or render a loading screen like we do here.
if (isLoading) {
return ;
}
- // Only require authentication within the (app) group's layout as users
- // need to be able to access the (auth) group and sign in again.
if (!session) {
- // On web, static rendering will stop here as the user is not authenticated
- // in the headless Node process that the pages are rendered in.
- return ;
+ return ;
}
+ console.log(session);
+ if (!session.isQuizDone()) {
+ return ;
+ }
+
return (
-
-
- This screen {pathname} doesn't exist: {pathname}
-