Skip to content

Commit

Permalink
Merge pull request #50 from nditc/rafsan
Browse files Browse the repository at this point in the history
up
  • Loading branch information
RafsanAmin authored Oct 12, 2024
2 parents a1fd574 + 9c79af7 commit 4d1b841
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 94 deletions.
1 change: 1 addition & 0 deletions src/app/api/getevents/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 1 addition & 4 deletions src/app/api/getquestion/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/club/Components/Admin/AddQuestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}`}
>
Expand Down Expand Up @@ -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"
}`}
>
Expand Down
14 changes: 11 additions & 3 deletions src/app/club/Components/Events/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const EventCard = ({
desc,
id,
category,
participated,
}: {
title: string;
date: any;
Expand All @@ -29,6 +30,7 @@ const EventCard = ({
desc: string;
id: string;
category: string;
participated: boolean;
}) => {
const now = Timestamp.now();

Expand All @@ -44,19 +46,25 @@ const EventCard = ({

return (
<div className="hover: relative flex flex-col overflow-hidden rounded-xl bg-white shadow lg:h-[20rem] lg:flex-row">
{ongoing && (
{participated && (
<div className="absolute right-5 top-5 rounded-xl bg-green-500 px-3 py-1 text-sm text-white">
Participated
</div>
)}

{ongoing && !participated && (
<div className="absolute right-5 top-5 animate-pulse rounded-xl bg-orange-500 px-3 py-1 text-sm text-white">
Ongoing
</div>
)}

{upcoming && (
{upcoming && !participated && (
<div className="absolute right-5 top-5 rounded-xl bg-primary px-3 py-1 text-sm text-white">
Upcoming
</div>
)}

{ended && (
{ended && !participated && (
<div className="absolute right-5 top-5 rounded-xl bg-red-500 px-3 py-1 text-sm text-white">
Ended
</div>
Expand Down
1 change: 1 addition & 0 deletions src/app/club/Components/Events/EventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const EventList = ({
id={e.id}
key={i}
category={e.category}
participated={e.participated}
/>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion src/app/club/Components/Home/DamianPopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DamianPopUp = () => {
const [roll, setRoll] = useState("");

useEffect(() => {
if (!userDataLoading && userData?.ndc_roll) {
if (!userDataLoading && !userData?.ndc_roll) {
onOpen();
}
}, [userData, userDataLoading]);
Expand Down
26 changes: 22 additions & 4 deletions src/app/club/Components/Participate/AnswerSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -72,9 +72,9 @@ const AnswerSheet = ({
description: string;
showResult: boolean;
}) => {
const [answers, setAnswers] = useState<answerInterface[]>(
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<answerInterface[]>(INIT);

const { isOpen, onOpen, onOpenChange } = useDisclosure();

Expand Down Expand Up @@ -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;
Expand All @@ -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 (
Expand Down
15 changes: 11 additions & 4 deletions src/app/club/Components/Participate/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -92,7 +97,9 @@ const Question = ({
option={options[i]}
selected={selectedVal}
index={i}
setSelected={setSelectedVal}
setSelected={(i) => {
setAnswerData(i, answer, index);
}}
key={i}
/>
);
Expand All @@ -107,7 +114,7 @@ const Question = ({
<input
className="h-16 rounded-xl border border-gray-300 px-5 py-3 focus:border-primary focus:outline-none"
onChange={(e) => {
setAnswer(e.currentTarget.value);
setAnswerData(selectedVal, e.target.value, index);
}}
value={answer}
name="answer"
Expand Down
Loading

0 comments on commit 4d1b841

Please sign in to comment.