log start/finish test
This commit is contained in:
parent
63fbd16a57
commit
2089bfe681
|
@ -3,7 +3,7 @@ import { useEffectOnce, useUpdateEffect } from 'react-use';
|
|||
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
|
||||
import analytics from '@react-native-firebase/analytics';
|
||||
import { context as Context } from './context';
|
||||
import { Event } from '../../config/analytics';
|
||||
import { Event } from 'config/analytics';
|
||||
|
||||
export interface SavedQualificationsProviderProps {
|
||||
children?: React.ReactNode;
|
||||
|
|
|
@ -56,6 +56,7 @@ const TestScreen = ({ route }: TestScreenProps) => {
|
|||
) : data?.qualification ? (
|
||||
data?.generateTest?.length ? (
|
||||
<Test
|
||||
qualification={data.qualification}
|
||||
questions={data.generateTest}
|
||||
onReset={() => refetch(undefined)}
|
||||
/>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Question as QuestionT, Answer } from 'libs/graphql';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import analytics from '@react-native-firebase/analytics';
|
||||
import { Question as QuestionT, Answer, Qualification } from 'libs/graphql';
|
||||
import { Event } from 'config/analytics';
|
||||
|
||||
import { ScrollableTab, Tab, Tabs } from 'native-base';
|
||||
import Question from './Question';
|
||||
|
@ -8,14 +10,27 @@ import SummaryTab from './SummaryTab';
|
|||
export interface TestProps {
|
||||
questions: QuestionT[];
|
||||
onReset: () => void;
|
||||
qualification: Qualification;
|
||||
}
|
||||
|
||||
const Test = ({ questions, onReset }: TestProps) => {
|
||||
const Test = ({ questions, onReset, qualification }: TestProps) => {
|
||||
const [reviewMode, setReviewMode] = useState(false);
|
||||
const [selectedAnswers, setSelectedAnswers] = useState<Answer[]>(
|
||||
new Array(questions.length).fill(''),
|
||||
);
|
||||
|
||||
const analyticsParams = useMemo(
|
||||
() => ({
|
||||
qualificationID: qualification.id.toString(),
|
||||
questions: questions.length.toString(),
|
||||
}),
|
||||
[qualification, questions],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
analytics().logEvent(Event.StartTest, analyticsParams);
|
||||
}, [analyticsParams]);
|
||||
|
||||
const createSelectAnswerHandler = (index: number) => (answer: Answer) => {
|
||||
if (reviewMode) {
|
||||
return;
|
||||
|
@ -27,6 +42,11 @@ const Test = ({ questions, onReset }: TestProps) => {
|
|||
);
|
||||
};
|
||||
|
||||
const handleFinishTest = () => {
|
||||
setReviewMode(true);
|
||||
analytics().logEvent(Event.FinishTest, analyticsParams);
|
||||
};
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
renderTabBar={(props: any) => {
|
||||
|
@ -65,7 +85,7 @@ const Test = ({ questions, onReset }: TestProps) => {
|
|||
answers={selectedAnswers}
|
||||
questions={questions}
|
||||
resetTest={onReset}
|
||||
finishTest={() => setReviewMode(true)}
|
||||
finishTest={handleFinishTest}
|
||||
/>
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
|
Reference in New Issue