From 15f9fb320da67a2aef92f8e21e583bf88d048613 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Tue, 9 Jul 2024 23:42:16 +0100 Subject: [PATCH] Changed approach on available type selection --- src/pages/(generation)/ReadingGeneration.tsx | 80 +++++++++----------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/src/pages/(generation)/ReadingGeneration.tsx b/src/pages/(generation)/ReadingGeneration.tsx index 2e919822..9a7297c4 100644 --- a/src/pages/(generation)/ReadingGeneration.tsx +++ b/src/pages/(generation)/ReadingGeneration.tsx @@ -26,16 +26,21 @@ import MatchSentencesEdit from "@/components/Generation/match.sentences.edit"; const DIFFICULTIES: Difficulty[] = ["easy", "medium", "hard"]; +const availableTypes = [ + { type: "fillBlanks", label: "Fill the Blanks" }, + { type: "trueFalse", label: "True or False" }, + { type: "writeBlanks", label: "Write the Blanks" }, + { type: "paragraphMatch", label: "Match Sentences" }, +]; + const PartTab = ({ part, - types, difficulty, index, setPart, updatePart, }: { part?: ReadingPart; - types: string[]; index: number; difficulty: Difficulty; setPart: (part?: ReadingPart) => void; @@ -44,6 +49,14 @@ const PartTab = ({ }) => { const [topic, setTopic] = useState(""); const [isLoading, setIsLoading] = useState(false); + const [types, setTypes] = useState([]); + + const toggleType = (type: string) => + setTypes((prev) => + prev.includes(type) + ? [...prev.filter((x) => x !== type)] + : [...prev, type] + ); const generate = () => { const url = new URLSearchParams(); @@ -181,6 +194,28 @@ const PartTab = ({ 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-reading/70 border-ielts-reading text-white" + )} + > + {x.label} + + ))} +
+
{ const [part2, setPart2] = useState(); const [part3, setPart3] = useState(); const [minTimer, setMinTimer] = useState(60); - const [types, setTypes] = useState([]); const [isLoading, setIsLoading] = useState(false); const [resultingExam, setResultingExam] = useState(); const [difficulty, setDifficulty] = useState( @@ -266,20 +300,6 @@ const ReadingGeneration = () => { const setExams = useExamStore((state) => state.setExams); const setSelectedModules = useExamStore((state) => state.setSelectedModules); - const availableTypes = [ - { type: "fillBlanks", label: "Fill the Blanks" }, - { type: "trueFalse", label: "True or False" }, - { type: "writeBlanks", label: "Write the Blanks" }, - { type: "paragraphMatch", label: "Match Sentences" }, - ]; - - const toggleType = (type: string) => - setTypes((prev) => - prev.includes(type) - ? [...prev.filter((x) => x !== type)] - : [...prev, type] - ); - const loadExam = async (examId: string) => { const exam = await getExamById("reading", examId.trim()); if (!exam) { @@ -333,7 +353,6 @@ const ReadingGeneration = () => { setPart3(undefined); setDifficulty(sample(DIFFICULTIES)!); setMinTimer(60); - setTypes([]); }) .catch((error) => { console.log(error); @@ -376,30 +395,6 @@ const ReadingGeneration = () => { />
- -
- -
- {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-reading/70 border-ielts-reading text-white" - )} - > - {x.label} - - ))} -
-
- { ].map(({ part, setPart }, index) => (