HoshiAI-app/app/tests/[id].tsx

51 lines
1.4 KiB
TypeScript

import { useTest } from "@/api/tests";
import Question from "@/components/question";
import Test from "@/components/test";
import { Button, ButtonText } from "@/components/ui/button";
import Content from "@/components/ui/content";
import { Stack, useLocalSearchParams } from "expo-router";
import { View } from "react-native";
import { useToast } from "react-native-toast-notifications";
const TestScreen = () => {
const { id: idParam } = useLocalSearchParams<{ id: string }>();
const id = +idParam;
const { data, isLoading } = useTest(id);
const toast = useToast();
if (!data)
return (
<>
<Stack.Screen options={{ title: `Test #${id}` }} />
<Content>{isLoading && <Test />}</Content>
</>
);
const handleStartTest = () => {
toast.show("Test started!", { type: "success" });
};
return (
<>
<Stack.Screen options={{ title: `Test #${id}` }} />
<Content>
<View className="mb-3">
<Test test={data} />
</View>
{data.is_available && <Button className="mb-3" onPress={handleStartTest}>
<ButtonText>Start Test</ButtonText>
</Button>}
<View className="gap-4">
{data.questions?.map((question) => (
<Question key={question.id} question={question} />
))}
</View>
</Content>
</>
);
};
export default TestScreen;