From 9ee8ebcda6516d662ccfd4a9ebf71910ed23ec1c Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Sat, 12 Oct 2024 18:35:57 +0600 Subject: [PATCH] run --- .../club/Components/Admin/AddQuestions.tsx | 17 ++-- src/app/club/Components/Home/DamianPopUp.tsx | 2 +- .../club/Components/Participate/Question.tsx | 27 +++++- .../club/admin/eventEdit/[eventID]/page.tsx | 94 ++++++++++--------- 4 files changed, 83 insertions(+), 57 deletions(-) diff --git a/src/app/club/Components/Admin/AddQuestions.tsx b/src/app/club/Components/Admin/AddQuestions.tsx index 57a153e..66a0d3b 100644 --- a/src/app/club/Components/Admin/AddQuestions.tsx +++ b/src/app/club/Components/Admin/AddQuestions.tsx @@ -179,23 +179,18 @@ const AddQuestions = ({ const deleteQuestion = (i: number) => { setQuestions((arr) => { - return [...arr.slice(0, i), ...arr.slice(i + 1, arr.length)]; + let a = [...arr.slice(0, i), ...arr.slice(i + 1, arr.length)]; + setQues && setQues(a); + return a; }); setAnswers((arr) => { - return [...arr.slice(0, i), ...arr.slice(i + 1, arr.length)]; + let a = [...arr.slice(0, i), ...arr.slice(i + 1, arr.length)]; + setAns && setAns(a); + return a; }); }; - useEffect(() => { - console.log("-------------"); - - console.log("qb", questions); - console.log("ab", answers); - - console.log("-------------"); - }, [questions, answers]); - const modifiedText = useMemo(() => { const lines = (question || "").split("\n"); diff --git a/src/app/club/Components/Home/DamianPopUp.tsx b/src/app/club/Components/Home/DamianPopUp.tsx index e71a622..51d2c07 100644 --- a/src/app/club/Components/Home/DamianPopUp.tsx +++ b/src/app/club/Components/Home/DamianPopUp.tsx @@ -30,7 +30,7 @@ const DamianPopUp = () => { const [roll, setRoll] = useState(""); useEffect(() => { - if (!userDataLoading && !userData?.ndc_roll) { + if (!userDataLoading && !userData?.ndc_roll && userAuth) { onOpen(); } }, [userData, userDataLoading]); diff --git a/src/app/club/Components/Participate/Question.tsx b/src/app/club/Components/Participate/Question.tsx index f61f632..b83401c 100644 --- a/src/app/club/Components/Participate/Question.tsx +++ b/src/app/club/Components/Participate/Question.tsx @@ -7,6 +7,7 @@ import remarkMath from "remark-math"; import "katex/dist/katex.min.css"; import rehypeHighlight from "rehype-highlight"; import "highlight.js/styles/atom-one-light.css"; +import { toast } from "react-toastify"; interface questionInterface { mcq: boolean; @@ -36,6 +37,7 @@ const Question = ({ givenAnswer, }: questionInterface) => { const [selectedVal, setSelectedVal] = useState(selectedOption); + const [savedOnce, setSavedOnce] = useState(givenAnswer === "" ? false : true); const options = [option0, option1, option2, option3]; const optionsArr = ["A", "B", "C", "D"]; @@ -71,7 +73,7 @@ const Question = ({ return (
-
+

{index + 1} @@ -114,12 +116,33 @@ const Question = ({ { - setAnswerData(selectedVal, e.target.value, index); + setAnswer(e.target.value); }} value={answer} name="answer" placeholder="Your Answer ..." /> +

+
+ {savedOnce ? ( + + Saved as: {givenAnswer} + + ) : ( + Not Saved Once + )} +
+ +
)} diff --git a/src/app/club/admin/eventEdit/[eventID]/page.tsx b/src/app/club/admin/eventEdit/[eventID]/page.tsx index 2d7c4d0..3bfb838 100644 --- a/src/app/club/admin/eventEdit/[eventID]/page.tsx +++ b/src/app/club/admin/eventEdit/[eventID]/page.tsx @@ -290,49 +290,40 @@ const Page = ({ params }: { params: { eventID: string } }) => { }); }; - // const save = async (event: any) => { - // localStorage.setItem( - // `event.${eventUID}`, - // JSON.stringify({ - // questions, - // answers, - // }), - // ); - // toast.info("Saved questions and answers."); - // }; - - useEffect(() => { - const t = setInterval(() => { - if (params.eventID !== "new") { - localStorage.setItem( - `event.${eventUID}`, - JSON.stringify({ - questions, - answers, - }), - ); - } - }, 1000 * 30); + const save = async (event: any) => { + localStorage.setItem( + `event.${eventUID}`, + JSON.stringify({ + questions, + answers, + }), + ); + toast.info("Saved questions and answers."); + }; - return () => { - clearInterval(t); - }; - }, [questions, answers, eventUID, params.eventID]); + // useEffect(() => { + // const t = setInterval(() => { + // if (params.eventID !== "new") { + // localStorage.setItem( + // `event.${eventUID}`, + // JSON.stringify({ + // questions, + // answers, + // }), + // ); + // } + // }, 1000 * 30); + + // return () => { + // clearInterval(t); + // }; + // }, [questions, answers, eventUID, params.eventID]); const loadLocal = async () => { const local = JSON.parse(localStorage.getItem(`event.${eventUID}`) || "{}"); console.dir(local); setData(local?.questions, local?.answers); toast.info("Loaded local questions and answers."); }; - - useEffect(() => { - console.log("-------------"); - - console.log("q", questions); - console.log("a", answers); - - console.log("-------------"); - }, [questions, answers]); const [notfound, setNotfound] = useState(false); const [changeImage, setChangeImage] = useState(); @@ -680,12 +671,14 @@ const Page = ({ params }: { params: { eventID: string } }) => { ) : null} } title="Caution" type="warning"> - Please do an inital save immediately after creating new event. If - you somehow lose your progress. you can back it up by using "Load - Backup" option. It will only work if you do it in same device you - were working on as well as not clear history and cache. + Please do an inital save immediately after creating new event. + Don't forget to save your progress, you can back it up by using + "Load Backup" option. But if you save blank then it will not work. + It will only work if you do it in same device you were working on + as well as not clear history and cache. Copy `event.[id]` in + localstorage to load and test questions in local. -
+
{params.eventID != "new" && ( { style={{ pointerEvents: loading ? "none" : "auto", }} - className="h-full w-full rounded-xl bg-primary px-8 py-2 text-lg text-white transition-all hover:bg-secondary_light hover:text-primary" + className="h-full w-full rounded-xl bg-primary px-8 py-2 text-center text-lg text-white transition-all hover:bg-secondary_light hover:text-primary" type="button" > Rankers @@ -701,7 +694,7 @@ const Page = ({ params }: { params: { eventID: string } }) => { )}
-
+
{loading ? ( ) : null} @@ -724,6 +717,21 @@ const Page = ({ params }: { params: { eventID: string } }) => {
+
+ +