diff --git a/src/pages/(generation)/ListeningGeneration.tsx b/src/pages/(generation)/ListeningGeneration.tsx index 66802eb9..fdbf36a7 100644 --- a/src/pages/(generation)/ListeningGeneration.tsx +++ b/src/pages/(generation)/ListeningGeneration.tsx @@ -18,23 +18,42 @@ import WriteBlanksEdit from "@/components/Generation/write.blanks.edit"; const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"]; +const MULTIPLE_CHOICE = { type: "multipleChoice", label: "Multiple Choice" }; +const WRITE_BLANKS_QUESTIONS = { + type: "writeBlanksQuestions", + label: "Write the Blanks: Questions", +}; +const WRITE_BLANKS_FILL = { + type: "writeBlanksFill", + label: "Write the Blanks: Fill", +}; +const WRITE_BLANKS_FORM = { + type: "writeBlanksForm", + label: "Write the Blanks: Form", +}; +const MULTIPLE_CHOICE_3 = { + type: "multipleChoice3Options", + label: "Multiple Choice", +}; + const PartTab = ({ part, - types, difficulty, + availableTypes, index, setPart, updatePart, }: { part?: ListeningPart; difficulty: Difficulty; - types: string[]; + availableTypes: { type: string; label: string }[]; index: number; setPart: (part?: ListeningPart) => void; updatePart: Dispatch>; }) => { const [topic, setTopic] = useState(""); const [isLoading, setIsLoading] = useState(false); + const [types, setTypes] = useState([]); const generate = () => { const url = new URLSearchParams(); @@ -126,8 +145,37 @@ const PartTab = ({ }); }; + const toggleType = (type: string) => + setTypes((prev) => + prev.includes(type) + ? [...prev.filter((x) => x !== type)] + : [...prev, type] + ); + return ( +
+ +
+ {availableTypes.map((x) => ( + toggleType(x.type)} + key={x.type} + className={clsx( + "px-6 py-4 w-64 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer", + "transition duration-300 ease-in-out", + !types.includes(x.type) + ? "bg-white border-mti-gray-platinum" + : "bg-ielts-listening/70 border-ielts-listening text-white" + )} + > + {x.label} + + ))} +
+
{ const [minTimer, setMinTimer] = useState(30); const [isLoading, setIsLoading] = useState(false); const [resultingExam, setResultingExam] = useState(); - const [types, setTypes] = useState([]); const [difficulty, setDifficulty] = useState( sample(DIFFICULTIES)! ); @@ -243,25 +290,11 @@ const ListeningGeneration = () => { setMinTimer(sum > 0 ? sum : 5); }, [part1, part2, part3, part4]); - const availableTypes = [ - { type: "multipleChoice", label: "Multiple Choice" }, - { type: "writeBlanksQuestions", label: "Write the Blanks: Questions" }, - { type: "writeBlanksFill", label: "Write the Blanks: Fill" }, - { type: "writeBlanksForm", label: "Write the Blanks: Form" }, - ]; - const router = useRouter(); const setExams = useExamStore((state) => state.setExams); const setSelectedModules = useExamStore((state) => state.setSelectedModules); - const toggleType = (type: string) => - setTypes((prev) => - prev.includes(type) - ? [...prev.filter((x) => x !== type)] - : [...prev, type] - ); - const submitExam = () => { const parts = [part1, part2, part3, part4].filter((x) => !!x); console.log({ parts }); @@ -289,7 +322,6 @@ const ListeningGeneration = () => { setPart3(undefined); setPart4(undefined); setDifficulty(sample(DIFFICULTIES)!); - setTypes([]); }) .catch((error) => { console.log(error); @@ -349,30 +381,6 @@ const ListeningGeneration = () => { />
- -
- -
- {availableTypes.map((x) => ( - toggleType(x.type)} - key={x.type} - className={clsx( - "px-6 py-4 w-64 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer", - "transition duration-300 ease-in-out", - !types.includes(x.type) - ? "bg-white border-mti-gray-platinum" - : "bg-ielts-listening/70 border-ielts-listening text-white" - )} - > - {x.label} - - ))} -
-
- { {[ - { part: part1, setPart: setPart1 }, - { part: part2, setPart: setPart2 }, - { part: part3, setPart: setPart3 }, - { part: part4, setPart: setPart4 }, - ].map(({ part, setPart }, index) => ( + { + part: part1, + setPart: setPart1, + types: [ + MULTIPLE_CHOICE, + WRITE_BLANKS_QUESTIONS, + WRITE_BLANKS_FILL, + WRITE_BLANKS_FORM, + ], + }, + { + part: part2, + setPart: setPart2, + types: [MULTIPLE_CHOICE, WRITE_BLANKS_QUESTIONS], + }, + { + part: part3, + setPart: setPart3, + types: [MULTIPLE_CHOICE_3, WRITE_BLANKS_QUESTIONS], + }, + { + part: part4, + setPart: setPart4, + types: [ + MULTIPLE_CHOICE, + WRITE_BLANKS_QUESTIONS, + WRITE_BLANKS_FILL, + WRITE_BLANKS_FORM, + ], + }, + ].map(({ part, setPart, types }, index) => (