diff --git a/src/app/api/getevents/route.ts b/src/app/api/getevents/route.ts
index 768cc0d..6b51b61 100644
--- a/src/app/api/getevents/route.ts
+++ b/src/app/api/getevents/route.ts
@@ -87,6 +87,7 @@ export async function POST(req: NextRequest) {
imageURL: e.data().imageURL,
description: e.data().description,
category: e.data().category,
+ participated: userParticipated.includes(e.id),
}));
return NextResponse.json({
diff --git a/src/app/api/getquestion/route.ts b/src/app/api/getquestion/route.ts
index 311c7ac..b50f90c 100644
--- a/src/app/api/getquestion/route.ts
+++ b/src/app/api/getquestion/route.ts
@@ -52,10 +52,7 @@ export async function POST(req: NextRequest) {
{ status: 404 },
);
} else if (now > endTime) {
- return NextResponse.json(
- { error: "The exam was over decades ago" },
- { status: 404 },
- );
+ return NextResponse.json({ error: "The exam is over" }, { status: 404 });
}
if ((data.ndc_id == "" || data.ndc_id == "none") && intra) {
diff --git a/src/app/club/Components/Admin/AddQuestions.tsx b/src/app/club/Components/Admin/AddQuestions.tsx
index efc57a5..57a153e 100644
--- a/src/app/club/Components/Admin/AddQuestions.tsx
+++ b/src/app/club/Components/Admin/AddQuestions.tsx
@@ -318,7 +318,7 @@ const AddQuestions = ({
onClick={() => {
setCorrectOption(i);
}}
- className={`h-10 w-10 rounded-full border border-primary_dark text-xl transition-colors ${
+ className={`h-10 w-10 shrink-0 rounded-full border border-primary_dark text-xl transition-colors ${
correctOption == i ? "bg-primary text-white" : "bg-white"
}`}
>
@@ -506,7 +506,7 @@ const Question = ({
type="button"
onClick={(e) => setCorrectOptionVal(i)}
disabled={!editing}
- className={`h-10 w-10 rounded-full border border-primary_dark text-xl transition-colors ${
+ className={`h-10 w-10 shrink-0 rounded-full border border-primary_dark text-xl transition-colors ${
correctOptionVal == i ? "bg-primary text-white" : "bg-white"
}`}
>
diff --git a/src/app/club/Components/Events/EventCard.tsx b/src/app/club/Components/Events/EventCard.tsx
index 91ab240..b4c0923 100644
--- a/src/app/club/Components/Events/EventCard.tsx
+++ b/src/app/club/Components/Events/EventCard.tsx
@@ -20,6 +20,7 @@ const EventCard = ({
desc,
id,
category,
+ participated,
}: {
title: string;
date: any;
@@ -29,6 +30,7 @@ const EventCard = ({
desc: string;
id: string;
category: string;
+ participated: boolean;
}) => {
const now = Timestamp.now();
@@ -44,19 +46,25 @@ const EventCard = ({
return (
- {ongoing && (
+ {participated && (
+
+ Participated
+
+ )}
+
+ {ongoing && !participated && (
Ongoing
)}
- {upcoming && (
+ {upcoming && !participated && (
Upcoming
)}
- {ended && (
+ {ended && !participated && (
Ended
diff --git a/src/app/club/Components/Events/EventList.tsx b/src/app/club/Components/Events/EventList.tsx
index a4b34f3..cab2b88 100644
--- a/src/app/club/Components/Events/EventList.tsx
+++ b/src/app/club/Components/Events/EventList.tsx
@@ -22,6 +22,7 @@ const EventList = ({
id={e.id}
key={i}
category={e.category}
+ participated={e.participated}
/>
);
})}
diff --git a/src/app/club/Components/Home/DamianPopUp.tsx b/src/app/club/Components/Home/DamianPopUp.tsx
index 17fc04a..e71a622 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) {
onOpen();
}
}, [userData, userDataLoading]);
diff --git a/src/app/club/Components/Participate/AnswerSheet.tsx b/src/app/club/Components/Participate/AnswerSheet.tsx
index 73d3fa0..77b7c77 100644
--- a/src/app/club/Components/Participate/AnswerSheet.tsx
+++ b/src/app/club/Components/Participate/AnswerSheet.tsx
@@ -4,7 +4,7 @@ import { doc, setDoc } from "firebase/firestore";
import { useAuthContext } from "../Layout/AuthContextProvider";
import Timer from "./Timer";
import Question from "./Question";
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { RiContactsBookUploadLine } from "react-icons/ri";
import ActualUser from "@/util/ActualUser";
import { CgSpinner } from "react-icons/cg";
@@ -72,9 +72,9 @@ const AnswerSheet = ({
description: string;
showResult: boolean;
}) => {
- const [answers, setAnswers] = useState
(
- Array(questions.length).fill({ option: 5, answer: "" }),
- );
+ const KEY = `event_answer_${id}`;
+ const INIT = Array(questions.length).fill({ option: 5, answer: "" });
+ const [answers, setAnswers] = useState(INIT);
const { isOpen, onOpen, onOpenChange } = useDisclosure();
@@ -103,6 +103,7 @@ const AnswerSheet = ({
const [examMarks, setExamMarks] = useState(1);
const [resultMarks, setResultMarks] = useState(0);
const [totalMarks, setTotalMarks] = useState(0);
+ const [loadedInit, setLoadedInit] = useState(false);
const SubmitFunc = async () => {
if (submitClicked) return;
@@ -114,11 +115,28 @@ const AnswerSheet = ({
setResultMarks(res.result);
setTotalMarks(res.totalMarks);
onOpen();
+ localStorage.removeItem(KEY);
//setSubmitClicked(false);
})
.catch(() => toast.error("Submission Error"));
};
+ useEffect(() => {
+ if (localStorage.getItem(KEY)) {
+ const ans = JSON.parse(localStorage.getItem(KEY) || "{}");
+ setAnswers(ans);
+ setLoadedInit(true);
+ } else {
+ setLoadedInit(true);
+ }
+ }, [KEY]);
+
+ useEffect(() => {
+ if (loadedInit) {
+ localStorage.setItem(KEY, JSON.stringify(answers));
+ }
+ }, [answers, loadedInit, KEY]);
+
const router = useRouter();
return (
diff --git a/src/app/club/Components/Participate/Question.tsx b/src/app/club/Components/Participate/Question.tsx
index 3714a20..f61f632 100644
--- a/src/app/club/Components/Participate/Question.tsx
+++ b/src/app/club/Components/Participate/Question.tsx
@@ -43,8 +43,13 @@ const Question = ({
const [answer, setAnswer] = useState(givenAnswer);
useEffect(() => {
- setAnswerData(selectedVal, answer, index);
- }, [selectedVal, answer]);
+ setAnswer(givenAnswer);
+ setSelectedVal(selectedOption);
+ }, [givenAnswer, selectedOption]);
+
+ // useEffect(() => {
+ // setAnswerData(selectedVal, answer, index);
+ // }, [selectedVal, answer]);
const modifiedText = useMemo(() => {
const lines = (question || "").split("\n");
@@ -92,7 +97,9 @@ const Question = ({
option={options[i]}
selected={selectedVal}
index={i}
- setSelected={setSelectedVal}
+ setSelected={(i) => {
+ setAnswerData(i, answer, index);
+ }}
key={i}
/>
);
@@ -107,7 +114,7 @@ const Question = ({
{
- setAnswer(e.currentTarget.value);
+ setAnswerData(selectedVal, e.target.value, index);
}}
value={answer}
name="answer"
diff --git a/src/app/club/admin/eventEdit/[eventID]/page.tsx b/src/app/club/admin/eventEdit/[eventID]/page.tsx
index dfe4372..2d7c4d0 100644
--- a/src/app/club/admin/eventEdit/[eventID]/page.tsx
+++ b/src/app/club/admin/eventEdit/[eventID]/page.tsx
@@ -31,6 +31,8 @@ import {
} from "@internationalized/date";
import { timeValue } from "@/app/club/Components/Time";
import Link from "next/link";
+import InfoBox from "@/app/club/Components/InfoBox";
+import { CiWarning } from "react-icons/ci";
const Page = ({ params }: { params: { eventID: string } }) => {
const [adminAuth, setAdminAuth] = useState(false);
@@ -288,29 +290,34 @@ const Page = ({ params }: { params: { eventID: string } }) => {
});
};
- const savelocal = async (event: any) => {
- localStorage.setItem(
- `event.${eventUID}`,
- JSON.stringify({
- questions,
- answers,
- }),
- );
- toast.info("Saved questions and answers.");
- goToAdminPanel();
- };
+ // const save = async (event: any) => {
+ // localStorage.setItem(
+ // `event.${eventUID}`,
+ // JSON.stringify({
+ // questions,
+ // answers,
+ // }),
+ // );
+ // toast.info("Saved questions and answers.");
+ // };
- 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);
+ return () => {
+ clearInterval(t);
+ };
+ }, [questions, answers, eventUID, params.eventID]);
const loadLocal = async () => {
const local = JSON.parse(localStorage.getItem(`event.${eventUID}`) || "{}");
console.dir(local);
@@ -545,6 +552,7 @@ const Page = ({ params }: { params: { eventID: string } }) => {
showMonthAndYearPickers
classNames={{
selectorIcon: "text-primary",
+ base: "bg-white rounded-xl shadow-none",
}}
value={date}
onChange={(e) => setDate(e)}
@@ -567,6 +575,7 @@ const Page = ({ params }: { params: { eventID: string } }) => {
showMonthAndYearPickers
classNames={{
selectorIcon: "text-primary",
+ base: "bg-white rounded-xl shadow-none",
}}
value={endDate}
onChange={(e) => setEndDate(e)}
@@ -670,85 +679,64 @@ 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.
+
+
+
{params.eventID != "new" && (
- {loading ? (
-
- ) : (
- "Rankers"
- )}
+ Rankers
)}
-
+
+ {loading ? (
+
+ ) : null}
+
{params.eventID != "new" && (
<>
- {loading ? (
-
- ) : (
-
- Delete
-
-
- )}
-
-
-
-
- {loading ? (
-
- ) : (
- "💾 Questions Locally"
- )}
-
-
-
-
- {loading ? (
-
- ) : (
- "💾 Questions Locally & Quit"
- )}
+
+ Delete
+
+
+
- {loading ? (
-
- ) : (
- "Load Local Ques."
- )}
+
+ Load Backup
+
>
@@ -758,15 +746,13 @@ const Page = ({ params }: { params: { eventID: string } }) => {
- {loading ? (
-
- ) : (
- "Submit"
- )}
+ {" "}
+ Submit