From d403f1c348ae5ea5353e8ec16838feb9a513e47a Mon Sep 17 00:00:00 2001 From: hansgabriel Date: Sun, 10 Dec 2023 23:27:23 +0800 Subject: [PATCH 1/4] Add question saving when changing views --- apps/expo/src/forms/CreateTestForm/index.tsx | 117 +++++++++--------- .../src/screens/create-question/index.tsx | 64 ++++++++-- apps/expo/src/screens/edit-test.tsx | 4 +- 3 files changed, 112 insertions(+), 73 deletions(-) diff --git a/apps/expo/src/forms/CreateTestForm/index.tsx b/apps/expo/src/forms/CreateTestForm/index.tsx index ba22029..dffd8c3 100644 --- a/apps/expo/src/forms/CreateTestForm/index.tsx +++ b/apps/expo/src/forms/CreateTestForm/index.tsx @@ -613,62 +613,59 @@ const CreateTestForm: FC = ({ )} - {questions.length > 0 && ( - <> - - - - Question ({questions.length}) - - - - View All - - - - - - {isLoading ? ( - - - - - - - - - ) : ( - { - return ( - - ); - }} + + + + Question {questions.length > 0 ? `(${questions.length})` : "()"} + + + + View All + + + + + + + {isLoading ? ( + + + - )} - - - - )} + + + + + + ) : ( + { + return ( + + ); + }} + /> + )} + + = ({ { setOpenAlert(false); - goBack(); }} isLoading={isCreatingQuiz} - onConfirm={handleSubmit(submitForm)} + onConfirm={() => { + setOpenAlert(false); + goBack(); + }} /> ); diff --git a/apps/expo/src/screens/create-question/index.tsx b/apps/expo/src/screens/create-question/index.tsx index 466a28e..057e1ba 100644 --- a/apps/expo/src/screens/create-question/index.tsx +++ b/apps/expo/src/screens/create-question/index.tsx @@ -191,7 +191,17 @@ export const CreateQuestionScreen: FC = () => { const snapPoints = useMemo(() => ["5%", "25%", "70%"], []); const openBottomSheet = () => { - handleSaveQuestion(); + const isValidInput = handleSaveQuestion({ + showToasts: false, + }); + + if (typeof isValidInput !== "boolean" || !isValidInput) { + errorToast({ + title: "Missing field", + message: "Please fill out all required fields", + }); + return; + } bottomSheetRef.current?.expand(); }; @@ -406,7 +416,11 @@ export const CreateQuestionScreen: FC = () => { const selectedImage = getSelectedImage(); - const handleSaveQuestion = () => { + const handleSaveQuestion = ({ + showToasts = true, + }: { + showToasts?: boolean; + } = {}) => { if (!questionType) return false; resetErrors(); const errors = checkErrors({ @@ -462,10 +476,12 @@ export const CreateQuestionScreen: FC = () => { editQuestion(selectedIndex!, question); resetQuestionImage(); resetErrors(); - successToast({ - title: "Success", - message: "Question saved successfully", - }); + if (showToasts) { + successToast({ + title: "Success", + message: "Question saved successfully", + }); + } return true; }; @@ -532,6 +548,18 @@ export const CreateQuestionScreen: FC = () => { }; const handleClickQuestion = (index: number) => () => { + const isValidInput = handleSaveQuestion({ + showToasts: false, + }); + + if (typeof isValidInput !== "boolean" || !isValidInput) { + errorToast({ + title: "Missing field", + message: "Please fill out all required fields", + }); + return; + } + setSelectedIndex(index); setSelectedQuestionId(index); setQuestionImage(questions[index]?.image ?? undefined); @@ -849,7 +877,7 @@ export const CreateQuestionScreen: FC = () => { { placeholderTextColor="#FFFFFF" /> {selectedChoice?.text && - selectedChoice?.text.length >= 100 ? ( + selectedChoice?.text.length >= 150 ? ( - You've reached the maximum of 100 characters. + You've reached the maximum of 150 characters. ) : null} @@ -996,9 +1024,9 @@ export const CreateQuestionScreen: FC = () => { { setOpenAlert(false); }} onConfirm={() => { - handleSaveQuestion(); + const isValidInput = handleSaveQuestion({ + showToasts: false, + }); + + if (typeof isValidInput !== "boolean" || !isValidInput) { + setOpenAlert(false); + errorToast({ + title: "Missing field", + message: "Please fill out all required fields", + }); + return; + } + resetQuestionImage(); goBack(); }} diff --git a/apps/expo/src/screens/edit-test.tsx b/apps/expo/src/screens/edit-test.tsx index c8755b5..5fb0eaa 100644 --- a/apps/expo/src/screens/edit-test.tsx +++ b/apps/expo/src/screens/edit-test.tsx @@ -37,7 +37,7 @@ export const EditTestScreen: FC> = ({ const [isUploading, setIsUploading] = useState(false); - const { data: testDetails, isLoading } = trpc.test.getById.useQuery( + const { data: testDetails, isFetching } = trpc.test.getById.useQuery( { testId }, { onSuccess: (data) => { @@ -179,7 +179,7 @@ export const EditTestScreen: FC> = ({ onSubmit={submitTestDetails} isCreatingQuiz={isEditingTest} isUploading={isUploading} - isLoading={isLoading} + isLoading={isFetching} /> From 159a37693a21f6b38f1d9fdd9b3a3b0a7e29030c Mon Sep 17 00:00:00 2001 From: hansgabriel Date: Mon, 11 Dec 2023 22:42:35 +0800 Subject: [PATCH 2/4] Fix requested changes --- apps/expo/src/forms/CreateTestForm/index.tsx | 28 ++++++++++--------- .../src/screens/create-question/index.tsx | 13 --------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/apps/expo/src/forms/CreateTestForm/index.tsx b/apps/expo/src/forms/CreateTestForm/index.tsx index dffd8c3..8ce9359 100644 --- a/apps/expo/src/forms/CreateTestForm/index.tsx +++ b/apps/expo/src/forms/CreateTestForm/index.tsx @@ -615,20 +615,22 @@ const CreateTestForm: FC = ({ )} - - - Question {questions.length > 0 ? `(${questions.length})` : "()"} - - - - View All + {questions.length > 0 && ( + + + Question ({questions.length}) - - - + + + View All + + + + + )} {isLoading ? ( diff --git a/apps/expo/src/screens/create-question/index.tsx b/apps/expo/src/screens/create-question/index.tsx index 057e1ba..7875e74 100644 --- a/apps/expo/src/screens/create-question/index.tsx +++ b/apps/expo/src/screens/create-question/index.tsx @@ -1035,19 +1035,6 @@ export const CreateQuestionScreen: FC = () => { setOpenAlert(false); }} onConfirm={() => { - const isValidInput = handleSaveQuestion({ - showToasts: false, - }); - - if (typeof isValidInput !== "boolean" || !isValidInput) { - setOpenAlert(false); - errorToast({ - title: "Missing field", - message: "Please fill out all required fields", - }); - return; - } - resetQuestionImage(); goBack(); }} From 0d42a06f57ba762fa9e83003efed9718ed130b72 Mon Sep 17 00:00:00 2001 From: hansgabriel Date: Mon, 11 Dec 2023 23:09:25 +0800 Subject: [PATCH 3/4] Fix flashlist warning --- apps/expo/src/forms/CreateTestForm/index.tsx | 32 +++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/apps/expo/src/forms/CreateTestForm/index.tsx b/apps/expo/src/forms/CreateTestForm/index.tsx index 8ce9359..521265d 100644 --- a/apps/expo/src/forms/CreateTestForm/index.tsx +++ b/apps/expo/src/forms/CreateTestForm/index.tsx @@ -651,20 +651,24 @@ const CreateTestForm: FC = ({ ) : ( - { - return ( - - ); - }} - /> + <> + {questions.length > 0 && ( + { + return ( + + ); + }} + /> + )} + )} From b4c313e109ded71d9e99c84b569dbb47614d71ec Mon Sep 17 00:00:00 2001 From: hansgabriel Date: Tue, 12 Dec 2023 01:07:50 +0800 Subject: [PATCH 4/4] Fix choice error outlines --- .../src/screens/create-question/ChoiceCard.tsx | 16 ++++------------ apps/expo/src/screens/create-question/index.tsx | 6 ++++++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/expo/src/screens/create-question/ChoiceCard.tsx b/apps/expo/src/screens/create-question/ChoiceCard.tsx index c5d2b6d..ef7c20c 100644 --- a/apps/expo/src/screens/create-question/ChoiceCard.tsx +++ b/apps/expo/src/screens/create-question/ChoiceCard.tsx @@ -113,9 +113,7 @@ export const MultipleChoiceCard: FC = ({ className={`flex h-36 w-36 flex-col flex-wrap items-center justify-evenly self-center rounded-2xl ${ choice.styles } ${ - errorState.choicesError[choice.id]?.length !== undefined - ? "border-2 border-red-500" - : "" + errorState.choicesError[choice.id]?.length !== undefined ? "" : "" } p-5`} onPress={handleOpenModal(choice.id)} > @@ -219,9 +217,7 @@ export const TrueOrFalseCard: FC = ({ className={`flex h-[220px] w-36 flex-col flex-wrap items-center justify-evenly self-center rounded-2xl ${ choice.styles } ${ - errorState.choicesError[choice.id]?.length !== undefined - ? "border-2 border-red-500" - : "" + errorState.choicesError[choice.id]?.length !== undefined ? "" : "" } p-5`} onPress={onPressCard} > @@ -328,9 +324,7 @@ export const MultiSelectCard: FC = ({ className={`flex h-16 w-[85vw] flex-col flex-wrap items-center justify-evenly self-center rounded-2xl ${ choice.styles } ${ - errorState.choicesError[choice.id]?.length !== undefined - ? "border-2 border-red-500" - : "" + errorState.choicesError[choice.id]?.length !== undefined ? "" : "" } p-5`} onPress={handleOpenModal(choice.id)} > @@ -442,9 +436,7 @@ export const IdentificationCard: FC = ({ className={`flex h-16 w-[85vw] flex-col flex-wrap items-center justify-evenly self-center rounded-2xl ${ choice.styles } ${ - errorState.choicesError[choice.id]?.length !== undefined - ? "border-2 border-red-500" - : "" + errorState.choicesError[choice.id]?.length !== undefined ? "" : "" } p-5`} onPress={handleOpenModal(choice.id)} > diff --git a/apps/expo/src/screens/create-question/index.tsx b/apps/expo/src/screens/create-question/index.tsx index 7875e74..d69f398 100644 --- a/apps/expo/src/screens/create-question/index.tsx +++ b/apps/expo/src/screens/create-question/index.tsx @@ -202,6 +202,7 @@ export const CreateQuestionScreen: FC = () => { }); return; } + bottomSheetRef.current?.expand(); }; @@ -548,6 +549,10 @@ export const CreateQuestionScreen: FC = () => { }; const handleClickQuestion = (index: number) => () => { + if (index === selectedIndex) { + return; + } + const isValidInput = handleSaveQuestion({ showToasts: false, }); @@ -560,6 +565,7 @@ export const CreateQuestionScreen: FC = () => { return; } + resetErrors(); setSelectedIndex(index); setSelectedQuestionId(index); setQuestionImage(questions[index]?.image ?? undefined);