From bcc6e3dc2edd260ea5d03f867a0fc90c0df7d89e Mon Sep 17 00:00:00 2001 From: hansgabriel Date: Tue, 5 Dec 2023 17:37:14 +0800 Subject: [PATCH] Fix replacing question --- apps/expo/src/forms/CreateTestForm/index.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/expo/src/forms/CreateTestForm/index.tsx b/apps/expo/src/forms/CreateTestForm/index.tsx index 691779e..a200090 100644 --- a/apps/expo/src/forms/CreateTestForm/index.tsx +++ b/apps/expo/src/forms/CreateTestForm/index.tsx @@ -94,10 +94,9 @@ const CreateTestForm: FC = ({ const randomizeQuestionType = Math.floor(Math.random() * types.length); const questionType = types[randomizeQuestionType]; - const [selectedQuestionType, setSelectedQuestionType] = - useState( - questionType !== undefined ? questionType : "multiple_choice", - ); + const [selectedQuestionType] = useState( + questionType !== undefined ? questionType : "multiple_choice", + ); const [openAlert, setOpenAlert] = useState(false); const [isBottomSheetOpen, setBottomSheetOpen] = useState(false); const [errorInAIQuestion, setErrorInAIQuestion] = useState(false); @@ -187,6 +186,9 @@ const CreateTestForm: FC = ({ const isLastQuestionInEdit = useQuestionStore( (state) => state.isLastQuestionInEdit, ); + const deleteLastQuestion = useQuestionStore( + (state) => state.deleteLastQuestion, + ); const addEmptyQuestion = useQuestionStore((state) => state.addEmptyQuestion); const setLastIndex = useQuestionStore((state) => state.setLastIndex); @@ -212,16 +214,16 @@ const CreateTestForm: FC = ({ }; const goToCreateQuestion = (questionType: QuestionType) => { - setSelectedQuestionType(questionType); if (isLastQuestionInEdit()) { - //create + deleteLastQuestion(); + addEmptyQuestion(questionType); setLastIndex(); + navigation.navigate("CreateQuestion"); } else { - //edit addEmptyQuestion(questionType); setLastIndex(); + navigation.navigate("CreateQuestion"); } - navigation.navigate("CreateQuestion"); }; const goToEditQuestion = (questionIndex: number) => () => { @@ -398,7 +400,6 @@ const CreateTestForm: FC = ({ }), ); removeBlankQuestions(); - addEmptyQuestion(selectedQuestionType); setLastIndex(); setErrorInAIQuestion(false); setShowNumberOfQuestionsModal(false);