[TestPage]: add regenerate test logic
This commit is contained in:
parent
24f07d5b84
commit
55a0bc34e8
|
@ -26,7 +26,7 @@ type QueryGenerateTestSimilarQualificationsQualificationArgs = {
|
|||
|
||||
const TestScreen = ({ route }: TestScreenProps) => {
|
||||
const variables = useVariables();
|
||||
const { data, loading, networkStatus } = useQuery<
|
||||
const { data, loading, networkStatus, refetch } = useQuery<
|
||||
Pick<Query, 'qualification' | 'generateTest' | 'similarQualifications'>,
|
||||
QueryGenerateTestSimilarQualificationsQualificationArgs
|
||||
>(QUERY_GENERATE_TEST_SIMILAR_QUALIFICATIONS_QUALIFICATION, {
|
||||
|
@ -55,7 +55,10 @@ const TestScreen = ({ route }: TestScreenProps) => {
|
|||
</Content>
|
||||
) : data?.qualification ? (
|
||||
data?.generateTest?.length ? (
|
||||
<Test questions={data.generateTest} />
|
||||
<Test
|
||||
questions={data.generateTest}
|
||||
onReset={() => refetch(undefined)}
|
||||
/>
|
||||
) : (
|
||||
<Suggestions
|
||||
qualifications={data?.similarQualifications.items ?? []}
|
||||
|
|
|
@ -12,6 +12,7 @@ export interface SummaryTabProps {
|
|||
answers: Answer[];
|
||||
questions: Question[];
|
||||
finishTest: () => void;
|
||||
resetTest: () => void;
|
||||
}
|
||||
|
||||
const SummaryTab = ({
|
||||
|
@ -19,6 +20,7 @@ const SummaryTab = ({
|
|||
answers,
|
||||
questions,
|
||||
finishTest,
|
||||
resetTest,
|
||||
}: SummaryTabProps) => {
|
||||
const correctAnswers = useMemo(() => {
|
||||
return answers.filter(
|
||||
|
@ -44,7 +46,7 @@ const SummaryTab = ({
|
|||
{polishPlurals('pytanie', 'pytania', 'pytań', correctAnswers)} z{' '}
|
||||
{total}.
|
||||
</H3>
|
||||
<Button full>
|
||||
<Button full onPress={resetTest}>
|
||||
<Text>Spróbuj ponownie</Text>
|
||||
</Button>
|
||||
</View>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useRef, useState } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Question as QuestionT, Answer } from 'libs/graphql';
|
||||
|
||||
import { ScrollableTab, Tab, Tabs } from 'native-base';
|
||||
|
@ -7,11 +7,10 @@ import SummaryTab from './SummaryTab';
|
|||
|
||||
export interface TestProps {
|
||||
questions: QuestionT[];
|
||||
onReset: () => void;
|
||||
}
|
||||
|
||||
const Test = ({ questions }: TestProps) => {
|
||||
const startedAtRef = useRef(new Date());
|
||||
const endedAtRef = useRef(new Date());
|
||||
const Test = ({ questions, onReset }: TestProps) => {
|
||||
const [reviewMode, setReviewMode] = useState(false);
|
||||
const [selectedAnswers, setSelectedAnswers] = useState<Answer[]>(
|
||||
new Array(questions.length).fill(''),
|
||||
|
@ -64,6 +63,7 @@ const Test = ({ questions }: TestProps) => {
|
|||
reviewMode={reviewMode}
|
||||
answers={selectedAnswers}
|
||||
questions={questions}
|
||||
resetTest={onReset}
|
||||
finishTest={() => setReviewMode(true)}
|
||||
/>
|
||||
</Tab>
|
||||
|
|
Reference in New Issue