Add quiz behind #12

Merged
anthony.richard merged 1 commits from Quiz_Behind into Common_Quizz 4 months ago

@ -1,57 +1,107 @@
import BackButton from "@/components/BackButton";
import { toBgColor, toTextColor } from "@/components/Constants";
import WeightQuestion, {
WeightQuestionRef,
} from "@/components/quiz/WeightQuestion";
import React, { useRef, useState } from "react";
import { View } from "react-native";
import Button from "@/components/ui/Button";
import Screen from "@/components/ui/Screen";
import Text from "@/components/ui/Text";
import React from "react";
import { View } from "react-native";
import FrequencyQuestion from "@/components/quiz/FrequencyQuestion";
import GoalQuestion from "@/components/quiz/GoalQuestion";
import GenderQuestion from "@/components/quiz/GenderQuestion";
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";
import SportQuestion from "@/components/quiz/SportQuestion";
import FrequencyQuestion, {
FrequencyQuestionRef,
} from "@/components/quiz/FrequencyQuestion";
import GoalQuestion, { GoalQuestionRef } from "@/components/quiz/GoalQuestion";
import GenderQuestion, {
GenderQuestionRef,
} from "@/components/quiz/GenderQuestion";
import HeightQuestion, {
HeightQuestionRef,
} from "@/components/quiz/HeightQuestion";
import AgeQuestion, { AgeQuestionRef } from "@/components/quiz/AgeQuestion";
import BeginnerQuestion, {
BeginnerQuestionRef,
} from "@/components/quiz/BeginnerQuestion";
import ActivityQuestion, {
ActivityQuestionRef,
} from "@/components/quiz/ActivityQuestion";
import SportQuestion, {
SportQuestionRef,
} from "@/components/quiz/SportQuestion";
import SleepQuestion, {
SleepQuestionRef,
} from "@/components/quiz/SleepQuestion";
export default function Quiz() {
const [currentQuestionIndex, setCurrentQuestionIndex] = React.useState(0);
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
const goalRef = useRef<GoalQuestionRef>(null);
const genderRef = useRef<GenderQuestionRef>(null);
const weightRef = useRef<WeightQuestionRef>(null);
const heightRef = useRef<HeightQuestionRef>(null);
const ageRef = useRef<AgeQuestionRef>(null);
const beginnerRef = useRef<BeginnerQuestionRef>(null);
const activityRef = useRef<ActivityQuestionRef>(null);
const frequencyRef = useRef<FrequencyQuestionRef>(null);
const sportQuestionRef = useRef<SportQuestionRef>(null);
const sleepQuestionRef = useRef<SleepQuestionRef>(null);
interface Question<T = any> {
component: React.ForwardRefExoticComponent<T & React.RefAttributes<any>>;
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: SportQuestion, props: {} },
{ component: SleepQuestion, props: {} },
{ 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 goBack = () => {
if (currentQuestionIndex >= 1) {
setCurrentQuestionIndex(currentQuestionIndex - 1);
}
};
const goNext = () => {
if (currentQuestionIndex < questions.length - 1) {
setCurrentQuestionIndex(currentQuestionIndex + 1);
} else {
collect();
}
};
const collect = () => {
console.log("Goal:", goalRef.current?.getAnswer());
console.log("Sexe:", genderRef.current?.getAnswer());
console.log("Weight:", weightRef.current?.getAnswer());
console.log("Height:", heightRef.current?.getAnswer());
console.log("Age:", ageRef.current?.getAnswer());
console.log("Beginner:", beginnerRef.current?.getAnswer());
console.log("Activity:", activityRef.current?.getAnswer());
console.log("Frequency:", frequencyRef.current?.getAnswer());
console.log("Sport:", sportQuestionRef.current?.getAnswer());
console.log("Sleep:", sleepQuestionRef.current?.getAnswer());
};
return (
<Screen>
<View className="gap-4 justify-between h-full">
<View className="flex-row justify-between items-center">
<BackButton onPress={goBack} />
<View className="flex-row justify-between items-center gap-4">
<BackButton
className="mt-2"
onPress={() => setCurrentQuestionIndex((i) => Math.max(i - 1, 0))}
/>
<Text size="2xl" weight="bold">
Questionnaire
</Text>
<View className={"px-4 py-2 rounded-2xl" + " " + toBgColor("blue")}>
<Text className={toTextColor("blue")} weight="bold">
{currentQuestionIndex + 1} sur {questions.length}
@ -66,7 +116,9 @@ export default function Quiz() {
})
)}
<Button afterIcon="arrowright" onPress={goNext}>
Suivant
{currentQuestionIndex == questions.length - 1
? "Terminer"
: "Suivant"}
</Button>
</View>
</Screen>

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@ -1,26 +1,26 @@
import { router } from "expo-router";
import Button from "./ui/Button";
import { TouchableOpacityProps } from "react-native";
import { ButtonProps } from "./ui/Button";
import { AntDesign } from "@expo/vector-icons";
import React from "react";
import { AntDesignIconNames } from "./Icons";
interface Props extends TouchableOpacityProps {
interface Props extends ButtonProps {
icon?: AntDesignIconNames;
}
export default React.forwardRef<any, Props>(
(props, ref): React.ReactElement => {
const { icon, onPress } = props;
({ icon, onPress, className, ...props }, ref): React.ReactElement => {
const defaultOnPress = () => {
router.back();
};
return (
<Button
className="h-16 w-16 mb-4"
className={"h-16 w-16 mb-4" + " " + className}
onPress={onPress ?? defaultOnPress}
{...ref}
{...props}
>
<AntDesign name={icon ?? "arrowleft"} size={24} />
</Button>

@ -0,0 +1,149 @@
import React, { forwardRef } from "react";
import { View, TouchableOpacity, ViewProps } from "react-native";
import Text from "./ui/Text";
import {
AntDesign,
Entypo,
FontAwesome6,
Ionicons,
MaterialCommunityIcons,
} from "@expo/vector-icons";
import {
AntDesignIconNames,
CommunityIconNames,
EntypoIconNames,
FontAwesome6IconNames,
FontAwesomeIconNames,
IonIconNames,
} from "./Icons";
export type CheckBoxDirection = "row" | "col";
interface CheckBoxProps extends ViewProps {
label?: string;
onChange: () => void;
antIcon?: AntDesignIconNames;
entypoIcon?: EntypoIconNames;
fontAwesomeIcon?: FontAwesomeIconNames;
fontAwesome6Icon?: FontAwesome6IconNames;
communityIcon?: CommunityIconNames;
IonIcon?: IonIconNames;
value: boolean;
isCheckIconVisible?: boolean;
endText?: string;
direction?: CheckBoxDirection;
}
export default forwardRef<any, CheckBoxProps>(
(
{
label,
onChange,
antIcon,
entypoIcon,
fontAwesomeIcon,
fontAwesome6Icon,
communityIcon,
IonIcon,
value,
isCheckIconVisible,
endText,
direction,
className,
...props
},
ref
) => {
return (
<TouchableOpacity
onPress={onChange}
className={
"items-center p-4 rounded-3xl" +
" " +
((direction ?? "row") == "row"
? "flex-row justify-between gap-4"
: "justify-center gap-1") +
" " +
(value
? "bg-orange-600 border-4 border-orange-300"
: "bg-gray-300 border-4 border-gray-300") +
" " +
(className ?? "")
}
{...props}
{...ref}
>
<View>
{antIcon ? (
<AntDesign
name={antIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{entypoIcon ? (
<Entypo
name={entypoIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{communityIcon ? (
<MaterialCommunityIcons
name={communityIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{fontAwesomeIcon ? (
<FontAwesome6
name={fontAwesomeIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{fontAwesome6Icon ? (
<FontAwesome6
name={fontAwesome6Icon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{IonIcon ? (
<Ionicons
name={IonIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
</View>
{label != null ? (
<Text
weight="bold"
color={value ? "white" : "black"}
className={(direction ?? "row") == "row" ? "flex-1" : ""}
>
{label}
</Text>
) : null}
{isCheckIconVisible ? (
<View
className={
"h-5 w-5 rounded border justify-center items-center" +
" " +
(value ? "border-white" : "border-black")
}
>
{value && <View className="h-2 w-2 bg-white" />}
</View>
) : null}
{endText != null ? (
<Text color={value ? "white" : "black"}>{endText}</Text>
) : null}
</TouchableOpacity>
);
}
);

@ -1,68 +0,0 @@
import React, {Component} from "react";
import {View, Text, TouchableOpacity, Image} from "react-native";
import {
AntDesign,
Entypo,
FontAwesome6,
MaterialCommunityIcons,
} from "@expo/vector-icons";
import {
AntDesignIconNames,
CommunityIconNames,
EntypoIconNames,
FontAwesomeIconNames,
} from "./Icons";
interface CheckButtonProps {
label: string;
value: boolean;
onChange: () => void;
antIcon?: AntDesignIconNames;
entypoIcon?: EntypoIconNames;
fontAwesomeIcon?: FontAwesomeIconNames;
communityIcon?: CommunityIconNames;
}
const CheckButton: React.FC<CheckButtonProps> = ({ label, value, onChange, antIcon,
entypoIcon,
fontAwesomeIcon,
communityIcon, }) => {
return (
<View style={{ flexBasis: "33.33%"}}>
<TouchableOpacity onPress={onChange} className={`p-5 m-1 rounded-3xl ${value ? 'bg-orange-600 border-4 border-orange-300' : 'bg-gray-300 border-4 border-gray-300'} items-center`}>
{antIcon ? (
<AntDesign
name={antIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{entypoIcon ? (
<Entypo
name={entypoIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{communityIcon ? (
<MaterialCommunityIcons
name={communityIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
{fontAwesomeIcon ? (
<FontAwesome6
name={fontAwesomeIcon}
size={30}
color={value ? "white" : "black"}
/>
) : null}
<Text className={`${value ? 'text-white' : 'text-black'}`}>{label}</Text>
</TouchableOpacity>
</View>
);
};
export default CheckButton;

@ -1,34 +0,0 @@
import React, {Component} from "react";
import {View, Text, TouchableOpacity, Image} from "react-native";
import {AntDesign, FontAwesome6} from "@expo/vector-icons";
import {AntDesignIconNames} from "./Icons";
interface CheckBoxProps {
label: string;
value: boolean;
onChange: () => void;
icon: AntDesignIconNames | string;
}
const CheckBox: React.FC<CheckBoxProps> = ({ label, value, onChange, icon }) => {
let AwesomIconList = ["weight-scale", "beer"];
return (
<TouchableOpacity onPress={onChange} className={`p-5 m-1 rounded-3xl ${value ? 'bg-orange-600 border-4 border-orange-300' : 'bg-gray-300 border-4 border-gray-300'} flex-row items-center`}>
<View className="mr-2.5">
{AwesomIconList.includes(icon) ? (
<FontAwesome6 name={icon} size={30} color={value ? "white" : "black"}/>
) : (
<AntDesign name={icon ?? "arrowleft"} size={30} color={value ? "white" : "black"}/>
)}
</View>
<Text className={`${value ? 'text-white' : 'text-black'} flex-1`}>{label}</Text>
<View className={`h-5 w-5 rounded border ${value ? 'border-white' : 'border-black'} items-center justify-center mr-2.5`}>
{value && <View className="h-2 w-2 bg-white" />}
</View>
</TouchableOpacity>
);
};
export default CheckBox;

@ -1,3 +1,26 @@
import { AntDesign } from "@expo/vector-icons";
import {
AntDesign,
Entypo,
FontAwesome,
Ionicons,
MaterialCommunityIcons,
} from "@expo/vector-icons";
export type AntDesignIconNames = keyof typeof AntDesign.glyphMap;
export type AntDesignIconNames = keyof typeof AntDesign.glyphMap;
export type EntypoIconNames = keyof typeof Entypo.glyphMap;
export type FontAwesomeIconNames = keyof typeof FontAwesome.glyphMap;
export type FontAwesome6IconNames =
| "person-running"
| "person-walking"
| "person-hiking"
| "skateboarding"
| "bike"
| "basketball"
| "heart"
| "yoga"
| "setting"
| "beer"
| "shield-heart"
| "weight-scale";
export type CommunityIconNames = keyof typeof MaterialCommunityIcons.glyphMap;
export type IonIconNames = keyof typeof Ionicons.glyphMap;

@ -8,9 +8,7 @@ interface Props extends ExtendedTextProps {
}
export default React.forwardRef<any, Props>(
(props, ref): React.ReactElement => {
const { isVisible, ...rest } = props;
({ isVisible, ...props }, ref): React.ReactElement => {
const buildClassName = (): string => {
return (
"flex-row items-center gap-2 bg-red-300 p-4 border-2 border-red-500 rounded-3xl" +
@ -22,7 +20,7 @@ export default React.forwardRef<any, Props>(
return (
<View className={buildClassName()} {...ref}>
<MaterialIcons name="error" size={24} color={"red"} />
<Text position="center" weight="bold" {...rest} />
<Text position="center" weight="bold" {...props} />
</View>
);
}

@ -12,8 +12,8 @@ interface Props extends FormInputProps {
}
export default React.forwardRef<any, Props>(
(props, ref): React.ReactElement => {
const {
(
{
onBlur,
onChangeText,
value,
@ -22,9 +22,10 @@ export default React.forwardRef<any, Props>(
label,
placeholder,
onPress,
...rest
} = props;
...props
},
ref
): React.ReactElement => {
return (
<View className="gap-2">
<Text weight="bold">{label}</Text>
@ -37,7 +38,7 @@ export default React.forwardRef<any, Props>(
onChangeText={onChangeText}
value={value}
{...ref}
{...rest}
{...props}
/>
{afterIcon != null ? (
<AntDesign name={afterIcon} size={24} onPress={onPress} />

@ -10,8 +10,7 @@ import { useSession } from "@/ctx";
import { router } from "expo-router";
export default React.forwardRef<any, ViewProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
({ ...props }, ref): React.ReactElement => {
const [email, setEmail] = React.useState("");
const [password, setPassword] = React.useState("");
const [error, setError] = React.useState("");
@ -47,7 +46,7 @@ export default React.forwardRef<any, ViewProps>(
};
return (
<View className="gap-4" {...ref} {...rest}>
<View className="gap-4" {...ref} {...props}>
<View className="gap-4">
<TextInput
beforeIcon="mail"

@ -2,8 +2,10 @@ import React, { useState } from "react";
import FormInput, { FormInputProps } from "./FormInput";
export default React.forwardRef<any, FormInputProps>(
(props, ref): React.ReactElement => {
const { onBlur, onChangeText, value, label, ...rest } = props;
(
{ onBlur, onChangeText, value, label, ...props },
ref
): React.ReactElement => {
const [showPassword, setShowPassword] = useState(false);
const toggleShowPassword = () => {
@ -22,7 +24,7 @@ export default React.forwardRef<any, FormInputProps>(
onPress={toggleShowPassword}
secureTextEntry={!showPassword}
{...ref}
{...rest}
{...props}
/>
);
}

@ -8,8 +8,7 @@ import { EMPTY_FIELD, INVALID_EMAIL, NOT_MATCHING_PASSWORD } from "../Errors";
import FormError from "./FormError";
export default React.forwardRef<any, ViewProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
({ ...props }, ref): React.ReactElement => {
const [email, setEmail] = React.useState("");
const [password, setPassword] = React.useState("");
const [confirmPassword, setConfirmPassword] = React.useState("");
@ -52,7 +51,7 @@ export default React.forwardRef<any, ViewProps>(
};
return (
<View className="gap-4" {...ref} {...rest}>
<View className="gap-4" {...ref} {...props}>
<View className="gap-4">
<TextInput
beforeIcon="mail"

@ -12,11 +12,9 @@ interface Props extends ModalProps {
}
export default React.forwardRef<any, Props>(
(props, ref): React.ReactElement => {
const { email, onPress, ...rest } = props;
({ email, onPress, ...props }, ref): React.ReactElement => {
return (
<Modal {...ref} animationType="fade" {...rest}>
<Modal {...ref} animationType="fade" {...props}>
<Screen>
<BackButton onPress={onPress} />
<View className="gap-4">

@ -1,78 +1,78 @@
import React from "react";
import React, { useImperativeHandle, useState } from "react";
import Question, { QuestionChildProps } from "./Question";
import Checkbox from "../CheckboxComponent";
import {View} from "react-native";
import {FontAwesome6} from "@expo/vector-icons";
import Checkbox from "../CheckBox";
import { View } from "react-native";
import {
CommunityIconNames,
AntDesignIconNames,
EntypoIconNames,
FontAwesome6IconNames,
} from "../Icons";
import { ESportLevel, SportLevels } from "@/model/enums/Enums";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
export interface ActivityQuestionRef {
getAnswer: () => ESportLevel;
}
const [checkedOne, setCheckedOne] = React.useState(true);
const [checkedTwo, setCheckedTwo] = React.useState(false);
const [checkedThree, setCheckedThree] = React.useState(false);
const [checkedFour, setCheckedFour] = React.useState(false);
const [checkedFive, setCheckedFive] = React.useState(false);
const handleChangeOne = () => {
if(!checkedOne) {
setCheckedOne(!checkedOne);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
}
};
const handleChangeTwo = () => {
if(!checkedTwo) {
setCheckedOne(false);
setCheckedTwo(!checkedTwo);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
}
};
const handleChangeThree = () => {
if(!checkedThree) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(!checkedThree);
setCheckedFour(false);
setCheckedFive(false);
}
};
const handleChangeFour = () => {
if(!checkedFour) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(!checkedFour);
setCheckedFive(false);
}
};
const handleChangeFive = () => {
if(!checkedFive) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(!checkedFive);
}
};
export default React.forwardRef<ActivityQuestionRef, QuestionChildProps>(
({ ...props }, ref): React.ReactElement => {
const [checkedItems, setCheckedItems] = useState([
true,
...Array(4).fill(false),
]);
return (
<Question
question="Comment estimez-vous votre niveau d'activité ?"
{...ref}
{...rest}
>
<View>
<Checkbox label="Athlète" value={checkedOne} onChange={handleChangeOne} icon={"smile-circle"} />
<Checkbox label="Très sportif" value={checkedTwo} onChange={handleChangeTwo} icon={"smileo"} />
<Checkbox label="Un peu sportif" value={checkedThree} onChange={handleChangeThree} icon={"meh"} />
<Checkbox label="Peu sportif" value={checkedFour} onChange={handleChangeFour} icon={"frowno"} />
<Checkbox label="Pas du tout sportif" value={checkedFive} onChange={handleChangeFive} icon={"frown"} />
</View>
</Question>
);
const handleChange = (index: number) => {
const newCheckedState = checkedItems.map((_, i) => i === index);
setCheckedItems(newCheckedState);
};
useImperativeHandle(ref, () => ({
getAnswer: () => {
var selected = 0;
checkedItems.forEach((item, index) => {
if (item) {
selected = index;
}
});
return SportLevels[SportLevels.length - 1 - selected];
},
}));
interface IData {
label: string;
commIcon?: CommunityIconNames;
antIcon?: AntDesignIconNames;
entypoIcon?: EntypoIconNames;
fontAwesomeIcon?: FontAwesome6IconNames;
}
const data: IData[] = [
{ label: "Athlète", antIcon: "smile-circle" },
{ label: "Très sportif", antIcon: "smileo" },
{ label: "Un peu sportif", antIcon: "meh" },
{ label: "Peu sportif", antIcon: "frowno" },
{ label: "Pas du tout sportif", antIcon: "frown" },
];
return (
<Question
question="Comment estimez-vous votre niveau d'activité ?"
{...ref}
{...props}
>
<View className="gap-2">
{data.map((item, index) => (
<Checkbox
key={index}
label={item.label}
value={checkedItems[index]}
onChange={() => handleChange(index)}
antIcon={item.antIcon}
endText={(data.length - index).toString()}
/>
))}
</View>
</Question>
);
}
);

@ -1,38 +1,53 @@
import React from "react";
import React, {
forwardRef,
ReactElement,
useImperativeHandle,
useState,
} from "react";
import Question, { QuestionChildProps } from "./Question";
import Slider from "../ui/Slider";
import { View } from "react-native";
import Text from "../ui/Text";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const MIN_AGE = 18;
const MAX_AGE = 100;
const [age, setAge] = React.useState(MIN_AGE);
const MIN_AGE = 18;
const MAX_AGE = 100;
export interface AgeQuestionRef {
getAnswer: () => number;
}
export default forwardRef<AgeQuestionRef, QuestionChildProps>(
(props, ref): ReactElement => {
const [answer, setAnswer] = useState<number>(MIN_AGE);
useImperativeHandle(ref, () => ({
getAnswer: () => answer,
}));
return (
<Question question="Quel âge avez-vous ?" {...ref} {...props}>
<View className="flex-row justify-center">
{age <= MIN_AGE ? (
{answer <= MIN_AGE ? (
<Text className="mt-8" size="4xl">
- de
</Text>
) : null}
{age >= MAX_AGE ? (
{answer >= MAX_AGE ? (
<Text className="mt-8" size="4xl">
+ de
</Text>
) : null}
<Text size="8xl" weight="bold">
{age}
{answer}
</Text>
<Text className="mt-8" size="4xl">
<Text className="mt-8 ml-1" size="4xl">
ans
</Text>
</View>
<Slider
minimumValue={MIN_AGE}
maximumValue={MAX_AGE}
onValueChange={setAge}
onValueChange={setAnswer}
/>
</Question>
);

@ -1,15 +1,35 @@
import React from "react";
import React, {
forwardRef,
ReactElement,
useImperativeHandle,
useState,
} from "react";
import Question, { QuestionChildProps } from "./Question";
import SegmentedControl from "../ui/SegmentedControl";
import { Image } from "react-native";
import { Image, View } from "react-native";
//@ts-ignore
import BenchImage from "@/assets/images/bench.png";
import CheckBox from "../CheckBox";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const ANSWERS = ["Non", "Oui"];
const [answer, setAnswer] = React.useState("Oui");
export interface BeginnerQuestionRef {
getAnswer: () => boolean;
}
export default forwardRef<BeginnerQuestionRef, QuestionChildProps>(
(props, ref): ReactElement => {
const [answer, setAnswer] = useState<boolean>(false);
useImperativeHandle(ref, () => ({
getAnswer: () => answer,
}));
function handleChangeOne() {
setAnswer(true);
}
function handleChangeTwo() {
setAnswer(false);
}
return (
<Question
@ -18,11 +38,21 @@ export default React.forwardRef<any, QuestionChildProps>(
{...props}
>
<Image className="self-center" source={BenchImage} alt="" />
<SegmentedControl
values={ANSWERS}
selectedIndex={ANSWERS.indexOf(answer)}
onValueChange={setAnswer}
/>
<View>
<CheckBox
className=""
label="Oui"
value={answer}
onChange={handleChangeOne}
fontAwesomeIcon={"check"}
/>
<CheckBox
label="Non"
value={!answer}
onChange={handleChangeTwo}
entypoIcon={"cross"}
/>
</View>
</Question>
);
}

@ -1,20 +1,33 @@
import React from "react";
import React, { useImperativeHandle } from "react";
import Question, { QuestionChildProps } from "./Question";
import Text from "../ui/Text";
import SegmentedControl from "../ui/SegmentedControl";
import { View } from "react-native";
const ANSWERS = ["1", "2", "3", "4", "5"];
export interface FrequencyQuestionRef {
getAnswer: () => number;
}
export interface FrequencyQuestionProps extends QuestionChildProps {
isMale: boolean;
}
export default React.forwardRef<any, FrequencyQuestionProps>(
(props, ref): React.ReactElement => {
const { isMale, ...rest } = props;
const ANSWERS = ["1", "2", "3", "4", "5"];
export default React.forwardRef<FrequencyQuestionRef, FrequencyQuestionProps>(
({ isMale, ...props }, ref): React.ReactElement => {
const [answer, setAnswer] = React.useState("1");
useImperativeHandle(ref, () => ({
getAnswer: () => parseInt(answer),
}));
return (
<Question question="Nombre de séance(s) par semaine ?" {...ref} {...rest}>
<Question
question="Nombre de séance(s) par semaine ?"
{...ref}
{...props}
>
<View className="items-center">
<Text size="2xl">
Je suis {isMale ? "prêt" : "prête"} à m'entraîner

@ -1,51 +1,55 @@
import React from "react";
import React, {
forwardRef,
ReactElement,
useImperativeHandle,
useState,
} from "react";
import Question, { QuestionChildProps } from "./Question";
import Checkbox from "../CheckboxComponent";
import {View} from "react-native";
import {FontAwesome6} from "@expo/vector-icons";
import Checkbox from "../CheckBox";
import { View } from "react-native";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
export interface GenderQuestionRef {
getAnswer: () => boolean;
}
const [checkedOne, setCheckedOne] = React.useState(false);
const [checkedTwo, setCheckedTwo] = React.useState(false);
const [checkedThree, setCheckedThree] = React.useState(true);
const handleChangeOne = () => {
if(!checkedOne)
{
setCheckedOne(!checkedOne);
setCheckedTwo(false);
setCheckedThree(false);
}
};
const handleChangeTwo = () => {
if(!checkedTwo) {
setCheckedOne(false);
setCheckedTwo(!checkedTwo);
setCheckedThree(false);
}
};
const handleChangeThree = () => {
if(!checkedThree) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(!checkedThree);
}
};
export default forwardRef<GenderQuestionRef, QuestionChildProps>(
({ ...props }, ref): ReactElement => {
const [answer, setAnswer] = useState(true);
return (
<Question
question="Quel est votre genre physiologique ?"
{...ref}
{...rest}
>
<View>
<Checkbox label="Homme" value={checkedOne} onChange={handleChangeOne} icon={"man"} />
<Checkbox label="Femme" value={checkedTwo} onChange={handleChangeTwo} icon={"woman"} />
<Checkbox label="Je ne préfère pas répondre" value={checkedThree} onChange={handleChangeThree} icon={"minuscircle"} />
</View>
</Question>
);
}
useImperativeHandle(ref, () => ({
getAnswer: () => answer,
}));
const handleChangeOne = () => {
setAnswer(true);
};
const handleChangeTwo = () => {
setAnswer(false);
};
return (
<Question
question="Quel est votre genre physiologique ?"
{...ref}
{...props}
>
<View className="gap-2">
<Checkbox
label="Homme"
value={answer}
onChange={handleChangeOne}
antIcon={"man"}
isCheckIconVisible={true}
/>
<Checkbox
label="Femme"
value={!answer}
onChange={handleChangeTwo}
antIcon={"woman"}
isCheckIconVisible={true}
/>
</View>
</Question>
);
}
);

@ -1,47 +1,87 @@
import React from "react";
import React, {
forwardRef,
ReactElement,
useImperativeHandle,
useState,
} from "react";
import Question, { QuestionChildProps } from "./Question";
import Checkbox from "../CheckboxComponent";
import {View} from "react-native";
import {FontAwesome6} from "@expo/vector-icons";
import { View } from "react-native";
import {
CommunityIconNames,
AntDesignIconNames,
EntypoIconNames,
FontAwesome6IconNames,
IonIconNames,
} from "../Icons";
import CheckBox from "../CheckBox";
import { EGoal, Goals } from "@/model/enums/Enums";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
export interface GoalQuestionRef {
getAnswer: () => EGoal;
}
const [checkedOne, setCheckedOne] = React.useState(true);
const [checkedTwo, setCheckedTwo] = React.useState(false);
const [checkedThree, setCheckedThree] = React.useState(false);
const [checkedFour, setCheckedFour] = React.useState(false);
const [checkedFive, setCheckedFive] = React.useState(false);
const handleChangeOne = () => {
setCheckedOne(!checkedOne);
export default forwardRef<GoalQuestionRef, QuestionChildProps>(
({ ...props }, ref): ReactElement => {
const [checkedItems, setCheckedItems] = useState([
true,
...Array(4).fill(false),
]);
interface IData {
label: string;
commIcon?: CommunityIconNames;
antIcon?: AntDesignIconNames;
entypoIcon?: EntypoIconNames;
fontAwesomeIcon?: FontAwesome6IconNames;
ionIcon?: IonIconNames;
}
const data: IData[] = [
{ label: "Perte de poids", commIcon: "weight" },
{ label: "Renforcement musculaire", commIcon: "arm-flex-outline" },
{ label: "Prise de masse", ionIcon: "beer-outline" },
{ label: "Amélioration endurance", fontAwesomeIcon: "shield-heart" },
{ label: "Maintenir en forme", antIcon: "linechart" },
];
const handleChange = (index: number) => {
const newCheckedState = checkedItems.map((_, i) => i === index);
setCheckedItems(newCheckedState);
};
const handleChangeTwo = () => {
setCheckedTwo(!checkedTwo);
};
const handleChangeThree = () => {
setCheckedThree(!checkedThree);
};
const handleChangeFour = () => {
setCheckedFour(!checkedFour);
};
const handleChangeFive = () => {
setCheckedFive(!checkedFive);
};
useImperativeHandle(ref, () => ({
getAnswer: () => {
var selected = 0;
checkedItems.forEach((item, index) => {
if (item) {
selected = index;
}
});
return Goals[selected];
},
}));
return (
<Question
question="Quel est votre objectif dans l'application ?"
{...ref}
{...rest}
{...props}
>
<View>
<Checkbox label="Perte de poids" value={checkedOne} onChange={handleChangeOne} icon="weight-scale" />
<Checkbox label="Renforcement musculaire" value={checkedTwo} onChange={handleChangeTwo} icon={"rest"} />
<Checkbox label="Prise de masse" value={checkedThree} onChange={handleChangeThree} icon="beer" />
<Checkbox label="Amélioration endurance" value={checkedFour} onChange={handleChangeFour} icon={"linechart"} />
<Checkbox label="Maintenir en forme" value={checkedFive} onChange={handleChangeFive} icon={"linechart"} />
</View>
<View className="gap-2">
{data.map((item, index) => (
<CheckBox
key={index}
label={item.label}
value={checkedItems[index]}
onChange={() => handleChange(index)}
fontAwesome6Icon={item.fontAwesomeIcon}
communityIcon={item.commIcon}
antIcon={item.antIcon}
entypoIcon={item.entypoIcon}
IonIcon={item.ionIcon}
/>
))}
</View>
</Question>
);
}

@ -1,17 +1,32 @@
import React from "react";
import React, {
forwardRef,
ReactElement,
useImperativeHandle,
useState,
} from "react";
import Question, { QuestionChildProps } from "./Question";
import Slider from "../ui/Slider";
import Text from "../ui/Text";
import { View } from "react-native";
import SegmentedControl from "../ui/SegmentedControl";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const MIN_HEIGHT = 120;
const MAX_HEIGHT = 250;
const MIN_HEIGHT = 120;
const MAX_HEIGHT = 250;
export interface HeightQuestionRef {
getAnswer: () => number;
}
export default forwardRef<HeightQuestionRef, QuestionChildProps>(
({ ...props }, ref): ReactElement => {
const [answer, setAnswer] = useState<number>(MIN_HEIGHT);
const UNITS = ["cm", "inch"];
const [height, setHeight] = React.useState(MIN_HEIGHT);
const [unit, setUnit] = React.useState("cm");
const [unit, setUnit] = useState<string>("cm");
useImperativeHandle(ref, () => ({
getAnswer: () => answer,
}));
return (
<Question question="Quel est votre taille ?" {...ref} {...props}>
<SegmentedControl
@ -20,18 +35,18 @@ export default React.forwardRef<any, QuestionChildProps>(
onValueChange={setUnit}
/>
<View className="flex-row justify-center">
{height <= MIN_HEIGHT ? (
{answer <= MIN_HEIGHT ? (
<Text className="mt-8" size="4xl">
- de
</Text>
) : null}
{height >= MAX_HEIGHT ? (
{answer >= MAX_HEIGHT ? (
<Text className="mt-8" size="4xl">
+ de
</Text>
) : null}
<Text size="8xl" weight="bold">
{height}
{answer}
</Text>
<Text className="mt-8" size="4xl">
{unit}
@ -40,7 +55,7 @@ export default React.forwardRef<any, QuestionChildProps>(
<Slider
minimumValue={MIN_HEIGHT}
maximumValue={MAX_HEIGHT}
onValueChange={setHeight}
onValueChange={setAnswer}
/>
</Question>
);

@ -0,0 +1,54 @@
import React, { useState } from "react";
import Question, { QuestionChildProps } from "./Question";
import { Image, View, Text } from "react-native";
import { MultiSelect } from "react-native-element-dropdown";
//@ts-ignore
import WheelChair from "@/assets/images/wheelchair.png";
import { EHealthProblem } from "@/model/enums/Enums";
export default React.forwardRef<any, QuestionChildProps>(
({ ...props }, ref) => {
const [selected, setSelected] = useState<string[]>([]);
type DataItem = {
label: string;
value: EHealthProblem;
};
const data: DataItem[] = [
{ label: "Arthrose", value: "ARTHROSE" },
{ label: "Migraine", value: "MIGRAINE" },
];
const renderItem = (item: { label: string }) => {
return (
<View className="p-4">
<Text>{item.label}</Text>
</View>
);
};
return (
<Question
question="Avez-vous des problèmes physiques ?"
{...props}
{...ref}
>
<Image className="self-center" source={WheelChair} alt="" />
<View className="border-2 border-orange-500 rounded-3xl p-4">
<MultiSelect
data={data}
labelField="label"
valueField="value"
placeholder="Selectionnez un problème physique "
searchPlaceholder="Search..."
value={selected}
onChange={setSelected}
renderItem={renderItem}
/>
</View>
</Question>
);
}
);

@ -1,15 +0,0 @@
import React from "react";
import Question, { QuestionChildProps } from "./Question";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
return (
<Question
question="Comment estimez vous votre niveau d'activité ?"
{...ref}
{...rest}
></Question>
);
}
);

@ -11,14 +11,13 @@ interface QuestionProps extends QuestionChildProps {
}
export default React.forwardRef<any, QuestionProps>(
(props, ref): React.ReactElement => {
const { question, isVisible, children, ...rest } = props;
({ question, isVisible, children, ...props }, ref): React.ReactElement => {
const getClassName = () => {
return "gap-6" + " " + (isVisible ? "block" : "hidden");
};
return (
<View className={getClassName()} {...ref} {...rest}>
<View className={getClassName()} {...ref} {...props}>
<Text size="4xl" position="center" weight="bold">
{question}
</Text>

@ -1,78 +1,91 @@
import React from "react";
import React, { useImperativeHandle, useState } from "react";
import Question, { QuestionChildProps } from "./Question";
import Checkbox from "../CheckboxComponent";
import {View} from "react-native";
import {FontAwesome6} from "@expo/vector-icons";
import Checkbox from "../CheckBox";
import { View } from "react-native";
import { ESleepLevel, SleepLevels } from "@/model/enums/Enums";
import { AntDesignIconNames } from "../Icons";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
export interface SleepQuestionRef {
getAnswer: () => ESleepLevel;
}
const [checkedOne, setCheckedOne] = React.useState(true);
const [checkedTwo, setCheckedTwo] = React.useState(false);
const [checkedThree, setCheckedThree] = React.useState(false);
const [checkedFour, setCheckedFour] = React.useState(false);
const [checkedFive, setCheckedFive] = React.useState(false);
const handleChangeOne = () => {
if(!checkedOne) {
setCheckedOne(!checkedOne);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
}
};
const handleChangeTwo = () => {
if(!checkedTwo) {
setCheckedOne(false);
setCheckedTwo(!checkedTwo);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
}
};
const handleChangeThree = () => {
if(!checkedThree) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(!checkedThree);
setCheckedFour(false);
setCheckedFive(false);
}
};
const handleChangeFour = () => {
if(!checkedFour) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(!checkedFour);
setCheckedFive(false);
}
};
const handleChangeFive = () => {
if(!checkedFive) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(!checkedFive);
}
};
export default React.forwardRef<SleepQuestionRef, QuestionChildProps>(
({ ...props }, ref): React.ReactElement => {
const [checkedItems, setCheckedItems] = useState([
true,
...Array(4).fill(false),
]);
return (
<Question
question="Quelle est la qualité de votre sommeil ?"
{...ref}
{...rest}
>
<View>
<Checkbox label="Excellente" value={checkedOne} onChange={handleChangeOne} icon={"smile-circle"} />
<Checkbox label="Bien" value={checkedTwo} onChange={handleChangeTwo} icon={"smileo"} />
<Checkbox label="Mauvaise" value={checkedThree} onChange={handleChangeThree} icon={"meh"} />
<Checkbox label="Très mauvaise" value={checkedFour} onChange={handleChangeFour} icon={"frowno"} />
<Checkbox label="Insomniaque" value={checkedFive} onChange={handleChangeFive} icon={"frown"} />
</View>
</Question>
);
const handleChange = (index: number) => {
const newCheckedState = checkedItems.map((_, i) => i === index);
setCheckedItems(newCheckedState);
};
useImperativeHandle(ref, () => ({
getAnswer: () => {
var selected = 0;
checkedItems.forEach((item, index) => {
if (item) {
selected = index;
}
});
return SleepLevels[SleepLevels.length - 1 - selected];
},
}));
interface IData {
label: string;
icon: AntDesignIconNames;
endText: string;
}
const data: IData[] = [
{
label: "Excellent",
icon: "smile-circle",
endText: ">8 heures",
},
{
label: "Bien",
icon: "smileo",
endText: "7-8 heures",
},
{
label: "Mauvaise",
icon: "meh",
endText: "6-7 heures",
},
{
label: "Très mauvaise",
icon: "frowno",
endText: "3-4 heures",
},
{
label: "Insomniaque",
icon: "frown",
endText: "<2 heures",
},
];
return (
<Question
question="Quelle est la qualité de votre sommeil ?"
{...ref}
{...props}
>
<View className="gap-2">
{data.map((item, index) => (
<Checkbox
key={index}
label={item.label}
value={checkedItems[index]}
onChange={() => handleChange(index)}
antIcon={item.icon}
endText={item.endText}
/>
))}
</View>
</Question>
);
}
);

@ -1,160 +1,86 @@
import React from "react";
import React, {
forwardRef,
ReactElement,
useImperativeHandle,
useState,
} from "react";
import Question, { QuestionChildProps } from "./Question";
import CheckButton from "../CheckButtonComponent";
import {View} from "react-native";
import {FontAwesome6} from "@expo/vector-icons";
import { View } from "react-native";
import CheckBox from "../CheckBox";
import {
AntDesignIconNames,
CommunityIconNames,
EntypoIconNames,
FontAwesome6IconNames,
} from "../Icons";
import { ESport, Sports } from "@/model/enums/Enums";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
export interface SportQuestionRef {
getAnswer: () => ESport;
}
const [checkedOne, setCheckedOne] = React.useState(true);
const [checkedTwo, setCheckedTwo] = React.useState(false);
const [checkedThree, setCheckedThree] = React.useState(false);
const [checkedFour, setCheckedFour] = React.useState(false);
const [checkedFive, setCheckedFive] = React.useState(false);
const [checkedSix, setCheckedSix] = React.useState(false);
const [checkedSeven, setCheckedSeven] = React.useState(false);
const [checkedEight, setCheckedEight] = React.useState(false);
const [checkedNine, setCheckedNine] = React.useState(false);
const handleChangeOne = () => {
if(!checkedOne) {
setCheckedOne(!checkedOne);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
setCheckedSix(false);
setCheckedSeven(false);
setCheckedEight(false);
setCheckedNine(false);
}
};
const handleChangeTwo = () => {
if(!checkedTwo) {
setCheckedOne(false);
setCheckedTwo(!checkedTwo);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
setCheckedSix(false);
setCheckedSeven(false);
setCheckedEight(false);
setCheckedNine(false);
}
};
const handleChangeThree = () => {
if(!checkedThree) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(!checkedThree);
setCheckedFour(false);
setCheckedFive(false);
setCheckedSix(false);
setCheckedSeven(false);
setCheckedEight(false);
setCheckedNine(false);
}
};
const handleChangeFour = () => {
if(!checkedFour) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(!checkedFour);
setCheckedFive(false);
setCheckedSix(false);
setCheckedSeven(false);
setCheckedEight(false);
setCheckedNine(false);
}
};
const handleChangeFive = () => {
if(!checkedFive) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(!checkedFive);
setCheckedSix(false);
setCheckedSeven(false);
setCheckedEight(false);
setCheckedNine(false);
}
};
const handleChangeSix = () => {
if(!checkedSix) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
setCheckedSix(!checkedSix);
setCheckedSeven(false);
setCheckedEight(false);
setCheckedNine(false);
}
};
const handleChangeSeven = () => {
if(!checkedSeven) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
setCheckedSix(false);
setCheckedSeven(!checkedSeven);
setCheckedEight(false);
setCheckedNine(false);
}
};
const handleChangeEight = () => {
if(!checkedEight) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
setCheckedSix(false);
setCheckedSeven(false);
setCheckedEight(!checkedEight);
setCheckedNine(false);
}
};
const handleChangeNine = () => {
if(!checkedNine) {
setCheckedOne(false);
setCheckedTwo(false);
setCheckedThree(false);
setCheckedFour(false);
setCheckedFive(false);
setCheckedSix(false);
setCheckedSeven(false);
setCheckedEight(false);
setCheckedNine(!checkedNine);
}
};
export default forwardRef<SportQuestionRef, QuestionChildProps>(
(props, ref): ReactElement => {
const [checkedItems, setCheckedItems] = useState([
true,
...Array(8).fill(false),
]);
return (
<Question
question="Quel sport ?"
{...ref}
{...rest}
>
<View className={`flex-wrap flex-row`}>
<CheckButton label="Course" value={checkedOne} onChange={handleChangeOne} fontAwesomeIcon={"person-running"} />
<CheckButton label="Marche" value={checkedTwo} onChange={handleChangeTwo} fontAwesomeIcon={"person-walking"} />
<CheckButton label="Rando" value={checkedThree} onChange={handleChangeThree} fontAwesomeIcon={"person-hiking"} />
const handleChange = (index: number) => {
const newCheckedState = checkedItems.map((_, i) => i === index);
setCheckedItems(newCheckedState);
};
<CheckButton label="Skate" value={checkedFour} onChange={handleChangeFour} communityIcon={"skateboarding"} />
<CheckButton label="Cyclisme" value={checkedFive} onChange={handleChangeFive} communityIcon={"bike"} />
<CheckButton label="Basket" value={checkedSix} onChange={handleChangeSix} fontAwesomeIcon={"basketball"} />
useImperativeHandle(ref, () => ({
getAnswer: () => {
var selected = 0;
checkedItems.forEach((item, index) => {
if (item) {
selected = index;
}
});
return Sports[selected];
},
}));
<CheckButton label="Cardio" value={checkedSeven} onChange={handleChangeSeven} antIcon={"heart"} />
<CheckButton label="Yoga" value={checkedEight} onChange={handleChangeEight} communityIcon={"yoga"} />
<CheckButton label="Autre" value={checkedNine} onChange={handleChangeNine} antIcon={"setting"} />
</View>
</Question>
);
interface IData {
label: string;
commIcon?: CommunityIconNames;
antIcon?: AntDesignIconNames;
entypoIcon?: EntypoIconNames;
fontAwesomeIcon?: FontAwesome6IconNames;
}
const data: IData[] = [
{ label: "Course", fontAwesomeIcon: "person-running" },
{ label: "Marche", fontAwesomeIcon: "person-walking" },
{ label: "Rando", fontAwesomeIcon: "person-hiking" },
{ label: "Skate", commIcon: "skateboarding" },
{ label: "Cyclisme", commIcon: "bike" },
{ label: "Basket", fontAwesomeIcon: "basketball" },
{ label: "Cardio", antIcon: "heart" },
{ label: "Yoga", commIcon: "yoga" },
{ label: "Autre", entypoIcon: "dots-three-horizontal" },
];
return (
<Question question="Quel sport pratiquez-vous ?" {...ref} {...props}>
<View className="flex-row justify-center flex-wrap gap-2">
{data.map((item, index) => (
<CheckBox
key={index}
label={item.label}
value={checkedItems[index]}
onChange={() => handleChange(index)}
fontAwesome6Icon={item.fontAwesomeIcon}
communityIcon={item.commIcon}
antIcon={item.antIcon}
entypoIcon={item.entypoIcon}
direction="col"
/>
))}
</View>
</Question>
);
}
);

@ -1,37 +1,52 @@
import React from "react";
import React, {
forwardRef,
ReactElement,
useImperativeHandle,
useState,
} from "react";
import Question, { QuestionChildProps } from "./Question";
import Slider from "../ui/Slider";
import Text from "../ui/Text";
import { View } from "react-native";
import SegmentedControl from "../ui/SegmentedControl";
export default React.forwardRef<any, QuestionChildProps>(
(props, ref): React.ReactElement => {
const MIN_WEIGHT = 40;
const MAX_WEIGHT = 200;
const MIN_WEIGHT = 40;
const MAX_WEIGHT = 200;
export interface WeightQuestionRef {
getAnswer: () => number;
}
const WeightQuestion = forwardRef<WeightQuestionRef, QuestionChildProps>(
(props, ref): ReactElement => {
const UNITS = ["kg", "lb"];
const [weight, setWeight] = React.useState(MIN_WEIGHT);
const [unit, setUnit] = React.useState("kg");
const [answer, setAnswer] = useState<number>(MIN_WEIGHT);
const [unit, setUnit] = useState<string>("kg");
useImperativeHandle(ref, () => ({
getAnswer: () => answer,
}));
return (
<Question question="Quel est votre poids ?" {...ref} {...props}>
<Question question="Quel est votre poids ?" {...props}>
<SegmentedControl
values={UNITS}
selectedIndex={UNITS.indexOf(unit)}
onValueChange={setUnit}
/>
<View className="flex-row justify-center gap-2">
{weight <= MIN_WEIGHT ? (
{answer <= MIN_WEIGHT && (
<Text className="mt-8" size="4xl">
- de
</Text>
) : null}
{weight >= MAX_WEIGHT ? (
)}
{answer >= MAX_WEIGHT && (
<Text className="mt-8" size="4xl">
+ de
</Text>
) : null}
)}
<Text size="8xl" weight="bold">
{weight}
{answer}
</Text>
<Text className="mt-8" size="4xl">
{unit}
@ -40,9 +55,11 @@ export default React.forwardRef<any, QuestionChildProps>(
<Slider
minimumValue={MIN_WEIGHT}
maximumValue={MAX_WEIGHT}
onValueChange={setWeight}
onValueChange={setAnswer}
/>
</Question>
);
}
);
export default WeightQuestion;

@ -8,7 +8,7 @@ import { Size } from "../Constants";
export type ButtonStyle = "default" | "outline" | "secondary";
//@ts-ignore
interface Props extends TouchableOpacityProps {
export interface ButtonProps extends TouchableOpacityProps {
size?: Size;
style?: ButtonStyle;
insideClassName?: string;
@ -16,9 +16,9 @@ interface Props extends TouchableOpacityProps {
afterIcon?: AntDesignIconNames;
}
export default React.forwardRef<any, Props>(
(props, ref): React.ReactElement => {
const {
export default React.forwardRef<any, ButtonProps>(
(
{
size,
style,
beforeIcon,
@ -27,9 +27,10 @@ export default React.forwardRef<any, Props>(
className,
insideClassName,
children,
...rest
} = props;
...props
},
ref
): React.ReactElement => {
const getButtonStyle = (): string => {
switch (style ?? "default") {
case "default":
@ -83,7 +84,7 @@ export default React.forwardRef<any, Props>(
};
return (
<View className={getButtonStyle()} {...ref} {...rest}>
<View className={getButtonStyle()} {...ref} {...props}>
<TouchableOpacity
className={"flex-row justify-center items-center gap-2 p-4 w-full"}
onPress={onPress}

@ -3,10 +3,9 @@ import { SafeAreaView } from "react-native-safe-area-context";
import React from "react";
export default React.forwardRef<any, ViewProps>(
(props, ref): React.ReactElement => {
const { children, ...rest } = props;
({ children, ...props }, ref): React.ReactElement => {
return (
<SafeAreaView className={"h-full p-4"} {...ref} {...rest}>
<SafeAreaView className={"h-full p-4"} {...ref} {...props}>
<View>{children}</View>
</SafeAreaView>
);

@ -2,8 +2,7 @@ import React from "react";
import Slider, { SliderProps } from "@react-native-community/slider";
export default React.forwardRef<any, SliderProps>(
(props, ref): React.ReactElement => {
const { ...rest } = props;
({ ...props }, ref): React.ReactElement => {
return (
<Slider
step={1}
@ -11,7 +10,7 @@ export default React.forwardRef<any, SliderProps>(
minimumTrackTintColor="#F97316"
maximumTrackTintColor="#F97316"
{...ref}
{...rest}
{...props}
/>
);
}

@ -20,18 +20,10 @@ export interface ExtendedTextProps extends TextProps {
}
export default React.forwardRef<any, ExtendedTextProps>(
(props, ref): React.ReactElement => {
const {
position,
color,
size,
weight,
isLink,
className,
children,
...rest
} = props;
(
{ position, color, size, weight, isLink, className, children, ...props },
ref
): React.ReactElement => {
const buildClassName = () => {
const textSize = toTextSize(size ?? "lg");
const textColor = toTextColor(color ?? "black");
@ -54,7 +46,7 @@ export default React.forwardRef<any, ExtendedTextProps>(
};
return (
<Text className={buildClassName()} {...ref} {...rest}>
<Text className={buildClassName()} {...ref} {...props}>
{children}
</Text>
);

@ -0,0 +1,146 @@
import {
EHealthProblem,
ESleepLevel,
ESport,
ESportLevel,
} from "./enums/Enums";
export class User {
private _name: string;
private _age: number;
private _height: number;
private _weight: number;
private _sexe: boolean; // true = Male, false = Female
private _logo: string;
private _nbSessionPerWeek: number;
private _goal: string;
private _healthProblems: EHealthProblem[];
private _sport: ESport;
private _sleepLevel: ESleepLevel;
private _sportLevel: ESportLevel;
constructor(
name: string,
age: number,
height: number,
weight: number,
sexe: boolean,
logo: string,
nbSessionPerWeek: number,
goal: string,
healthProblems: EHealthProblem[],
sport: ESport,
sleepLevel: ESleepLevel,
sportLevel: ESportLevel
) {
this._name = name;
this._age = age;
this._height = height;
this._weight = weight;
this._sexe = sexe;
this._logo = logo;
this._nbSessionPerWeek = nbSessionPerWeek;
this._goal = goal;
this._healthProblems = healthProblems;
this._sport = sport;
this._sleepLevel = sleepLevel;
this._sportLevel = sportLevel;
}
get name(): string {
return this._name;
}
get age(): number {
return this._age;
}
get height(): number {
return this._height;
}
get weight(): number {
return this._weight;
}
get sexe(): boolean {
return this._sexe;
}
get logo(): string {
return this._logo;
}
get nbSessionPerWeek(): number {
return this._nbSessionPerWeek;
}
get goals(): string {
return this._goal;
}
get healthProblems(): EHealthProblem[] {
return this._healthProblems;
}
get sports(): ESport {
return this._sport;
}
get sleepLevel(): ESleepLevel {
return this._sleepLevel;
}
get sportLevel(): ESportLevel {
return this._sportLevel;
}
// Setters
set name(value: string) {
this._name = value;
}
set age(value: number) {
this._age = value;
}
set height(value: number) {
this._height = value;
}
set weight(value: number) {
this._weight = value;
}
set sexe(value: boolean) {
this._sexe = value;
}
set logo(value: string) {
this._logo = value;
}
set nbSessionPerWeek(value: number) {
this._nbSessionPerWeek = value;
}
set goals(value: string) {
this._goal = value;
}
set healthProblems(value: EHealthProblem[]) {
this._healthProblems = value;
}
set sports(value: ESport) {
this._sport = value;
}
set sleepLevel(value: ESleepLevel) {
this._sleepLevel = value;
}
set sportLevel(value: ESportLevel) {
this._sportLevel = value;
}
}

@ -0,0 +1,42 @@
export const Goals = [
"WEIGHT_LOSE",
"IMPROVE_MUSCLE",
"WEIGHT_GAIN",
"IMPROVE_STAMINA",
"KEEP_FIT",
] as const;
export const SportLevels = [
"NOT_SPORTY",
"BEGINNER",
"SPORTY",
"VERY_SPORTY",
"PERFORMER",
] as const;
export const Sports = [
"RUNNING",
"WALKING",
"RANDO",
"SKATEBOARD",
"BIKING",
"BASKETBALL",
"CARDIO",
"YOGA",
"ELSE",
] as const;
export const SleepLevels = [
"TERRIBLE",
"VERY_BAD",
"BAD",
"GOOD",
"EXCELLENT",
] as const;
export type EGoal = (typeof Goals)[number];
export type ESportLevel = (typeof SportLevels)[number];
export type ESport = (typeof Sports)[number];
export type ESleepLevel = (typeof SleepLevels)[number];
export type EHealthProblem = "ARTHROSE" | "MIGRAINE";

17
package-lock.json generated

@ -37,6 +37,7 @@
"react-dom": "18.3.1",
"react-hook-form": "^7.54.2",
"react-native": "0.76.6",
"react-native-element-dropdown": "^2.12.4",
"react-native-gesture-handler": "^2.20.2",
"react-native-gifted-charts": "^1.4.54",
"react-native-reanimated": "^3.16.7",
@ -12247,6 +12248,22 @@
"node": ">=10"
}
},
"node_modules/react-native-element-dropdown": {
"version": "2.12.4",
"resolved": "https://registry.npmjs.org/react-native-element-dropdown/-/react-native-element-dropdown-2.12.4.tgz",
"integrity": "sha512-abZc5SVji9FIt7fjojRYrbuvp03CoeZJrgvezQoDoSOrpiTqkX69ix5m+j06W2AVncA0VWvbT+vCMam8SoVadw==",
"license": "MIT",
"dependencies": {
"lodash": "^4.17.21"
},
"engines": {
"node": ">= 16.0.0"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
}
},
"node_modules/react-native-gesture-handler": {
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.22.0.tgz",

@ -44,6 +44,7 @@
"react-dom": "18.3.1",
"react-hook-form": "^7.54.2",
"react-native": "0.76.6",
"react-native-element-dropdown": "^2.12.4",
"react-native-gesture-handler": "^2.20.2",
"react-native-gifted-charts": "^1.4.54",
"react-native-reanimated": "^3.16.7",

Loading…
Cancel
Save