From 4990246a35fd18384e71af10dfa45b0f9ef95d14 Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Tue, 1 Oct 2024 23:41:09 +0600 Subject: [PATCH 01/31] sdsd --- src/app/(main)/activities/Upcoming.tsx | 18 +++--------- src/app/(main)/activities/page.tsx | 27 ++++++++++-------- src/app/(main)/styles/markdown.css | 38 ++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/app/(main)/activities/Upcoming.tsx b/src/app/(main)/activities/Upcoming.tsx index 807b0f4..54e90d6 100644 --- a/src/app/(main)/activities/Upcoming.tsx +++ b/src/app/(main)/activities/Upcoming.tsx @@ -10,8 +10,6 @@ interface Props { description: string; actionButtonTitle1: string; actionButtonRedirect1: string; - actionButtonTitle2: string; - actionButtonRedirect2: string; image: string; timestamp: number; } @@ -74,8 +72,6 @@ const Upcoming = ({ description, actionButtonTitle1, actionButtonRedirect1, - actionButtonTitle2, - actionButtonRedirect2, image, timestamp, }: Props) => { @@ -86,7 +82,7 @@ const Upcoming = ({ const firstTwoWords = words.slice(0, 2).join(" "); const restOfSentence = words.slice(2).join(" "); - const detailsEncrypt = encrypt(actionButtonRedirect2); + const detailsEncrypt = encrypt(actionButtonRedirect1); return (
@@ -95,7 +91,7 @@ const Upcoming = ({ {"Image"}
@@ -105,21 +101,15 @@ const Upcoming = ({ {restOfSentence}
-

{description}

+

{description}

- -
{actionButtonTitle1}
-
-
{actionButtonTitle2}
+
{actionButtonTitle1}
diff --git a/src/app/(main)/activities/page.tsx b/src/app/(main)/activities/page.tsx index 9a83ec9..d5b4a2e 100644 --- a/src/app/(main)/activities/page.tsx +++ b/src/app/(main)/activities/page.tsx @@ -60,18 +60,21 @@ const Activities = async ({

UPCOMING

EVENT

-
- +
+ {upcoming.map((d, ind) => { + return ( + + ); + })}
) : null} diff --git a/src/app/(main)/styles/markdown.css b/src/app/(main)/styles/markdown.css index ebca6c7..2b9819a 100644 --- a/src/app/(main)/styles/markdown.css +++ b/src/app/(main)/styles/markdown.css @@ -10,18 +10,25 @@ .markdown p { padding-bottom: 0.5rem; } + +.markdown p::first-line { + padding-left: 1rem; +} .markdown a { color: #3b82f6; } .markdown h1 { font-size: 2.25rem; - padding-top: 1.25rem; - padding-bottom: 0.5rem; + padding-top: 2.5rem; + padding-bottom: 1rem; font-weight: 400; } +/* .markdown h1::first-letter { + color: #2f4770; +} */ .markdown h2 { font-size: 1.875rem; - padding-top: 1.15rem; + padding-top: 2.5rem; padding-bottom: 0.5rem; font-weight: 400; } @@ -30,11 +37,17 @@ .markdown h5, .markdown h6 { font-size: 1.5rem; - padding-top: 0.65rem; - padding-bottom: 0.5rem; + padding-top: 0.25rem; + padding-bottom: 0.25rem; font-family: Nunito; font-weight: 700; } + +.markdown h4, +.markdown h5, +.markdown h6 { + font-size: 1.25rem !important; +} .markdown table { border: 1px solid #e4e4e7; border-radius: 2px; @@ -53,3 +66,18 @@ padding: 0.5rem 2rem; border: 1px solid #d1d5db; } + +.markdown ul { + list-style-type: circle; + list-style-position: inside; +} + +.markdown ol { + list-style-type: decimal; + list-style-position: inside; +} + +.markdown li::marker { + color: #3b82f6; + font-weight: bold; +} From 1dcaaae5a53649c764a4314809edfaf4eb436916 Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Tue, 1 Oct 2024 23:46:59 +0600 Subject: [PATCH 02/31] f --- src/app/(main)/activities/Upcoming.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/(main)/activities/Upcoming.tsx b/src/app/(main)/activities/Upcoming.tsx index 54e90d6..8923993 100644 --- a/src/app/(main)/activities/Upcoming.tsx +++ b/src/app/(main)/activities/Upcoming.tsx @@ -85,9 +85,9 @@ const Upcoming = ({ const detailsEncrypt = encrypt(actionButtonRedirect1); return ( -
+
-
+
{"Image"} Date: Fri, 4 Oct 2024 11:09:16 +0600 Subject: [PATCH 03/31] Tweak --- src/app/club/Components/Profile/ClubInfo.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/club/Components/Profile/ClubInfo.tsx b/src/app/club/Components/Profile/ClubInfo.tsx index 0c69fd4..07d0367 100644 --- a/src/app/club/Components/Profile/ClubInfo.tsx +++ b/src/app/club/Components/Profile/ClubInfo.tsx @@ -109,7 +109,7 @@ const ClubInfo = ({ ndc_roll: roll, }); - toast.success("Data Updated!"); + toast.success("NDC Roll Updated!"); updateUserData(); setEditing(false); setLoading(false); From f633542d56060ff8dd1ea3aba5e0db76f0023562 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Fri, 4 Oct 2024 15:24:07 +0600 Subject: [PATCH 04/31] Event Details Page Eligibility Tweak --- src/app/club/eventdetails/[id]/ParticipateButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/club/eventdetails/[id]/ParticipateButton.tsx b/src/app/club/eventdetails/[id]/ParticipateButton.tsx index acd48ab..de875de 100644 --- a/src/app/club/eventdetails/[id]/ParticipateButton.tsx +++ b/src/app/club/eventdetails/[id]/ParticipateButton.tsx @@ -57,7 +57,7 @@ const ParticipateButton = ({ ); } - return
; + return
You are not eligible for this exam
; }; export default ParticipateButton; From 3ef837cea606c4bc6fb034f41ba20c631a447617 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Fri, 4 Oct 2024 21:24:56 +0600 Subject: [PATCH 05/31] Tweak --- .../club/eventdetails/[id]/Eligibility.tsx | 26 +++++++++++++++++++ .../eventdetails/[id]/ParticipateButton.tsx | 2 +- src/app/club/eventdetails/[id]/page.tsx | 9 ++++++- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/app/club/eventdetails/[id]/Eligibility.tsx diff --git a/src/app/club/eventdetails/[id]/Eligibility.tsx b/src/app/club/eventdetails/[id]/Eligibility.tsx new file mode 100644 index 0000000..f3e1791 --- /dev/null +++ b/src/app/club/eventdetails/[id]/Eligibility.tsx @@ -0,0 +1,26 @@ +"use client"; + +import { useUserDataContext } from "../../Components/Layout/UserDataProvider"; + +const Eligibility = ({ + intra_club, + intra_college, + publicQuiz, +}: { + intra_club: boolean; + intra_college: boolean; + publicQuiz: boolean; +}) => { + const { userData, userDataLoading, dataError } = useUserDataContext(); + if (intra_college && userData && userData.ndc_roll != "") return
; + if (intra_club && userData && userData.ndc_id != "") return
; + if (publicQuiz && userData) return
; + + return ( +
+ You are not eligible for this exam +
+ ); +}; + +export default Eligibility; diff --git a/src/app/club/eventdetails/[id]/ParticipateButton.tsx b/src/app/club/eventdetails/[id]/ParticipateButton.tsx index de875de..acd48ab 100644 --- a/src/app/club/eventdetails/[id]/ParticipateButton.tsx +++ b/src/app/club/eventdetails/[id]/ParticipateButton.tsx @@ -57,7 +57,7 @@ const ParticipateButton = ({ ); } - return
You are not eligible for this exam
; + return
; }; export default ParticipateButton; diff --git a/src/app/club/eventdetails/[id]/page.tsx b/src/app/club/eventdetails/[id]/page.tsx index bf01985..85f79ac 100644 --- a/src/app/club/eventdetails/[id]/page.tsx +++ b/src/app/club/eventdetails/[id]/page.tsx @@ -10,6 +10,7 @@ import { firestore } from "firebase-admin"; import { getFirestore, Timestamp } from "firebase-admin/firestore"; import { timeValue } from "../../Components/Time"; import ParticipateButton from "./ParticipateButton"; +import Eligibility from "./Eligibility"; type ParamType = { id: string }; @@ -69,13 +70,19 @@ const page = async ({ params }: { params: ParamType }) => { {`${DateData.hour}:${DateData.minute}`}

- {!timeUp && !notTime && ( + {!timeUp && !notTime ? ( + ) : ( + )}
From 9de039fd365cd735a32adbd6ad6c5850640e1a8b Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Sun, 6 Oct 2024 20:40:31 +0600 Subject: [PATCH 06/31] Roll Enter Pop Up Added --- src/app/club/Components/Home/DamianPopUp.tsx | 130 +++++++++++++++++++ src/app/club/page.tsx | 2 + 2 files changed, 132 insertions(+) create mode 100644 src/app/club/Components/Home/DamianPopUp.tsx diff --git a/src/app/club/Components/Home/DamianPopUp.tsx b/src/app/club/Components/Home/DamianPopUp.tsx new file mode 100644 index 0000000..b208821 --- /dev/null +++ b/src/app/club/Components/Home/DamianPopUp.tsx @@ -0,0 +1,130 @@ +"use client"; + +import { + Button, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, + useDisclosure, +} from "@nextui-org/react"; +import { useUserDataContext } from "../Layout/UserDataProvider"; +import { useEffect, useState } from "react"; +import { MdCircleNotifications } from "react-icons/md"; +import { useAuthContext } from "../Layout/AuthContextProvider"; +import { toast } from "react-toastify"; +import { doc, updateDoc } from "firebase/firestore"; +import { db } from "@/config/firebase"; + +const DamianPopUp = () => { + const userAuth = useAuthContext().userAuth; + const userLoading = useAuthContext().loading; + const { userData, userDataLoading, dataError, updateUserData } = + useUserDataContext(); + + const [loading, setLoading] = useState(false); + + const { isOpen, onOpen, onOpenChange } = useDisclosure(); + + const [roll, setRoll] = useState(""); + + useEffect(() => { + if (!userDataLoading && userData.ndc_roll == "") { + onOpen(); + } + }, [userData, userDataLoading]); + + const onSubmit = async (e: any) => { + if (roll == "") { + toast.error("Roll can't be empty"); + return; + } + + setLoading(true); + + if (userAuth && !userLoading) { + try { + await updateDoc(doc(db, "participants", userAuth.uid), { + ndc_roll: roll, + }); + + toast.success("NDC Roll Updated!"); + updateUserData(); + setLoading(false); + } catch (err) { + console.error(err); + toast.error("Aww Snap!"); + setLoading(false); + } + } + }; + + return ( +
+ + + {(onClose) => ( + <> + +

+ + {" "} + + Notification: + + Hi there. Are you a Notre Damian? The NDITC Intra-College Fest + is set for October 14-15!. Then what are you waiting for? + Enter your NDC Roll, get ready and keep your eyes on the + Events page. (Ignore this notification if you are not a + Damian) +

+ + + setRoll(e.currentTarget.value)} + value={roll} + name={"roll"} + placeholder={"#####"} + /> +
+ + + + + + )} +
+
+
+ ); +}; + +export default DamianPopUp; diff --git a/src/app/club/page.tsx b/src/app/club/page.tsx index 7dda67c..1947f5f 100644 --- a/src/app/club/page.tsx +++ b/src/app/club/page.tsx @@ -7,6 +7,7 @@ import Rules from "@/app/club/Components/Home/Rules"; import Contact from "@/app/club/Components/Contact"; import FAQ from "@/app/club/Components/Home/FAQ"; import Ranking from "./Components/Dashboard/Ranking"; +import DamianPopUp from "./Components/Home/DamianPopUp"; const page = () => { return ( @@ -17,6 +18,7 @@ const page = () => { + ); From 09acf40e25b0d82069846cd019403eb886129d16 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Tue, 8 Oct 2024 00:37:46 +0600 Subject: [PATCH 07/31] User Counting System --- .../club/admin/(adminpanel)/users/page.tsx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/app/club/admin/(adminpanel)/users/page.tsx b/src/app/club/admin/(adminpanel)/users/page.tsx index 138d1c8..89778b5 100644 --- a/src/app/club/admin/(adminpanel)/users/page.tsx +++ b/src/app/club/admin/(adminpanel)/users/page.tsx @@ -12,6 +12,7 @@ import { MdEventNote, MdOutlinePersonSearch } from "react-icons/md"; import { collection, doc, + getCountFromServer, getDoc, getDocs, limit, @@ -59,6 +60,8 @@ const Page = () => { const [usersData, setUsersData] = useState([]); const [lastUserDoc, setLastUserDoc] = useState(); + const [totalUsers, setTotalUsers] = useState(0); + const docLimit = 10; useEffect(() => { @@ -71,6 +74,9 @@ const Page = () => { .then((resp) => { setAdminAuth(resp.auth || false); + const countSnap = getCountFromServer(onFilterQuery(false, true)); + countSnap.then((r) => r.data()).then((r) => setTotalUsers(r.count)); + getDocs(onFilterQuery(false)).then((data) => { console.log(data.docs[data.docs.length - 1]); setLastUserDoc(data.docs[data.docs.length - 1]); @@ -116,7 +122,7 @@ const Page = () => { const [isYearSelected, setIsYearSelected] = useState(false); const [selectedClass, setSelectedClass] = useState(2001); - const onFilterQuery = (loadMore: boolean) => { + const onFilterQuery = (loadMore: boolean, limitLess = false) => { let conditions = []; if (isTimeSort) { @@ -132,12 +138,9 @@ const Page = () => { if (isVerified) conditions.push(where("verified", "==", true)); if (isSelected) conditions.push(where("selected", "==", true)); if (loadMore) conditions.push(startAfter(lastUserDoc)); + if (!limitLess) conditions.push(limit(docLimit)); - const usersQuery = query( - collection(db, "participants"), - limit(docLimit), - ...conditions, - ); + const usersQuery = query(collection(db, "participants"), ...conditions); return usersQuery; }; @@ -181,6 +184,9 @@ const Page = () => { .catch((e) => toast.error(e)); } } else { + const countSnap = getCountFromServer(onFilterQuery(false, true)); + countSnap.then((r) => r.data()).then((r) => setTotalUsers(r.count)); + getDocs(onFilterQuery(false)).then((data) => { setLastUserDoc(data.docs[data.docs.length - 1]); const tempArr: any[] = []; @@ -328,7 +334,8 @@ const Page = () => {

- USERS INFO + USERS INFO : + {totalUsers}

@@ -268,7 +270,7 @@ const AddQuestions = ({ setCorrectOption(i); }} className={`h-10 w-10 rounded-full border border-primary_dark text-xl transition-colors ${ - correctOption == i ? "bg-primary" : "bg-white" + correctOption == i ? "bg-primary text-white" : "bg-white" }`} > {e} @@ -388,7 +390,7 @@ const Question = ({ - { setQuestionVal(e.currentTarget.value); @@ -397,6 +399,7 @@ const Question = ({ name="question" placeholder="Question ..." disabled={!editing} + rows={7} />
@@ -426,7 +429,7 @@ const Question = ({ onClick={(e) => setCorrectOptionVal(i)} disabled={!editing} className={`h-10 w-10 rounded-full border border-primary_dark text-xl transition-colors ${ - correctOptionVal == i ? "bg-primary" : "bg-white" + correctOptionVal == i ? "bg-primary text-white" : "bg-white" }`} > {e} diff --git a/src/app/club/Components/Participate/Question.tsx b/src/app/club/Components/Participate/Question.tsx index 4719c79..9811d60 100644 --- a/src/app/club/Components/Participate/Question.tsx +++ b/src/app/club/Components/Participate/Question.tsx @@ -1,4 +1,12 @@ -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; +import Markdown from "react-markdown"; +import SyntaxHighlighter from "react-syntax-highlighter"; +import { oneLight } from "react-syntax-highlighter/dist/esm/styles/prism"; +import rehypeKatex from "rehype-katex"; +import remarkGfm from "remark-gfm"; +import remarkMath from "remark-math"; +import "katex/dist/katex.min.css"; +import { docco } from "react-syntax-highlighter/dist/esm/styles/hljs"; interface questionInterface { mcq: boolean; @@ -38,14 +46,59 @@ const Question = ({ setAnswerData(selectedVal, answer, index); }, [selectedVal, answer]); + const modifiedText = useMemo(() => { + const lines = (question || "").split("\n"); + + return lines + .map((line, index) => { + // Check if the line is part of a list + const isListItem = /^\s*[*\-+]\s+|^\s*\d+\.\s+/.test(line); + const isNextLineListItem = + index < lines.length - 1 && + /^\s*[*\-+]\s+|^\s*\d+\.\s+/.test(lines[index + 1]); + + if (isListItem || isNextLineListItem) return line; + + if (line.trim() === "\\") return line.replace("\\", " \n"); + + return line + " \n"; + }) + .join("\n") + .replaceAll("~~", "\n --- \n"); + }, []); + return (
-
+

{index + 1}

-

{question}

+

+ {" "} + + {String(children).replace(/\n$/, "")} + + ) : ( + + {children} + + ); + }, + }} + > + {modifiedText} + +

{mcq ? ( diff --git a/src/app/club/participate/[id]/page.tsx b/src/app/club/participate/[id]/page.tsx index ddcb19c..d78d255 100644 --- a/src/app/club/participate/[id]/page.tsx +++ b/src/app/club/participate/[id]/page.tsx @@ -90,7 +90,7 @@ const Page = ({ params }: { params: { id: string } }) => { return (
- {isError != "" && } + {isError != "" && } {isLoading && } {!isLoading && isError == "" && docSnapshot.questions && (
diff --git a/src/app/globals.css b/src/app/globals.css index 95726e9..a1f9d69 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -329,3 +329,91 @@ p { .container-login { @apply mx-auto max-w-[100vw] sm:max-w-[90vw] xl:max-w-[85vw] 2xl:max-w-[75vw]; } + +.ques img { + max-width: 450px; + width: 100%; +} +.ques ul li { + list-style: lead; + list-style-position: inside; + margin-left: 0.35rem; +} +.ques ul { + margin-top: 0.25rem; + margin-bottom: 0.75rem; +} +.ques p { + padding-bottom: 0.5rem; +} + +.ques p::first-line { + padding-left: 1rem; +} +.ques a { + color: #3b82f6; +} +.ques h1 { + font-size: 2.25rem; + padding-top: 2.5rem; + padding-bottom: 1rem; + font-weight: 400; +} +/* .ques h1::first-letter { + color: #2f4770; +} */ +.ques h2 { + font-size: 1.875rem; + padding-top: 2.5rem; + padding-bottom: 0.5rem; + font-weight: 400; +} +.ques h3, +.ques h4, +.ques h5, +.ques h6 { + font-size: 1.5rem; + padding-top: 0.25rem; + padding-bottom: 0.25rem; + font-family: Nunito; + font-weight: 700; +} + +.ques h4, +.ques h5, +.ques h6 { + font-size: 1.25rem !important; +} +.ques table { + border: 1px solid #e4e4e7; + border-radius: 2px; +} +.ques thead tr { + background-color: #e4e4e7; +} +.ques tbody tr:nth-child(2n-1) { + background-color: transparent; +} +.ques tbody tr:nth-child(2n) { + background-color: #e4e4e7d0; +} +.ques td, +.ques th { + padding: 0.5rem 2rem; + border: 1px solid #d1d5db; +} + +.ques ul { + list-style-type: circle; + list-style-position: inside; +} + +.ques ol { + list-style-type: decimal; + list-style-position: inside; +} + +.ques li::marker { + color: #3b82f6; + font-weight: bold; +} From fa5ad89ed72d12ee71688fcebfbb0f02dff93344 Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Fri, 11 Oct 2024 13:13:48 +0600 Subject: [PATCH 09/31] up --- src/app/club/Components/Admin/AdminEventCard.tsx | 7 +++++-- src/app/club/Components/Events/EventCard.tsx | 7 ++++--- .../club/Components/Layout/UserDataProvider.tsx | 5 +++++ src/app/club/events/[uid]/[memberid]/page.tsx | 7 ++++++- src/util/leadingzero.ts | 16 ++++++++++++++++ 5 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/util/leadingzero.ts diff --git a/src/app/club/Components/Admin/AdminEventCard.tsx b/src/app/club/Components/Admin/AdminEventCard.tsx index c83383e..8668ec7 100644 --- a/src/app/club/Components/Admin/AdminEventCard.tsx +++ b/src/app/club/Components/Admin/AdminEventCard.tsx @@ -3,6 +3,7 @@ import { IoCalendarOutline, IoSettingsOutline } from "react-icons/io5"; import { BsStopwatch } from "react-icons/bs"; import { timeValue } from "../Time"; import { Timestamp } from "firebase/firestore"; +import _L0 from "@/util/leadingzero"; const AdminEventCard = ({ title, @@ -44,14 +45,16 @@ const AdminEventCard = ({ {title}
- {timeValue(endDate).minute - dateData.minute} Minutes + {timeValue(endDate).hour - dateData.hour > 0 && + `${Math.abs(timeValue(endDate).hour - dateData.hour)}H : `} + {Math.abs(timeValue(endDate).minute - dateData.minute)}M
{category}
{`${dateData.date} ${dateData.monthText} ${dateData.year}`} |{" "} - {`${dateData.hour}:${dateData.minute}`} + {`${_L0(dateData.hour - (dateData.hour > 12 ? 12 : 0))}:${_L0(dateData.minute)} ${dateData.hour >= 12 ? "PM" : "AM"}`}

diff --git a/src/app/club/Components/Events/EventCard.tsx b/src/app/club/Components/Events/EventCard.tsx index 4881a44..59099ec 100644 --- a/src/app/club/Components/Events/EventCard.tsx +++ b/src/app/club/Components/Events/EventCard.tsx @@ -8,6 +8,7 @@ import { Timestamp } from "firebase/firestore"; import PartcipateButton from "./PartcipateButton"; import { MdOutlineTimer } from "react-icons/md"; import { createCipheriv } from "crypto"; +import _L0 from "@/util/leadingzero"; const EventCard = ({ title, @@ -69,13 +70,13 @@ const EventCard = ({ {`${dateData.date} ${dateData.monthText} ${dateData.year}`}{" "} |{" "} - {`${dateData.hour}:${dateData.minute}`} + {`${_L0(dateData.hour - (dateData.hour > 12 ? 12 : 0))}:${_L0(dateData.minute)} ${dateData.hour >= 12 ? "PM" : "AM"}`}

{timeValue(endDate).hour - dateData.hour > 0 && - `${timeValue(endDate).hour - dateData.hour}H : `} - {timeValue(endDate).minute - dateData.minute}M + `${Math.abs(timeValue(endDate).hour - dateData.hour)}H : `} + {Math.abs(timeValue(endDate).minute - dateData.minute)}M

{desc} diff --git a/src/app/club/Components/Layout/UserDataProvider.tsx b/src/app/club/Components/Layout/UserDataProvider.tsx index 3b47865..b014999 100644 --- a/src/app/club/Components/Layout/UserDataProvider.tsx +++ b/src/app/club/Components/Layout/UserDataProvider.tsx @@ -42,6 +42,9 @@ export const UserDataContextProvider = ({ useEffect(() => { if (Route.includes("club")) { setCanLoadData(true); + } else { + setUserDataLoading(false); + setDataError(true); } }, [Route]); @@ -74,8 +77,10 @@ export const UserDataContextProvider = ({ }); } else if (userAuth && !userAuth?.emailVerified) { setUserData(null); + setUserDataLoading(false); } else if (!loading) { setUserData(null); + setUserDataLoading(false); } } }, [userAuth, loading, canLoadData, forceReload]); diff --git a/src/app/club/events/[uid]/[memberid]/page.tsx b/src/app/club/events/[uid]/[memberid]/page.tsx index 8d6714c..bd4d00d 100644 --- a/src/app/club/events/[uid]/[memberid]/page.tsx +++ b/src/app/club/events/[uid]/[memberid]/page.tsx @@ -6,6 +6,7 @@ import { useAuthContext } from "@/app/club/Components/Layout/AuthContextProvider import { useUserDataContext } from "@/app/club/Components/Layout/UserDataProvider"; import { useState, useEffect } from "react"; import Loading from "@/app/club/Components/Loading"; +import { useRouter } from "next/navigation"; const getEvents = async (ndc_id: string, uid: string, ndc_roll: string) => { const res = await fetch("/api/getevents", { @@ -37,7 +38,7 @@ const Page = ({ params }: { params: { uid: string; memberid: string } }) => { const [ongoingList, setOngoingList] = useState(null); const [eventsList, setEventsList] = useState(null); - + const Router = useRouter(); useEffect(() => { if (!loading && !userDataLoading) { getEvents(memberidval, uidVal || "", userData?.ndc_roll || "") @@ -60,6 +61,10 @@ const Page = ({ params }: { params: { uid: string; memberid: string } }) => { setIsLoading(false); setIsError("Error Occurred"); } + + if (!loading && !userDataLoading && (!userData || !userAuth)) { + Router.push("/club/events/"); + } }, [userAuth, userData, loading, userDataLoading, error, dataError]); return ( diff --git a/src/util/leadingzero.ts b/src/util/leadingzero.ts new file mode 100644 index 0000000..907a40b --- /dev/null +++ b/src/util/leadingzero.ts @@ -0,0 +1,16 @@ +const _L0 = (num: number, digits: number = 2): string => { + let str = String(num); + const zeros = digits - str.length; + + if (zeros <= 0) { + return str; + } + + for (let i = 0; i < zeros; i++) { + str = '0' + str; + } + + return str; +}; + +export default _L0; From 1fba7ff18afda4121cb85a22b36573f18fa2e4ad Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Fri, 11 Oct 2024 16:53:39 +0600 Subject: [PATCH 10/31] up --- package-lock.json | 262 ++---------------- package.json | 2 +- src/app/api/memberdata/route.ts | 2 - src/app/club/(user-handle)/login/page.tsx | 1 - .../club/Components/Admin/AdminEventCard.tsx | 7 +- src/app/club/Components/Admin/EditConfig.tsx | 2 +- src/app/club/Components/Events/EventCard.tsx | 18 +- src/app/club/Components/Home/DamianPopUp.tsx | 2 +- .../club/Components/Participate/Question.tsx | 28 +- .../club/admin/(adminpanel)/users/page.tsx | 1 - .../club/admin/eventEdit/[eventID]/page.tsx | 1 - src/app/club/admin/login/page.tsx | 1 - src/app/club/admin/rankers/[id]/page.tsx | 2 - .../club/eventdetails/[id]/Eligibility.tsx | 8 + src/app/club/eventdetails/[id]/page.tsx | 1 - src/app/club/events/page.tsx | 2 - src/app/globals.css | 25 +- src/util/Time.ts | 16 ++ 18 files changed, 91 insertions(+), 290 deletions(-) create mode 100644 src/util/Time.ts diff --git a/package-lock.json b/package-lock.json index cf14f8b..a30a6d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,9 +28,9 @@ "react-firebase-hooks": "^5.1.1", "react-icons": "^5.0.1", "react-markdown": "^9.0.1", - "react-syntax-highlighter": "^15.5.0", "react-toastify": "^10.0.5", "react-zoom-pan-pinch": "^3.4.3", + "rehype-highlight": "^7.0.0", "rehype-katex": "^7.0.1", "remark-gfm": "^4.0.0", "remark-math": "^6.0.0", @@ -8976,18 +8976,6 @@ "reusify": "^1.0.4" } }, - "node_modules/fault": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/fault/-/fault-1.0.4.tgz", - "integrity": "sha512-CJ0HCB5tL5fYTEA7ToAq5+kTwd++Borf1/bifxd9iT70QcXr4MRrO3Llf8Ifs70q+SJcGHFtnIE/Nw6giCtECA==", - "dependencies": { - "format": "^0.2.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/faye-websocket": { "version": "0.11.4", "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.11.4.tgz", @@ -9241,14 +9229,6 @@ "node": ">= 0.12" } }, - "node_modules/format": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/format/-/format-0.2.2.tgz", - "integrity": "sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==", - "engines": { - "node": ">=0.4.x" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -9915,15 +9895,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/hast-util-parse-selector": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/hast-util-parse-selector/-/hast-util-parse-selector-2.2.5.tgz", - "integrity": "sha512-7j6mrk/qqkSehsM92wQjdIgWM2/BW61u/53G6xmC8i1OmEdKLHbk419QKQUjz6LglWsfqoiHmyMRkP1BGjecNQ==", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, "node_modules/hast-util-to-jsx-runtime": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/hast-util-to-jsx-runtime/-/hast-util-to-jsx-runtime-2.3.0.tgz", @@ -9977,71 +9948,12 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/hastscript": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/hastscript/-/hastscript-6.0.0.tgz", - "integrity": "sha512-nDM6bvd7lIqDUiYEiu5Sl/+6ReP0BMk/2f4U/Rooccxkj0P5nm+acM5PrGJ/t5I8qPGiqZSE6hVAwZEdZIvP4w==", - "dependencies": { - "@types/hast": "^2.0.0", - "comma-separated-tokens": "^1.0.0", - "hast-util-parse-selector": "^2.0.0", - "property-information": "^5.0.0", - "space-separated-tokens": "^1.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - } - }, - "node_modules/hastscript/node_modules/@types/hast": { - "version": "2.3.10", - "resolved": "https://registry.npmjs.org/@types/hast/-/hast-2.3.10.tgz", - "integrity": "sha512-McWspRw8xx8J9HurkVBfYj0xKoE25tOFlHGdx4MJ5xORQrMGZNqJhVQWaIbm6Oyla5kYOXtDiopzKRJzEOkwJw==", - "dependencies": { - "@types/unist": "^2" - } - }, - "node_modules/hastscript/node_modules/@types/unist": { - "version": "2.0.11", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.11.tgz", - "integrity": "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==" - }, - "node_modules/hastscript/node_modules/comma-separated-tokens": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-1.0.8.tgz", - "integrity": "sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/hastscript/node_modules/property-information": { - "version": "5.6.0", - "resolved": "https://registry.npmjs.org/property-information/-/property-information-5.6.0.tgz", - "integrity": "sha512-YUHSPk+A30YPv+0Qf8i9Mbfe/C0hdPXk1s1jPVToV8pk8BQtpw10ct89Eo7OWkutrwqvT0eicAxlOg3dOAu8JA==", - "dependencies": { - "xtend": "^4.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/hastscript/node_modules/space-separated-tokens": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-1.1.5.tgz", - "integrity": "sha512-q/JSVd1Lptzhf5bkYm4ob4iWPjx0KiRe3sRFBNrVqbJkFaBm5vbbowy1mymoPNLRa52+oadOhJ+K49wsSeSjTA==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, "node_modules/highlight.js": { - "version": "10.7.3", - "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz", - "integrity": "sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==", + "version": "11.9.0", + "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.9.0.tgz", + "integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==", "engines": { - "node": "*" + "node": ">=12.0.0" } }, "node_modules/html-entities": { @@ -11266,12 +11178,13 @@ } }, "node_modules/lowlight": { - "version": "1.20.0", - "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-1.20.0.tgz", - "integrity": "sha512-8Ktj+prEb1RoCPkEOrPMYUN/nCggB7qAWe3a7OpMjWQkh3l2RD5wKRQ+o8Q8YuI9RG/xs95waaI/E6ym/7NsTw==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-3.1.0.tgz", + "integrity": "sha512-CEbNVoSikAxwDMDPjXlqlFYiZLkDJHwyGu/MfOsJnF3d7f3tds5J3z8s/l9TMXhzfsJCCJEAsD78842mwmg0PQ==", "dependencies": { - "fault": "^1.0.0", - "highlight.js": "~10.7.0" + "@types/hast": "^3.0.0", + "devlop": "^1.0.0", + "highlight.js": "~11.9.0" }, "funding": { "type": "github", @@ -13273,14 +13186,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/prismjs": { - "version": "1.29.0", - "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.29.0.tgz", - "integrity": "sha512-Kx/1w86q/epKcmte75LNrEoT+lX8pBpavuAbvJWRXar7Hz8jrtF+e3vY751p0R8H9HdArwaCTNDDzHg/ScJK1Q==", - "engines": { - "node": ">=6" - } - }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", @@ -13573,21 +13478,6 @@ } } }, - "node_modules/react-syntax-highlighter": { - "version": "15.5.0", - "resolved": "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-15.5.0.tgz", - "integrity": "sha512-+zq2myprEnQmH5yw6Gqc8lD55QHnpKaU8TOcFeC/Lg/MQSs8UknEA0JC4nTZGFAXC2J2Hyj/ijJ7NlabyPi2gg==", - "dependencies": { - "@babel/runtime": "^7.3.1", - "highlight.js": "^10.4.1", - "lowlight": "^1.17.0", - "prismjs": "^1.27.0", - "refractor": "^3.6.0" - }, - "peerDependencies": { - "react": ">= 0.14.0" - } - }, "node_modules/react-textarea-autosize": { "version": "8.5.3", "resolved": "https://registry.npmjs.org/react-textarea-autosize/-/react-textarea-autosize-8.5.3.tgz", @@ -13699,112 +13589,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/refractor": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/refractor/-/refractor-3.6.0.tgz", - "integrity": "sha512-MY9W41IOWxxk31o+YvFCNyNzdkc9M20NoZK5vq6jkv4I/uh2zkWcfudj0Q1fovjUQJrNewS9NMzeTtqPf+n5EA==", - "dependencies": { - "hastscript": "^6.0.0", - "parse-entities": "^2.0.0", - "prismjs": "~1.27.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/character-entities": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/character-entities/-/character-entities-1.2.4.tgz", - "integrity": "sha512-iBMyeEHxfVnIakwOuDXpVkc54HijNgCyQB2w0VfGQThle6NXn50zU6V/u+LDhxHcDUPojn6Kpga3PTAD8W1bQw==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/character-entities-legacy": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-1.1.4.tgz", - "integrity": "sha512-3Xnr+7ZFS1uxeiUDvV02wQ+QDbc55o97tIV5zHScSPJpcLm/r0DFPcoY3tYRp+VZukxuMeKgXYmsXQHO05zQeA==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/character-reference-invalid": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz", - "integrity": "sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/is-alphabetical": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-alphabetical/-/is-alphabetical-1.0.4.tgz", - "integrity": "sha512-DwzsA04LQ10FHTZuL0/grVDk4rFoVH1pjAToYwBrHSxcrBIGQuXrQMtD5U1b0U2XVgKZCTLLP8u2Qxqhy3l2Vg==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/is-alphanumerical": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-alphanumerical/-/is-alphanumerical-1.0.4.tgz", - "integrity": "sha512-UzoZUr+XfVz3t3v4KyGEniVL9BDRoQtY7tOyrRybkVNjDFWyo1yhXNGrrBTQxp3ib9BLAWs7k2YKBQsFRkZG9A==", - "dependencies": { - "is-alphabetical": "^1.0.0", - "is-decimal": "^1.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/is-decimal": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-decimal/-/is-decimal-1.0.4.tgz", - "integrity": "sha512-RGdriMmQQvZ2aqaQq3awNA6dCGtKpiDFcOzrTWrDAT2MiWrKQVPmxLGHl7Y2nNu6led0kEyoX0enY0qXYsv9zw==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/is-hexadecimal": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz", - "integrity": "sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/parse-entities": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/parse-entities/-/parse-entities-2.0.0.tgz", - "integrity": "sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==", - "dependencies": { - "character-entities": "^1.0.0", - "character-entities-legacy": "^1.0.0", - "character-reference-invalid": "^1.0.0", - "is-alphanumerical": "^1.0.0", - "is-decimal": "^1.0.0", - "is-hexadecimal": "^1.0.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" - } - }, - "node_modules/refractor/node_modules/prismjs": { - "version": "1.27.0", - "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.27.0.tgz", - "integrity": "sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==", - "engines": { - "node": ">=6" - } - }, "node_modules/regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", @@ -13886,6 +13670,22 @@ "jsesc": "bin/jsesc" } }, + "node_modules/rehype-highlight": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/rehype-highlight/-/rehype-highlight-7.0.0.tgz", + "integrity": "sha512-QtobgRgYoQaK6p1eSr2SD1i61f7bjF2kZHAQHxeCHAuJf7ZUDMvQ7owDq9YTkmar5m5TSUol+2D3bp3KfJf/oA==", + "dependencies": { + "@types/hast": "^3.0.0", + "hast-util-to-text": "^4.0.0", + "lowlight": "^3.0.0", + "unist-util-visit": "^5.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/rehype-katex": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/rehype-katex/-/rehype-katex-7.0.1.tgz", @@ -16473,14 +16273,6 @@ "node": ">=0.8" } }, - "node_modules/xtend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", - "engines": { - "node": ">=0.4" - } - }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 1c09bad..6c01786 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,9 @@ "react-firebase-hooks": "^5.1.1", "react-icons": "^5.0.1", "react-markdown": "^9.0.1", - "react-syntax-highlighter": "^15.5.0", "react-toastify": "^10.0.5", "react-zoom-pan-pinch": "^3.4.3", + "rehype-highlight": "^7.0.0", "rehype-katex": "^7.0.1", "remark-gfm": "^4.0.0", "remark-math": "^6.0.0", diff --git a/src/app/api/memberdata/route.ts b/src/app/api/memberdata/route.ts index 6109ca0..ba5e42a 100644 --- a/src/app/api/memberdata/route.ts +++ b/src/app/api/memberdata/route.ts @@ -16,8 +16,6 @@ export async function POST(req: NextRequest) { const member = await memberDOC.json(); - console.log(member); - if (!memberDOC.ok) { return NextResponse.json( { error: "No such Club Member exists" }, diff --git a/src/app/club/(user-handle)/login/page.tsx b/src/app/club/(user-handle)/login/page.tsx index 0811953..9442ad7 100644 --- a/src/app/club/(user-handle)/login/page.tsx +++ b/src/app/club/(user-handle)/login/page.tsx @@ -53,7 +53,6 @@ const Page = () => { }); }; useEffect(() => { - console.log(auth); setAuthLoading(true); if (userAuth) { Router.push("/club/profile"); diff --git a/src/app/club/Components/Admin/AdminEventCard.tsx b/src/app/club/Components/Admin/AdminEventCard.tsx index 8668ec7..1319f35 100644 --- a/src/app/club/Components/Admin/AdminEventCard.tsx +++ b/src/app/club/Components/Admin/AdminEventCard.tsx @@ -4,6 +4,7 @@ import { BsStopwatch } from "react-icons/bs"; import { timeValue } from "../Time"; import { Timestamp } from "firebase/firestore"; import _L0 from "@/util/leadingzero"; +import { RemainingTimeHM } from "@/util/Time"; const AdminEventCard = ({ title, @@ -25,6 +26,7 @@ const AdminEventCard = ({ category: string; }) => { const dateData = timeValue(date); + const remainingTime = RemainingTimeHM(date, endDate); return (

@@ -45,9 +47,8 @@ const AdminEventCard = ({ {title}
- {timeValue(endDate).hour - dateData.hour > 0 && - `${Math.abs(timeValue(endDate).hour - dateData.hour)}H : `} - {Math.abs(timeValue(endDate).minute - dateData.minute)}M + {remainingTime.hours > 0 && `${remainingTime.hours}h `} + {remainingTime.mins}min
{category}
diff --git a/src/app/club/Components/Admin/EditConfig.tsx b/src/app/club/Components/Admin/EditConfig.tsx index 214697c..3f604bd 100644 --- a/src/app/club/Components/Admin/EditConfig.tsx +++ b/src/app/club/Components/Admin/EditConfig.tsx @@ -36,7 +36,7 @@ const EditConfig = () => { } setLoading(false); }; - console.log(configs); + return (
endDate; + const dateData = timeValue(date); + const remainingTime = RemainingTimeHM(date, endDate); + return (
{ongoing && ( -
+
Ongoing
)} @@ -51,6 +56,12 @@ const EventCard = ({
)} + {ended && ( +
+ Ended +
+ )} +
- {timeValue(endDate).hour - dateData.hour > 0 && - `${Math.abs(timeValue(endDate).hour - dateData.hour)}H : `} - {Math.abs(timeValue(endDate).minute - dateData.minute)}M + {remainingTime.hours > 0 && `${remainingTime.hours}h `} + {remainingTime.mins}min

{desc} diff --git a/src/app/club/Components/Home/DamianPopUp.tsx b/src/app/club/Components/Home/DamianPopUp.tsx index b208821..17fc04a 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/Question.tsx b/src/app/club/Components/Participate/Question.tsx index 9811d60..3714a20 100644 --- a/src/app/club/Components/Participate/Question.tsx +++ b/src/app/club/Components/Participate/Question.tsx @@ -1,12 +1,12 @@ import { useEffect, useMemo, useState } from "react"; import Markdown from "react-markdown"; import SyntaxHighlighter from "react-syntax-highlighter"; -import { oneLight } from "react-syntax-highlighter/dist/esm/styles/prism"; import rehypeKatex from "rehype-katex"; import remarkGfm from "remark-gfm"; import remarkMath from "remark-math"; import "katex/dist/katex.min.css"; -import { docco } from "react-syntax-highlighter/dist/esm/styles/hljs"; +import rehypeHighlight from "rehype-highlight"; +import "highlight.js/styles/atom-one-light.css"; interface questionInterface { mcq: boolean; @@ -59,12 +59,9 @@ const Question = ({ if (isListItem || isNextLineListItem) return line; - if (line.trim() === "\\") return line.replace("\\", " \n"); - - return line + " \n"; + return line + "\n"; }) - .join("\n") - .replaceAll("~~", "\n --- \n"); + .join("\n"); }, []); return ( @@ -79,22 +76,7 @@ const Question = ({ - {String(children).replace(/\n$/, "")} - - ) : ( - - {children} - - ); - }, - }} + rehypePlugins={[rehypeKatex, rehypeHighlight]} > {modifiedText} diff --git a/src/app/club/admin/(adminpanel)/users/page.tsx b/src/app/club/admin/(adminpanel)/users/page.tsx index 89778b5..896dcff 100644 --- a/src/app/club/admin/(adminpanel)/users/page.tsx +++ b/src/app/club/admin/(adminpanel)/users/page.tsx @@ -78,7 +78,6 @@ const Page = () => { countSnap.then((r) => r.data()).then((r) => setTotalUsers(r.count)); getDocs(onFilterQuery(false)).then((data) => { - console.log(data.docs[data.docs.length - 1]); setLastUserDoc(data.docs[data.docs.length - 1]); const tempArr: any[] = []; data.docs.forEach((e, i) => { diff --git a/src/app/club/admin/eventEdit/[eventID]/page.tsx b/src/app/club/admin/eventEdit/[eventID]/page.tsx index 2b1e5d8..1752a85 100644 --- a/src/app/club/admin/eventEdit/[eventID]/page.tsx +++ b/src/app/club/admin/eventEdit/[eventID]/page.tsx @@ -105,7 +105,6 @@ const Page = ({ params }: { params: { eventID: string } }) => { }) .then((r) => r.json()) .then((resp) => { - console.log(resp); setAdminAuth(resp.auth || false); setAuthLoading(false); }) diff --git a/src/app/club/admin/login/page.tsx b/src/app/club/admin/login/page.tsx index 83b8453..2a03783 100644 --- a/src/app/club/admin/login/page.tsx +++ b/src/app/club/admin/login/page.tsx @@ -56,7 +56,6 @@ const Page = () => { }) .then((r) => r.json()) .then((resp) => { - console.log(resp); if (resp.auth) { Router.push("/club/admin"); } else { diff --git a/src/app/club/admin/rankers/[id]/page.tsx b/src/app/club/admin/rankers/[id]/page.tsx index c4c0f43..80d457e 100644 --- a/src/app/club/admin/rankers/[id]/page.tsx +++ b/src/app/club/admin/rankers/[id]/page.tsx @@ -671,8 +671,6 @@ const EditEventData = ({ const [error, setError] = useState(""); - console.log(data); - const updateData = async () => { await updateDoc( doc(db, "answers", id, "eventparticipant", uid), diff --git a/src/app/club/eventdetails/[id]/Eligibility.tsx b/src/app/club/eventdetails/[id]/Eligibility.tsx index f3e1791..e23e34f 100644 --- a/src/app/club/eventdetails/[id]/Eligibility.tsx +++ b/src/app/club/eventdetails/[id]/Eligibility.tsx @@ -16,6 +16,14 @@ const Eligibility = ({ if (intra_club && userData && userData.ndc_id != "") return

; if (publicQuiz && userData) return
; + if (!userData) { + return ( +
+ Please login to participate +
+ ); + } + return (
You are not eligible for this exam diff --git a/src/app/club/eventdetails/[id]/page.tsx b/src/app/club/eventdetails/[id]/page.tsx index 85f79ac..036b97a 100644 --- a/src/app/club/eventdetails/[id]/page.tsx +++ b/src/app/club/eventdetails/[id]/page.tsx @@ -57,7 +57,6 @@ const page = async ({ params }: { params: ParamType }) => {

- {"Category>"} {`${data?.category}>`}

diff --git a/src/app/club/events/page.tsx b/src/app/club/events/page.tsx index a9864e4..694f06f 100644 --- a/src/app/club/events/page.tsx +++ b/src/app/club/events/page.tsx @@ -36,8 +36,6 @@ const page = async () => { ...e.data(), })); - console.log(eventList); - return (
diff --git a/src/app/globals.css b/src/app/globals.css index a1f9d69..3a05023 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -354,35 +354,38 @@ p { color: #3b82f6; } .ques h1 { - font-size: 2.25rem; - padding-top: 2.5rem; - padding-bottom: 1rem; - font-weight: 400; + font-size: 1.75rem; + padding-top: 0.5rem; + padding-bottom: 0.25rem; + font-weight: 700; + font-family: "Inter"; } /* .ques h1::first-letter { color: #2f4770; } */ .ques h2 { - font-size: 1.875rem; - padding-top: 2.5rem; - padding-bottom: 0.5rem; - font-weight: 400; + font-size: 1.5rem; + padding-top: 0.5rem; + padding-bottom: 0.25rem; + font-weight: 700; + font-family: "Inter"; } .ques h3, .ques h4, .ques h5, .ques h6 { - font-size: 1.5rem; + font-size: 1.25rem; padding-top: 0.25rem; padding-bottom: 0.25rem; - font-family: Nunito; + font-family: "Inter"; + font-weight: 700; } .ques h4, .ques h5, .ques h6 { - font-size: 1.25rem !important; + font-size: 1.15rem !important; } .ques table { border: 1px solid #e4e4e7; diff --git a/src/util/Time.ts b/src/util/Time.ts new file mode 100644 index 0000000..06abe01 --- /dev/null +++ b/src/util/Time.ts @@ -0,0 +1,16 @@ +import { timeValue } from "@/app/club/Components/Time"; + +export const RemainingTimeHM = (before: any, after: any) => { + let hours = timeValue(after).hour - timeValue(before).hour; + let mins = timeValue(after).minute - timeValue(before).minute; + + if (mins < 0) { + mins = 60 + mins; + hours--; + } + + return { + hours, + mins, + }; +}; From f83564808051cc0939c529bad83557a2c140e029 Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Fri, 11 Oct 2024 18:16:40 +0600 Subject: [PATCH 11/31] UP --- .../club/Components/Admin/AddQuestions.tsx | 29 ++++-- .../club/admin/eventEdit/[eventID]/page.tsx | 99 +++++++++++++++---- 2 files changed, 99 insertions(+), 29 deletions(-) diff --git a/src/app/club/Components/Admin/AddQuestions.tsx b/src/app/club/Components/Admin/AddQuestions.tsx index a732fd1..433272e 100644 --- a/src/app/club/Components/Admin/AddQuestions.tsx +++ b/src/app/club/Components/Admin/AddQuestions.tsx @@ -40,14 +40,17 @@ const AddQuestions = ({ questionsData, answersData, setData, + setQues, + setAns, }: { questionsData: any[]; answersData: any[]; setData: (questionData: any, answerData: any) => void; + setQues?: (s: any) => void; + setAns?: (s: any) => void; }) => { - const [questions, setQuestions] = - useState(questionsData); - const [answers, setAnswers] = useState(answersData); + const [questions, setQuestions] = useState([]); + const [answers, setAnswers] = useState([]); useEffect(() => { setAnswers(answersData); @@ -68,7 +71,6 @@ const AddQuestions = ({ const [point, setPoint] = useState(1); - const setOption = (i: number, value: string) => { switch (i) { case 0: @@ -94,7 +96,7 @@ const AddQuestions = ({ const addQuestion = () => { setQuestions((oldValue: any) => { - return [ + let sqd = [ ...oldValue, { question: question, @@ -106,10 +108,12 @@ const AddQuestions = ({ option3: option3, }, ]; + setQues && setQues(sqd); + return sqd; }); setAnswers((oldValue: any) => { - return [ + let sad = [ ...oldValue, { mcq: isMCQ, @@ -118,6 +122,10 @@ const AddQuestions = ({ correctAnswers: correctAnswers, }, ]; + + setAns && setAns(sad); + + return sad; }); setQuestion(""); @@ -173,7 +181,12 @@ const AddQuestions = ({ }; useEffect(() => { - setData(questions, answers); + console.log("-------------"); + + console.log("qb", questions); + console.log("ab", answers); + + console.log("-------------"); }, [questions, answers]); return ( @@ -198,7 +211,7 @@ const AddQuestions = ({ correctOption={answers[i].correctOption} correctAnswers={answers[i].correctAnswers} index={i} - key={i} + key={i + Math.random()} onValueChange={onValueChange} deleteQuestion={deleteQuestion} /> diff --git a/src/app/club/admin/eventEdit/[eventID]/page.tsx b/src/app/club/admin/eventEdit/[eventID]/page.tsx index 1752a85..0b00b43 100644 --- a/src/app/club/admin/eventEdit/[eventID]/page.tsx +++ b/src/app/club/admin/eventEdit/[eventID]/page.tsx @@ -117,7 +117,7 @@ const Page = ({ params }: { params: { eventID: string } }) => { setAdminAuth(false); setAuthLoading(false); } - + console.log("loaded"); if (params.eventID != "new") { const event = getDoc(doc(db, "events", params.eventID)).then((event) => { if (event.exists()) { @@ -154,7 +154,7 @@ const Page = ({ params }: { params: { eventID: string } }) => { } else { setNotfound(false); } - }, [user]); + }, [params.eventID, user]); const handleSubmit = async (event: any) => { event.preventDefault(); @@ -288,6 +288,33 @@ 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 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(); @@ -595,6 +622,8 @@ const Page = ({ params }: { params: { eventID: string } }) => { questionsData={questions} answersData={answers} setData={setData} + setQues={(s) => setQuestions(s)} + setAns={(s) => setAnswers(s)} /> @@ -651,26 +680,54 @@ const Page = ({ params }: { params: { eventID: string } }) => { )}
-
+
{params.eventID != "new" && ( -
- -
+ <> +
+ +
+
+ +
+
+ +
+ )}
From 3cd0fda9c2fa6c9732f2342a19a3f8e53a7ef93a Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Fri, 11 Oct 2024 19:29:44 +0600 Subject: [PATCH 12/31] Added Markdown Preview --- .../club/Components/Admin/AddQuestions.tsx | 71 ++++++++++++++++++- src/app/globals.css | 8 +-- 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/app/club/Components/Admin/AddQuestions.tsx b/src/app/club/Components/Admin/AddQuestions.tsx index 433272e..efc57a5 100644 --- a/src/app/club/Components/Admin/AddQuestions.tsx +++ b/src/app/club/Components/Admin/AddQuestions.tsx @@ -1,8 +1,15 @@ -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { FaPlus } from "react-icons/fa6"; import { RiDeleteBin6Line } from "react-icons/ri"; import { RxGear } from "react-icons/rx"; +import Markdown from "react-markdown"; import { toast } from "react-toastify"; +import rehypeHighlight from "rehype-highlight"; +import rehypeKatex from "rehype-katex"; +import remarkGfm from "remark-gfm"; +import remarkMath from "remark-math"; +import "highlight.js/styles/atom-one-light.css"; +import "katex/dist/katex.min.css"; interface questionInterface { mcq: boolean; @@ -189,6 +196,24 @@ const AddQuestions = ({ console.log("-------------"); }, [questions, answers]); + const modifiedText = useMemo(() => { + const lines = (question || "").split("\n"); + + return lines + .map((line, index) => { + // Check if the line is part of a list + const isListItem = /^\s*[*\-+]\s+|^\s*\d+\.\s+/.test(line); + const isNextLineListItem = + index < lines.length - 1 && + /^\s*[*\-+]\s+|^\s*\d+\.\s+/.test(lines[index + 1]); + + if (isListItem || isNextLineListItem) return line; + + return line + "\n"; + }) + .join("\n"); + }, [question]); + return (
@@ -238,7 +263,18 @@ const AddQuestions = ({ rows={7} />
- +
+ +
+ + {modifiedText} + +
+
From 9c79af7583a1d62fa306aaec698b24e816987e96 Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Sat, 12 Oct 2024 14:19:06 +0600 Subject: [PATCH 15/31] up --- src/app/api/getevents/route.ts | 1 + src/app/api/getquestion/route.ts | 5 +- .../club/Components/Admin/AddQuestions.tsx | 4 +- src/app/club/Components/Events/EventCard.tsx | 14 +- src/app/club/Components/Events/EventList.tsx | 1 + src/app/club/Components/Home/DamianPopUp.tsx | 2 +- .../Components/Participate/AnswerSheet.tsx | 26 +++- .../club/Components/Participate/Question.tsx | 15 +- .../club/admin/eventEdit/[eventID]/page.tsx | 138 ++++++++---------- 9 files changed, 112 insertions(+), 94 deletions(-) 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" && ( <>
-
-
- -
-
-
+
@@ -758,15 +746,13 @@ const Page = ({ params }: { params: { eventID: string } }) => {
From 9ee8ebcda6516d662ccfd4a9ebf71910ed23ec1c Mon Sep 17 00:00:00 2001 From: RafsanAmin Date: Sat, 12 Oct 2024 18:35:57 +0600 Subject: [PATCH 16/31] 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 } }) => {
+
+ +
+ +
@@ -471,7 +538,7 @@ const Page = () => { )}
- ) : authLoading ? ( + ) : authLoading || loading ? ( ) : ( From c8990af2ddfed4970daf649aa5499b333b65127b Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Mon, 14 Oct 2024 10:48:49 +0600 Subject: [PATCH 21/31] User Data Download System Updated / Tweaked --- .../Components/Admin/DownloadUserData.tsx | 124 ++++++++++++++++++ .../club/admin/(adminpanel)/users/page.tsx | 74 +---------- 2 files changed, 130 insertions(+), 68 deletions(-) create mode 100644 src/app/club/Components/Admin/DownloadUserData.tsx diff --git a/src/app/club/Components/Admin/DownloadUserData.tsx b/src/app/club/Components/Admin/DownloadUserData.tsx new file mode 100644 index 0000000..e081df4 --- /dev/null +++ b/src/app/club/Components/Admin/DownloadUserData.tsx @@ -0,0 +1,124 @@ +import { + Button, + Modal, + ModalBody, + ModalContent, + ModalFooter, + ModalHeader, + useDisclosure, +} from "@nextui-org/react"; +import { getDocs } from "firebase/firestore"; +import { useState } from "react"; +import { MdOutlinePersonSearch } from "react-icons/md"; +import { toast } from "react-toastify"; +import * as XLSX from "xlsx"; + +const DownloadUserData = ({ + adminAuth, + onFilterQuery, +}: { + adminAuth: boolean; + onFilterQuery: (loadMore: boolean, limitLess: boolean) => any; +}) => { + const [loading, setLoading] = useState(false); + + const { isOpen, onOpen, onOpenChange } = useDisclosure(); + + const getAllDocs = async (limitless: boolean) => { + try { + if (adminAuth) { + setLoading(true); + const data: any = []; + const x = await getDocs(onFilterQuery(false, limitless)); + + x.forEach((doc) => { + const temp: any = doc.data(); + const createdAt = new Date( + temp?.timestamp?.seconds * 1000, + ).toString(); + if (temp.timestamp) { + delete temp.timestamp; + } + data.push({ + uid: doc.id, + createdAt, + ...temp, + }); + }); + + const workBook = XLSX.utils.book_new(); + const xlsx = XLSX.utils.json_to_sheet(data); + XLSX.utils.book_append_sheet(workBook, xlsx, "All Participants"); + + XLSX.writeFile(workBook, "Participants.xlsx"); + + // setUrl(URL.createObjectURL(blob)); + + // setTimeout(() => downloadRef.current?.click(), 3000); + setLoading(false); + toast.info("Data Downloaded as XLSX"); + } + } catch (err) { + setLoading(false); + console.error(err); + toast.error("Something went wrong!"); + } + }; + + return ( +
+ + + + + + {(onClose) => ( + <> + + All USER DATA! + + +

+ Are you really fucking serious?!? If you've gone mental. Then + alright. Go ahead. Download all the User Data at once. Good + Luck! +

+
+ + + + + + )} +
+
+
+ ); +}; + +export default DownloadUserData; diff --git a/src/app/club/admin/(adminpanel)/users/page.tsx b/src/app/club/admin/(adminpanel)/users/page.tsx index 0056c96..4680ab6 100644 --- a/src/app/club/admin/(adminpanel)/users/page.tsx +++ b/src/app/club/admin/(adminpanel)/users/page.tsx @@ -39,10 +39,9 @@ import { FaCaretUp, FaFilter, FaRegEdit } from "react-icons/fa"; import { FiCheckCircle, FiUser } from "react-icons/fi"; import { LiaTimesSolid } from "react-icons/lia"; import PassingYear from "../../../Components/PassingYear"; -import { CiEdit } from "react-icons/ci"; import Loading from "../../../Components/Loading"; import { BiHeart } from "react-icons/bi"; -import * as XLSX from "xlsx"; +import DownloadUserData from "@/app/club/Components/Admin/DownloadUserData"; const getMemberByRoll = async (ndc_roll: string) => { const res = await fetch("/api/getmemberbyroll", { @@ -61,8 +60,6 @@ const Page = () => { const [usersData, setUsersData] = useState([]); const [lastUserDoc, setLastUserDoc] = useState(); - const [loading, setLoading] = useState(false); - const [totalUsers, setTotalUsers] = useState(0); const docLimit = 10; @@ -217,47 +214,6 @@ const Page = () => { }); }; - const getAllDocs = async (limitless: boolean) => { - try { - if (adminAuth) { - setLoading(true); - const data: any = []; - const x = await getDocs(onFilterQuery(false, limitless)); - - x.forEach((doc) => { - const temp = doc.data(); - const createdAt = new Date( - temp?.timestamp?.seconds * 1000, - ).toString(); - if (temp.timestamp) { - delete temp.timestamp; - } - data.push({ - uid: doc.id, - createdAt, - ...temp, - }); - }); - - const workBook = XLSX.utils.book_new(); - const xlsx = XLSX.utils.json_to_sheet(data); - XLSX.utils.book_append_sheet(workBook, xlsx, "All Participants"); - - XLSX.writeFile(workBook, "Participants.xlsx"); - - // setUrl(URL.createObjectURL(blob)); - - // setTimeout(() => downloadRef.current?.click(), 3000); - setLoading(false); - toast.info("Data Downloaded as XLSX"); - } - } catch (err) { - setLoading(false); - console.error(err); - toast.error("Something went wrong!"); - } - }; - return ( <> {adminAuth ? ( @@ -374,28 +330,10 @@ const Page = () => { />
-
- - -
+
@@ -538,7 +476,7 @@ const Page = () => { )}
- ) : authLoading || loading ? ( + ) : authLoading ? ( ) : ( From 85a575ae8916e216b1d0c9bdee052cb72002d2e2 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Mon, 14 Oct 2024 11:41:40 +0600 Subject: [PATCH 22/31] Announcement Tweak --- src/app/club/Components/Admin/AdminAnnouncements.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/club/Components/Admin/AdminAnnouncements.tsx b/src/app/club/Components/Admin/AdminAnnouncements.tsx index 04b56d7..c831130 100644 --- a/src/app/club/Components/Admin/AdminAnnouncements.tsx +++ b/src/app/club/Components/Admin/AdminAnnouncements.tsx @@ -51,6 +51,7 @@ const Announcements = () => { }); annc.reverse(); setAnnouncements(annc); + setOrder(docs.docs.length); }) .catch((err) => { toast.error("Announcements can't be loaded"); From 34cecd15e7c0eace20390ea15840e410255cd449 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Mon, 14 Oct 2024 19:12:29 +0600 Subject: [PATCH 23/31] Ranker Download System --- src/app/club/admin/rankers/[id]/page.tsx | 50 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/app/club/admin/rankers/[id]/page.tsx b/src/app/club/admin/rankers/[id]/page.tsx index 80d457e..9a78db0 100644 --- a/src/app/club/admin/rankers/[id]/page.tsx +++ b/src/app/club/admin/rankers/[id]/page.tsx @@ -43,6 +43,8 @@ import Field from "../../../Components/Field"; import PassingYear from "../../../Components/PassingYear"; import Loading from "../../../Components/Loading"; import { useRouter } from "next/navigation"; +import * as XLSX from "xlsx"; +import { FaDownload } from "react-icons/fa6"; const Page = ({ params }: { params: { id: string } }) => { const [adminAuth, setAdminAuth] = useState(false); @@ -202,6 +204,41 @@ const Page = ({ params }: { params: { id: string } }) => { }); }; + const [loading, setLoading] = useState(false); + + const downloadData = async () => { + try { + setLoading(true); + if (adminAuth) { + const data: any = []; + + usersData.forEach((e: any, i: number) => { + data.push({ + uid: e.id, + ...e.data, + ...e.quizData, + }); + }); + + const workBook = XLSX.utils.book_new(); + const xlsx = XLSX.utils.json_to_sheet(data); + XLSX.utils.book_append_sheet(workBook, xlsx, "All Participants"); + + XLSX.writeFile(workBook, "Participants.xlsx"); + + // setUrl(URL.createObjectURL(blob)); + + // setTimeout(() => downloadRef.current?.click(), 3000); + setLoading(false); + toast.info("Data Downloaded as XLSX"); + } + } catch (err) { + setLoading(false); + console.error(err); + toast.error("Something went wrong!"); + } + }; + return ( <> {adminAuth ? ( @@ -238,6 +275,15 @@ const Page = ({ params }: { params: { id: string } }) => { > Search User + +
@@ -391,7 +437,7 @@ const Page = ({ params }: { params: { id: string } }) => { - {usersData.length >= docLimit && ( + {/*usersData.length >= docLimit && ( - )} + )*/}
) : authLoading ? ( From 14f184c6285c0839fac46044bbc9e1d0c3ce6c50 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Tue, 15 Oct 2024 16:44:05 +0600 Subject: [PATCH 24/31] Ranker Answers Tweaks --- src/app/club/admin/rankers/[id]/page.tsx | 28 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/club/admin/rankers/[id]/page.tsx b/src/app/club/admin/rankers/[id]/page.tsx index 9a78db0..1131405 100644 --- a/src/app/club/admin/rankers/[id]/page.tsx +++ b/src/app/club/admin/rankers/[id]/page.tsx @@ -768,14 +768,30 @@ const EditEventData = ({ }} /> -
+
{eventData.answers.map((e: any, i: number) => { return ( -
- {`${i + 1}. `} -
-

{`Chosen Option: ${e.option == 0 ? "A" : e.option == 1 ? "B" : e.option == 2 ? "C" : e.option == 3 ? "D" : "Not Selected"}`}

-

{`Chosen Answer: ${e.answer == "" ? "Not Answered" : e.answer}`}

+
+

{`Answer No. ${i + 1}`}

+
+
+ MCQ : + +

+ {`${e.option == 0 ? "A" : e.option == 1 ? "B" : e.option == 2 ? "C" : e.option == 3 ? "D" : "X"}`} +

+
+
+
+ + Answer: + +
+ {`${e.answer == "" ? "Not Answered" : e.answer}`} +
); From 82ead73a894c0805c401e81025b11781c60ba932 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Tue, 15 Oct 2024 18:52:46 +0600 Subject: [PATCH 25/31] Tweak --- src/app/club/admin/rankers/[id]/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/club/admin/rankers/[id]/page.tsx b/src/app/club/admin/rankers/[id]/page.tsx index 1131405..efd5120 100644 --- a/src/app/club/admin/rankers/[id]/page.tsx +++ b/src/app/club/admin/rankers/[id]/page.tsx @@ -773,7 +773,7 @@ const EditEventData = ({ return (

{`Answer No. ${i + 1}`}

From c76900e5399c8ef0d7d98173d8821751cca493cb Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Tue, 15 Oct 2024 19:55:15 +0600 Subject: [PATCH 26/31] Tweak --- src/app/club/admin/rankers/[id]/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/club/admin/rankers/[id]/page.tsx b/src/app/club/admin/rankers/[id]/page.tsx index efd5120..02ff79e 100644 --- a/src/app/club/admin/rankers/[id]/page.tsx +++ b/src/app/club/admin/rankers/[id]/page.tsx @@ -749,7 +749,7 @@ const EditEventData = ({ }; return ( -
+
{error == "" && eventData && eventData?.uid == uid && (
-
+
{eventData.answers.map((e: any, i: number) => { return (
Date: Fri, 18 Oct 2024 21:52:14 +0600 Subject: [PATCH 27/31] push --- .../club/Components/Admin/AdminEventCard.tsx | 9 +- .../club/Components/Participate/Question.tsx | 5 +- src/app/club/admin/rankers/[id]/page.tsx | 130 ++++++++++++++---- src/app/club/page.tsx | 1 - 4 files changed, 112 insertions(+), 33 deletions(-) diff --git a/src/app/club/Components/Admin/AdminEventCard.tsx b/src/app/club/Components/Admin/AdminEventCard.tsx index 1319f35..edfbec2 100644 --- a/src/app/club/Components/Admin/AdminEventCard.tsx +++ b/src/app/club/Components/Admin/AdminEventCard.tsx @@ -1,6 +1,6 @@ import Link from "next/link"; import { IoCalendarOutline, IoSettingsOutline } from "react-icons/io5"; -import { BsStopwatch } from "react-icons/bs"; +import { BsStopwatch, BsTrophy } from "react-icons/bs"; import { timeValue } from "../Time"; import { Timestamp } from "firebase/firestore"; import _L0 from "@/util/leadingzero"; @@ -68,6 +68,13 @@ const AdminEventCard = ({ EDIT + + + RANKS +
); diff --git a/src/app/club/Components/Participate/Question.tsx b/src/app/club/Components/Participate/Question.tsx index e5dd410..27a6778 100644 --- a/src/app/club/Components/Participate/Question.tsx +++ b/src/app/club/Components/Participate/Question.tsx @@ -37,7 +37,7 @@ const Question = ({ givenAnswer, }: questionInterface) => { const [selectedVal, setSelectedVal] = useState(selectedOption); - const [savedOnce, setSavedOnce] = useState(givenAnswer === "" ? false : true); + const [savedOnce, setSavedOnce] = useState(false); const options = [option0, option1, option2, option3]; const optionsArr = ["A", "B", "C", "D"]; @@ -47,6 +47,9 @@ const Question = ({ useEffect(() => { setAnswer(givenAnswer); setSelectedVal(selectedOption); + if (givenAnswer !== "") { + setSavedOnce(true); + } }, [givenAnswer, selectedOption]); // useEffect(() => { diff --git a/src/app/club/admin/rankers/[id]/page.tsx b/src/app/club/admin/rankers/[id]/page.tsx index 02ff79e..a587cde 100644 --- a/src/app/club/admin/rankers/[id]/page.tsx +++ b/src/app/club/admin/rankers/[id]/page.tsx @@ -42,7 +42,7 @@ import { BiHeart } from "react-icons/bi"; import Field from "../../../Components/Field"; import PassingYear from "../../../Components/PassingYear"; import Loading from "../../../Components/Loading"; -import { useRouter } from "next/navigation"; +import { notFound, useRouter } from "next/navigation"; import * as XLSX from "xlsx"; import { FaDownload } from "react-icons/fa6"; @@ -52,7 +52,9 @@ const Page = ({ params }: { params: { id: string } }) => { const [authLoading, setAuthLoading] = useState(true); const [usersData, setUsersData] = useState([]); + const [eventAns, seteventAns] = useState([]); const [lastUserDoc, setLastUserDoc] = useState(); + const [eventQues, setEventQues] = useState([]); const docLimit = 5; @@ -86,6 +88,13 @@ const Page = ({ params }: { params: { id: string } }) => { }); //setUsersData((oldArr: any) => [oldArr, ...tempArr]); + getDoc(doc(db, "answers", params.id)).then((event) => { + if (event.exists()) { + seteventAns(event.data()); + } else { + notFound(); + } + }); setAuthLoading(false); }; @@ -244,9 +253,9 @@ const Page = ({ params }: { params: { id: string } }) => { {adminAuth ? (
-
+

RANKERS PANEL

@@ -417,13 +426,14 @@ const Page = ({ params }: { params: { id: string } }) => { /> {params.id != "public" && ( - )} @@ -698,29 +708,31 @@ const EditUserData = ({ ); }; -const EditEventData = ({ +const EditeventAns = ({ data, id, uid, allData, setAllData, + eData, i, }: { data: any; id: string; uid: string; allData: any[]; + eData: any; setAllData: React.Dispatch; i: number; }) => { - const [eventData, setEventData] = useState(data); + const [eventAns, seteventAns] = useState(data); const [error, setError] = useState(""); const updateData = async () => { await updateDoc( doc(db, "answers", id, "eventparticipant", uid), - eventData, + eventAns, ).catch(() => { setError("Error Occurred. Code 0"); toast.error("Error Occurred 0"); @@ -728,7 +740,7 @@ const EditEventData = ({ await updateDoc( doc(db, "eventparticipant", uid, "eventsData", id), - eventData, + eventAns, ).catch(() => { setError("Error Occurred. Code 1"); toast.error("Error Occurred 1"); @@ -739,7 +751,7 @@ const EditEventData = ({ // No change return e; } else { - return { ...e, quizData: { ...eventData } }; + return { ...e, quizData: { ...eventAns } }; } }); // Re-render with the new array @@ -747,19 +759,33 @@ const EditEventData = ({ toast.success("Event Data Updated"); }; + const checkAns = (main: any, data: any) => { + if (main.mcq) { + if (data.option == main.correctOption) { + return true; + } + } else { + const correctAnswers = main.correctAnswers.toString().split(";"); + + if (correctAnswers.includes(data.answer)) { + return true; + } + } + return false; + }; return (
- {error == "" && eventData && eventData?.uid == uid && ( + {error == "" && eventAns && eventAns?.uid == uid && (
{ - setEventData((oldData: any) => { + seteventAns((oldData: any) => { return { ...oldData, marks: data, @@ -769,30 +795,74 @@ const EditEventData = ({ />
- {eventData.answers.map((e: any, i: number) => { + {eventAns.answers.map((e: any, i: number) => { return (
-

{`Answer No. ${i + 1}`}

+

{`${i + 1}`}

-
- MCQ : - -

- {`${e.option == 0 ? "A" : e.option == 1 ? "B" : e.option == 2 ? "C" : e.option == 3 ? "D" : "X"}`} -

-
-
-
- - Answer: - -
- {`${e.answer == "" ? "Not Answered" : e.answer}`} -
+ {eData?.answers[i].mcq ? ( +
+ + MCQ Given: + + +

+ {`${e.option == 0 ? "A" : e.option == 1 ? "B" : e.option == 2 ? "C" : e.option == 3 ? "D" : "X"}`} +

+
+
+ {!checkAns(eData.answers[i], e) && ( + <> + {" "} + + Correct: + + +

+ {`${eData?.answers[i].correctOption == 0 ? "A" : eData?.answers[i].correctOption == 1 ? "B" : eData?.answers[i].correctOption == 2 ? "C" : eData?.answers[i].correctOption == 3 ? "D" : "X"}`} +

+
+ + )} +
+ ) : null} + + {!eData?.answers[i].mcq ? ( +
+ Answer: +
+ {`${e.answer == "" ? "-" : e.answer}`} + {!checkAns(eData.answers[i], e) ? ( + <> +
+
+ {`${eData?.answers[i].correctAnswers == "" ? "Not Answered" : (eData?.answers[i].correctAnswers).replaceAll(";", " ; ")}`}{" "} +
+ + ) : null} +
+ ) : null}
+

{`${eData.answers[i].point}`}

); })} diff --git a/src/app/club/page.tsx b/src/app/club/page.tsx index 1947f5f..e90992f 100644 --- a/src/app/club/page.tsx +++ b/src/app/club/page.tsx @@ -18,7 +18,6 @@ const page = () => { -
); From 9168e32a04f32d7383a83a5656170e21bf318c43 Mon Sep 17 00:00:00 2001 From: The-XENO-Studios Date: Tue, 22 Oct 2024 22:55:34 +0600 Subject: [PATCH 28/31] Club Portal Removed --- .../(user-handle)/delete-account/page.tsx | 133 --- src/app/club/(user-handle)/login/page.tsx | 143 --- .../profile/announcements/page.tsx | 17 - .../club/(user-handle)/profile/club/page.tsx | 25 - .../(user-handle)/profile/events/page.tsx | 7 - src/app/club/(user-handle)/profile/layout.tsx | 99 -- src/app/club/(user-handle)/profile/page.tsx | 59 -- src/app/club/(user-handle)/register/page.tsx | 398 -------- .../registration-closed/page.tsx | 23 - .../(user-handle)/reset-password/page.tsx | 122 --- src/app/club/(user-handle)/verify/page.tsx | 150 --- .../club/Components/Admin/AddQuestions.tsx | 598 ------------ .../Components/Admin/AdminAnnouncements.tsx | 276 ------ .../club/Components/Admin/AdminEventCard.tsx | 83 -- src/app/club/Components/Admin/AdminEvents.tsx | 70 -- .../Components/Admin/DownloadUserData.tsx | 124 --- src/app/club/Components/Admin/EditConfig.tsx | 110 --- .../club/Components/Admin/EventPicture.tsx | 143 --- src/app/club/Components/CommonPage.tsx | 150 --- src/app/club/Components/Contact.tsx | 191 ---- src/app/club/Components/CurrentYear.tsx | 18 - src/app/club/Components/Dashboard/Ranking.tsx | 108 --- src/app/club/Components/DeveloperLink.tsx | 19 - src/app/club/Components/Error.tsx | 44 - src/app/club/Components/Events/EventCard.tsx | 120 --- src/app/club/Components/Events/EventList.tsx | 33 - .../Components/Events/PartcipateButton.tsx | 18 - src/app/club/Components/Field.tsx | 50 - src/app/club/Components/File.tsx | 11 - src/app/club/Components/Home/About.tsx | 57 -- src/app/club/Components/Home/DamianPopUp.tsx | 130 --- src/app/club/Components/Home/FAQ.tsx | 106 --- src/app/club/Components/Home/Hero.tsx | 48 - src/app/club/Components/Home/Member.tsx | 68 -- .../club/Components/Home/RedirectButton.tsx | 37 - src/app/club/Components/Home/Rules.tsx | 71 -- src/app/club/Components/Home/Setter.tsx | 48 - src/app/club/Components/InfoBox.tsx | 27 - .../Components/Layout/AuthContextProvider.tsx | 27 - .../club/Components/Layout/ConfigProvider.tsx | 63 -- src/app/club/Components/Layout/Footer.tsx | 176 ---- src/app/club/Components/Layout/Hover.tsx | 144 --- src/app/club/Components/Layout/Navbar.tsx | 320 ------- .../Components/Layout/UserDataProvider.tsx | 97 -- src/app/club/Components/Loading.tsx | 12 - src/app/club/Components/Modal.tsx | 27 - .../Components/Participate/AnswerSheet.tsx | 292 ------ .../club/Components/Participate/Question.tsx | 189 ---- src/app/club/Components/Participate/Timer.tsx | 60 -- src/app/club/Components/PassingYear.tsx | 50 - .../club/Components/Profile/Announcements.tsx | 74 -- src/app/club/Components/Profile/ClubInfo.tsx | 315 ------- .../club/Components/Profile/ContestCard.tsx | 115 --- src/app/club/Components/Profile/EditData.tsx | 181 ---- .../club/Components/Profile/ProfileHero.tsx | 50 - .../club/Components/Profile/ProfilePic.tsx | 157 ---- src/app/club/Components/Select.tsx | 39 - src/app/club/Components/SubNav.tsx | 45 - src/app/club/Components/Textarea.tsx | 44 - src/app/club/Components/Time.ts | 40 - src/app/club/Context/AdminContext.ts | 5 - src/app/club/actions/actions.ts | 1 - .../admin/(adminpanel)/announcements/page.tsx | 14 - .../club/admin/(adminpanel)/events/page.tsx | 15 - src/app/club/admin/(adminpanel)/layout.tsx | 120 --- src/app/club/admin/(adminpanel)/page.tsx | 117 --- .../club/admin/(adminpanel)/users/AddUser.tsx | 65 -- .../club/admin/(adminpanel)/users/page.tsx | 846 ----------------- .../club/admin/eventEdit/[eventID]/page.tsx | 777 --------------- src/app/club/admin/login/page.tsx | 141 --- src/app/club/admin/rankers/[id]/page.tsx | 883 ------------------ src/app/club/developer/Modal.tsx | 141 --- src/app/club/developer/developers.ts | 75 -- src/app/club/developer/page.tsx | 88 -- .../club/eventdetails/[id]/Eligibility.tsx | 34 - .../eventdetails/[id]/ParticipateButton.tsx | 63 -- src/app/club/eventdetails/[id]/loading.tsx | 35 - src/app/club/eventdetails/[id]/page.tsx | 108 --- .../events/[uid]/[memberid]/[type]/page.tsx | 29 - src/app/club/events/[uid]/[memberid]/page.tsx | 97 -- src/app/club/events/page.tsx | 52 -- src/app/club/page.tsx | 26 - src/app/club/participate/[id]/page.tsx | 114 --- src/app/club/standings/[type]/page.tsx | 194 ---- 84 files changed, 10491 deletions(-) delete mode 100644 src/app/club/(user-handle)/delete-account/page.tsx delete mode 100644 src/app/club/(user-handle)/login/page.tsx delete mode 100644 src/app/club/(user-handle)/profile/announcements/page.tsx delete mode 100644 src/app/club/(user-handle)/profile/club/page.tsx delete mode 100644 src/app/club/(user-handle)/profile/events/page.tsx delete mode 100644 src/app/club/(user-handle)/profile/layout.tsx delete mode 100644 src/app/club/(user-handle)/profile/page.tsx delete mode 100644 src/app/club/(user-handle)/register/page.tsx delete mode 100644 src/app/club/(user-handle)/registration-closed/page.tsx delete mode 100644 src/app/club/(user-handle)/reset-password/page.tsx delete mode 100644 src/app/club/(user-handle)/verify/page.tsx delete mode 100644 src/app/club/Components/Admin/AddQuestions.tsx delete mode 100644 src/app/club/Components/Admin/AdminAnnouncements.tsx delete mode 100644 src/app/club/Components/Admin/AdminEventCard.tsx delete mode 100644 src/app/club/Components/Admin/AdminEvents.tsx delete mode 100644 src/app/club/Components/Admin/DownloadUserData.tsx delete mode 100644 src/app/club/Components/Admin/EditConfig.tsx delete mode 100644 src/app/club/Components/Admin/EventPicture.tsx delete mode 100644 src/app/club/Components/CommonPage.tsx delete mode 100644 src/app/club/Components/Contact.tsx delete mode 100644 src/app/club/Components/CurrentYear.tsx delete mode 100644 src/app/club/Components/Dashboard/Ranking.tsx delete mode 100644 src/app/club/Components/DeveloperLink.tsx delete mode 100644 src/app/club/Components/Error.tsx delete mode 100644 src/app/club/Components/Events/EventCard.tsx delete mode 100644 src/app/club/Components/Events/EventList.tsx delete mode 100644 src/app/club/Components/Events/PartcipateButton.tsx delete mode 100644 src/app/club/Components/Field.tsx delete mode 100644 src/app/club/Components/File.tsx delete mode 100644 src/app/club/Components/Home/About.tsx delete mode 100644 src/app/club/Components/Home/DamianPopUp.tsx delete mode 100644 src/app/club/Components/Home/FAQ.tsx delete mode 100644 src/app/club/Components/Home/Hero.tsx delete mode 100644 src/app/club/Components/Home/Member.tsx delete mode 100644 src/app/club/Components/Home/RedirectButton.tsx delete mode 100644 src/app/club/Components/Home/Rules.tsx delete mode 100644 src/app/club/Components/Home/Setter.tsx delete mode 100644 src/app/club/Components/InfoBox.tsx delete mode 100644 src/app/club/Components/Layout/AuthContextProvider.tsx delete mode 100644 src/app/club/Components/Layout/ConfigProvider.tsx delete mode 100644 src/app/club/Components/Layout/Footer.tsx delete mode 100644 src/app/club/Components/Layout/Hover.tsx delete mode 100644 src/app/club/Components/Layout/Navbar.tsx delete mode 100644 src/app/club/Components/Layout/UserDataProvider.tsx delete mode 100644 src/app/club/Components/Loading.tsx delete mode 100644 src/app/club/Components/Modal.tsx delete mode 100644 src/app/club/Components/Participate/AnswerSheet.tsx delete mode 100644 src/app/club/Components/Participate/Question.tsx delete mode 100644 src/app/club/Components/Participate/Timer.tsx delete mode 100644 src/app/club/Components/PassingYear.tsx delete mode 100644 src/app/club/Components/Profile/Announcements.tsx delete mode 100644 src/app/club/Components/Profile/ClubInfo.tsx delete mode 100644 src/app/club/Components/Profile/ContestCard.tsx delete mode 100644 src/app/club/Components/Profile/EditData.tsx delete mode 100644 src/app/club/Components/Profile/ProfileHero.tsx delete mode 100644 src/app/club/Components/Profile/ProfilePic.tsx delete mode 100644 src/app/club/Components/Select.tsx delete mode 100644 src/app/club/Components/SubNav.tsx delete mode 100644 src/app/club/Components/Textarea.tsx delete mode 100644 src/app/club/Components/Time.ts delete mode 100644 src/app/club/Context/AdminContext.ts delete mode 100644 src/app/club/actions/actions.ts delete mode 100644 src/app/club/admin/(adminpanel)/announcements/page.tsx delete mode 100644 src/app/club/admin/(adminpanel)/events/page.tsx delete mode 100644 src/app/club/admin/(adminpanel)/layout.tsx delete mode 100644 src/app/club/admin/(adminpanel)/page.tsx delete mode 100644 src/app/club/admin/(adminpanel)/users/AddUser.tsx delete mode 100644 src/app/club/admin/(adminpanel)/users/page.tsx delete mode 100644 src/app/club/admin/eventEdit/[eventID]/page.tsx delete mode 100644 src/app/club/admin/login/page.tsx delete mode 100644 src/app/club/admin/rankers/[id]/page.tsx delete mode 100644 src/app/club/developer/Modal.tsx delete mode 100644 src/app/club/developer/developers.ts delete mode 100644 src/app/club/developer/page.tsx delete mode 100644 src/app/club/eventdetails/[id]/Eligibility.tsx delete mode 100644 src/app/club/eventdetails/[id]/ParticipateButton.tsx delete mode 100644 src/app/club/eventdetails/[id]/loading.tsx delete mode 100644 src/app/club/eventdetails/[id]/page.tsx delete mode 100644 src/app/club/events/[uid]/[memberid]/[type]/page.tsx delete mode 100644 src/app/club/events/[uid]/[memberid]/page.tsx delete mode 100644 src/app/club/events/page.tsx delete mode 100644 src/app/club/page.tsx delete mode 100644 src/app/club/participate/[id]/page.tsx delete mode 100644 src/app/club/standings/[type]/page.tsx diff --git a/src/app/club/(user-handle)/delete-account/page.tsx b/src/app/club/(user-handle)/delete-account/page.tsx deleted file mode 100644 index aeca790..0000000 --- a/src/app/club/(user-handle)/delete-account/page.tsx +++ /dev/null @@ -1,133 +0,0 @@ -"use client"; - -import Field from "@/app/club/Components/Field"; -import React, { useEffect, useState } from "react"; -import Link from "next/link"; -import { auth, db, pfp } from "@/config/firebase"; - -import { deleteUser, signInWithEmailAndPassword } from "firebase/auth"; - -import { toast } from "react-toastify"; -import { CgArrowLeft, CgSpinner } from "react-icons/cg"; -import { useRouter } from "next/navigation"; -import Image from "next/image"; -import { doc, DocumentReference, deleteDoc } from "firebase/firestore"; -import { useAuthState } from "react-firebase-hooks/auth"; -import { deleteObject, ref } from "firebase/storage"; -import ActualUser from "@/util/ActualUser"; - -const deleteEventParticipantDoc = async (uid: string) => { - const res = await fetch("/api/submit", { - method: "POST", - body: JSON.stringify({ uid: uid }), - }); - - if (!res.ok) { - toast.error("Error Occurred"); - return []; - } - - return res.json(); -}; - -const Page = () => { - const [password, setPassword] = useState(""); - const [loading, setLoading] = useState(false); - const [user] = useAuthState(auth); - const Router = useRouter(); - const handleSubmit = async (event: any) => { - event.preventDefault(); - setLoading(true); - if (user && user.email) { - signInWithEmailAndPassword(auth, user.email, password) - .then(async (UserCred) => { - const UserInfo = UserCred.user; - await deleteUser(UserInfo); - await deleteDoc(doc(db, "participants", UserInfo.uid)); - await deleteObject(ref(pfp, "pfp/" + UserInfo.uid)); - await deleteEventParticipantDoc(UserInfo.uid); - toast.success(`User Deleted!`); - setLoading(false); - Router.push("/club"); - }) - .catch((error) => { - console.dir(error); - switch (error.code) { - case "auth/invalid-credential": - toast.error(`Invalid password.`); - break; - case "storage/object-not-found": - break; - default: - console.error(error.message); - toast.error(error.message.replaceAll("Firebase: ", "")); - break; - } - setLoading(false); - }); - } else { - toast.error(`User not logged in.`); - setLoading(false); - } - }; - - return ( -
-
- -
- -
-

- ACCOUNT DELETION -

-

- If your delete your account then you have to register again. -

-
- setPassword(String(data))} - name="Password" - label="Password" - type="password" - />{" "} -
- -
-
- - -
-
- ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/login/page.tsx b/src/app/club/(user-handle)/login/page.tsx deleted file mode 100644 index 9442ad7..0000000 --- a/src/app/club/(user-handle)/login/page.tsx +++ /dev/null @@ -1,143 +0,0 @@ -"use client"; - -import Field from "@/app/club/Components/Field"; -import React, { useEffect, useState } from "react"; -import Link from "next/link"; -import { auth, db } from "@/config/firebase"; - -import { signInWithEmailAndPassword } from "firebase/auth"; - -import { toast } from "react-toastify"; -import { CgLogIn, CgSpinner } from "react-icons/cg"; -import { useRouter } from "next/navigation"; -import Image from "next/image"; -import { FirebaseError } from "firebase/app"; -import { useAuthContext } from "@/app/club/Components/Layout/AuthContextProvider"; - -const Page = () => { - const [password, setPassword] = useState(""); - const [email, setEmail] = useState(""); - const [loading, setLoading] = useState(false); - const [authLoading, setAuthLoading] = useState(false); - - const userAuth = useAuthContext().userAuth; - const uloading = useAuthContext().loading; - - const Router = useRouter(); - const handleSubmit = async (event: any) => { - event.preventDefault(); - setLoading(true); - signInWithEmailAndPassword(auth, email, password) - .then(async (UserCred) => { - toast.success("User logged in!"); - setLoading(false); - Router.push("/club/profile"); - }) - .catch((error: FirebaseError) => { - console.dir(error); - switch (error.code) { - case "auth/invalid-credential": - toast.error(`Invalid email or password.`); - break; - case "auth/too-many-requests": - toast.error( - `Too many login attempts. Please reset your password to login again.`, - ); - break; - default: - console.error(error.message); - toast.error(error.message.replaceAll("Firebase: ", "")); - break; - } - setLoading(false); - }); - }; - useEffect(() => { - setAuthLoading(true); - if (userAuth) { - Router.push("/club/profile"); - } - setAuthLoading(false); - }, [Router, userAuth]); - return ( -
-
-
- {uloading || authLoading ? ( -
- -
- ) : ( - <> - -

- PARTICIPANT Login -

-
- setEmail(String(data))} - name="email" - label="E-mail" - type="email" - /> - setPassword(String(data))} - name="Password" - label="Password" - type="password" - />{" "} -
-
- - Reset Password - -
-
- - -
- Don't have an account?{" "} - - Register Now - -
-
- - )} - - -
-
- ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/profile/announcements/page.tsx b/src/app/club/(user-handle)/profile/announcements/page.tsx deleted file mode 100644 index b060e2e..0000000 --- a/src/app/club/(user-handle)/profile/announcements/page.tsx +++ /dev/null @@ -1,17 +0,0 @@ -"use client"; - -import { useUserDataContext } from "@/app/club/Components/Layout/UserDataProvider"; -import Announcements from "@/app/club/Components/Profile/Announcements"; -import React from "react"; - -const Page = () => { - const { userData } = useUserDataContext(); - return ( -
- {userData?.ndc_id ? : null} - -
- ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/profile/club/page.tsx b/src/app/club/(user-handle)/profile/club/page.tsx deleted file mode 100644 index dbc8945..0000000 --- a/src/app/club/(user-handle)/profile/club/page.tsx +++ /dev/null @@ -1,25 +0,0 @@ -"use client"; -import { useUserDataContext } from "@/app/club/Components/Layout/UserDataProvider"; -import ClubInfo from "@/app/club/Components/Profile/ClubInfo"; -import { auth } from "@/config/firebase"; - -const Page = () => { - const { userData, userDataLoading, dataError, updateUserData } = - useUserDataContext(); - - return ( -
- {userData && !userDataLoading ? ( - - ) : null} -
- ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/profile/events/page.tsx b/src/app/club/(user-handle)/profile/events/page.tsx deleted file mode 100644 index 6a9b51a..0000000 --- a/src/app/club/(user-handle)/profile/events/page.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -const page = () => { - return
S
; -}; - -export default page; diff --git a/src/app/club/(user-handle)/profile/layout.tsx b/src/app/club/(user-handle)/profile/layout.tsx deleted file mode 100644 index 6f42b76..0000000 --- a/src/app/club/(user-handle)/profile/layout.tsx +++ /dev/null @@ -1,99 +0,0 @@ -/* eslint-disable @next/next/no-img-element */ -"use client"; - -import { auth } from "@/config/firebase"; -import { usePathname, useRouter } from "next/navigation"; -import React, { useEffect, useState } from "react"; -import { toast } from "react-toastify"; -import { useAuthState } from "react-firebase-hooks/auth"; -import { CgSpinner } from "react-icons/cg"; -import { - UserDataContextProvider, - useUserDataContext, -} from "@/app/club/Components/Layout/UserDataProvider"; -import ProfileHero from "../../Components/Profile/ProfileHero"; -import { SubNav, SubNavItem } from "../../Components/SubNav"; -import { CgProfile } from "react-icons/cg"; -import { MdAnnouncement, MdEvent } from "react-icons/md"; -import { IoPeopleOutline } from "react-icons/io5"; -import ContestCard from "../../Components/Profile/ContestCard"; -import Loading from "../../Components/Loading"; - -const Page = ({ children }: { children: React.ReactNode }) => { - const [userAuth, loading, error] = useAuthState(auth); - const [dLoading, setDLoading] = useState(true); - const Route = useRouter(); - - useEffect(() => { - auth.currentUser?.reload(); - - if (userAuth) { - fetch("/api/admin", { - method: "POST", - body: JSON.stringify({ id: userAuth.email }), - }) - .then((r) => r.json()) - .then((resp) => { - setDLoading(false); - if (resp.auth) { - Route.push("/club/admin"); - } - }) - .catch((err) => { - setDLoading(false); - toast.error("Something went wrong"); - }); - } - - if (userAuth && !userAuth?.emailVerified) { - setDLoading(false); - Route.push("/club/verify"); - } else if (!loading && !userAuth) { - setDLoading(false); - Route.push("/club/login"); - } - }, [Route, userAuth, loading]); - - return ( - <> - {userAuth ? ( -
- -
-
- - -
-
- - - Profile - - - Club{" "} - - - Notice - - {/* - Events - */} - -
- {children} -
-
-
- ) : loading || dLoading ? ( - - ) : ( -
- )} - - ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/profile/page.tsx b/src/app/club/(user-handle)/profile/page.tsx deleted file mode 100644 index 5dc74c1..0000000 --- a/src/app/club/(user-handle)/profile/page.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/* eslint-disable @next/next/no-img-element */ -"use client"; - -import { auth } from "@/config/firebase"; -import { useRouter } from "next/navigation"; -import React, { useEffect, useState } from "react"; -import { FaRegTrashAlt } from "react-icons/fa"; -import Link from "next/link"; -import { useAuthState } from "react-firebase-hooks/auth"; -import EditData from "@/app/club/Components/Profile/EditData"; -import Announcements from "@/app/club/Components/Profile/Announcements"; -import ClubInfo from "@/app/club/Components/Profile/ClubInfo"; -import { useUserDataContext } from "@/app/club/Components/Layout/UserDataProvider"; -import { MdLockReset } from "react-icons/md"; - -const Page = () => { - const [userAuth, loading, error] = useAuthState(auth); - - const [uData, setUserData] = useState(); - - const { userData, userDataLoading, dataError } = useUserDataContext(); - - // const [dLoading, setDLoading] = useState(true); - - const Route = useRouter(); - - useEffect(() => { - if (userData) { - setUserData({ ...userData }); - } - }, [userData]); - - return ( - <> - - -

- SPECIAL ACTIONS -

-
- - - Reset Password - - - Delete Account - -
- - ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/register/page.tsx b/src/app/club/(user-handle)/register/page.tsx deleted file mode 100644 index 89f8407..0000000 --- a/src/app/club/(user-handle)/register/page.tsx +++ /dev/null @@ -1,398 +0,0 @@ -"use client"; - -import Field from "@/app/club/Components/Field"; -import React, { useEffect, useReducer, useState } from "react"; -import { regDataInit, regDataType, classes } from "@/config/registerData"; -import Select from "@/app/club/Components/Select"; -import { auth, db } from "@/config/firebase"; -import { doc, serverTimestamp, setDoc } from "firebase/firestore"; - -import { - createUserWithEmailAndPassword, - sendEmailVerification, -} from "firebase/auth"; - -import verifyData from "@/util/verification"; -import { AiOutlineUserAdd } from "react-icons/ai"; -import { toast } from "react-toastify"; -import { CgSpinner } from "react-icons/cg"; -import { useRouter } from "next/navigation"; -import Link from "next/link"; -import { getConfig } from "@/config/config_db"; -import { Checkbox } from "@nextui-org/checkbox"; -import { useAuthContext } from "@/app/club/Components/Layout/AuthContextProvider"; -import PassingYear from "../../Components/PassingYear"; -import { CiWarning } from "react-icons/ci"; - -type actionType = { - type: "SET_FIELD"; - name: string; - data: string | number; -}; - -const getRegisteredNDC = async (regData: regDataType) => { - const res = await fetch("/api/createaccountndc", { - method: "POST", - body: JSON.stringify({ ...regData }), - }); - - return res; -}; - -const Page = () => { - const { userAuth, loading, error } = useAuthContext(); - - const [regData, dispatch] = useReducer< - (prevState: regDataType, action: actionType) => regDataType - >((prevState: regDataType, action: actionType) => { - switch (action.type) { - case "SET_FIELD": - return { ...prevState, [action.name]: action.data }; - default: - return { ...prevState }; - } - }, regDataInit); - const [password, setPassword] = useState(""); - const [confirmPassword, setConfirmPassword] = useState(""); - const [isNDCStudent, setIsNDCStudent] = useState(false); - const [configLoading, setConfigLoading] = useState(true); - const [rloading, setLoading] = useState(false); - const Router = useRouter(); - const handleSubmit = async (event: any) => { - event.preventDefault(); - setLoading(true); - const [verified, massage] = verifyData(regData, password, confirmPassword); - - if (isNDCStudent && regData.ndc_id != "") { - if (verified) { - const ndc_register_res = await getRegisteredNDC(regData); - const ndc_register_json = await ndc_register_res.json(); - - if (!ndc_register_res.ok) { - toast.error(ndc_register_json.error); - setLoading(false); - return; - } else { - if (ndc_register_json.success) { - regData.ndc_id = ndc_register_json.memberID; - createUserWithEmailAndPassword(auth, regData.email, password) - .then(async (userInfo) => { - //add userInfo in Collections - const uid = userInfo.user.uid; - await setDoc(doc(db, "participants", uid), { - ...regData, - institution: "Notre Dame College", - mobile: ndc_register_json.mobile, - name: ndc_register_json.name, - address: ndc_register_json.address, - class: ndc_register_json.year, - ndc_roll: ndc_register_json.roll, - timestamp: serverTimestamp(), - imageUrl: - "https://firebasestorage.googleapis.com/v0/b/ftmpc-63d81.appspot.com/o/pfp%2Fno_user.webp?alt=media&token=fd930687-e7b9-4fa6-9603-f20b73bd0a86", - }); - await sendEmailVerification(userInfo.user); - toast.success( - "Email verification link sent! Please verify your email please.", - ); - setLoading(false); - Router.push("/club/verify"); - }) - .catch((error) => { - switch (error.code) { - case "auth/email-already-in-use": - toast.error(`Email address already in use.`); - break; - case "auth/invalid-email": - toast.error(`Email address is invalid.`); - break; - case "auth/operation-not-allowed": - toast.error(`Error during sign up.`); - break; - case "auth/weak-password": - toast.error( - "Password is not strong enough. Add additional characters including special characters and numbers.", - ); - break; - default: - toast.error(error.message.replaceAll("Firebase: ", "")); - - break; - } - setLoading(false); - }); - } - } - } else { - toast.error(massage); - setLoading(false); - } - } else { - if (verified) { - // - - regData.ndc_id = ""; - createUserWithEmailAndPassword(auth, regData.email, password) - .then(async (userInfo) => { - //add userInfo in Collections - const uid = userInfo.user.uid; - await setDoc(doc(db, "participants", uid), { - ...regData, - timestamp: serverTimestamp(), - imageUrl: - "https://firebasestorage.googleapis.com/v0/b/ftmpc-63d81.appspot.com/o/pfp%2Fno_user.webp?alt=media&token=fd930687-e7b9-4fa6-9603-f20b73bd0a86", - }); - await sendEmailVerification(userInfo.user); - toast.success( - "Email verification link sent! Please verify your email please.", - ); - setLoading(false); - Router.push("/club/verify"); - }) - .catch((error) => { - switch (error.code) { - case "auth/email-already-in-use": - toast.error(`Email address already in use.`); - break; - case "auth/invalid-email": - toast.error(`Email address is invalid.`); - break; - case "auth/operation-not-allowed": - toast.error(`Error during sign up.`); - break; - case "auth/weak-password": - toast.error( - "Password is not strong enough. Add additional characters including special characters and numbers.", - ); - break; - default: - toast.error(error.message.replaceAll("Firebase: ", "")); - - break; - } - setLoading(false); - }); - } else { - toast.error(massage); - setLoading(false); - } - } - }; - const setValue = (name: string, data: string | number) => { - dispatch({ type: "SET_FIELD", name, data }); - }; - - useEffect(() => { - if (!loading && userAuth) { - Router.push("/club/verify"); - } - }, [userAuth, loading]); - - useEffect(() => { - getConfig() - .then((config: any) => { - if (!config.registration_status) { - Router.push("/club/registration-closed"); - } else { - setConfigLoading(false); - } - }) - .catch((err) => { - console.error(err); - - toast.error("Aww Snap!"); - }); - }, [Router]); - - return ( -
-
- {configLoading ? ( -
- -
- ) : ( - <> - -
- -

- Registration Form -

-

- Please fill out the form below to register.{" "} - - Login Instead - {" "} - if you have already registered. By filling out this form you are - agreeing, to our terms and conditions. -

- - {isNDCStudent && ( -

- - {" "} - - Notice: - - All Batch '26 Students are requested to create a Non-member - Account right now as all of your Club Forms haven't been - submitted yet. After we announce, you can enter your Roll in - your profile and it will be converted to a Member account - automatically. -

- )} -
- {/* */} -
- - -
-
-
- {/* Non-Member Fields */} - {!isNDCStudent ? ( - <> - - - - - - - ) : null} - {/* Member Fields */} - {isNDCStudent ? ( - - ) : null} - {/* Common Fields */} - - -

- setPassword(String(data))} - name="Password" - label="Password" - type="password" - />{" "} - setConfirmPassword(String(data))} - name="Confirm Password" - label="Confirm Password" - type="password" - /> -
- - - - - )} -
-
- ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/registration-closed/page.tsx b/src/app/club/(user-handle)/registration-closed/page.tsx deleted file mode 100644 index 4788b0c..0000000 --- a/src/app/club/(user-handle)/registration-closed/page.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from "react"; -import { TbUserOff } from "react-icons/tb"; - -const Page = () => { - return ( -
-
- -

- REGISTRATION CLOSED -

-

- We regret to inform you that registration has now closed. We - appreciate your interest and would like to thank everyone who signed - up. Please stay tuned for future updates and opportunities to - participate.{" "} -

-
-
- ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/reset-password/page.tsx b/src/app/club/(user-handle)/reset-password/page.tsx deleted file mode 100644 index 823fc51..0000000 --- a/src/app/club/(user-handle)/reset-password/page.tsx +++ /dev/null @@ -1,122 +0,0 @@ -"use client"; - -import Field from "@/app/club/Components/Field"; -import React, { useEffect, useState } from "react"; -import Link from "next/link"; -import { auth, db } from "@/config/firebase"; - -import { - deleteUser, - sendEmailVerification, - sendPasswordResetEmail, - signInWithEmailAndPassword, -} from "firebase/auth"; - -import { toast } from "react-toastify"; -import { CgArrowLeft, CgSpinner } from "react-icons/cg"; -import { useRouter } from "next/navigation"; -import Image from "next/image"; -import { doc, DocumentReference, deleteDoc } from "firebase/firestore"; -import { useAuthState } from "react-firebase-hooks/auth"; - -const Page = () => { - const [email, setEmail] = useState(""); - const [loading, setLoading] = useState(false); - const [user] = useAuthState(auth); - const Router = useRouter(); - const handleSubmit = async (event: any) => { - event.preventDefault(); - setLoading(true); - sendPasswordResetEmail(auth, email) - .then(() => { - setLoading(false); - auth.signOut(); - toast.success( - "Reset password link sent to you email. Reset Password then login again.", - ); - Router.push("/club/login"); - }) - .catch((error) => { - switch (error.code) { - case "auth/email-already-in-use": - toast.error(`Email address already in use.`); - break; - case "auth/invalid-email": - toast.error(`Email address is invalid.`); - break; - case "auth/operation-not-allowed": - toast.error(`Error during sign up.`); - break; - default: - toast.error(error.message.replaceAll("Firebase: ", "")); - - break; - } - setLoading(false); - }); - }; - useEffect(() => { - if (user && user.email) { - setEmail(user.email); - } - }, [user]); - return ( -
-
-
-
- -
-

- PASSWORD RESET -

-

- Get password reset link to reset your password. Then login again. -

-
- setEmail(String(data))} - name="email" - label="E-mail" - type="email" - /> -
- -
-
-
- -
-
- ); -}; - -export default Page; diff --git a/src/app/club/(user-handle)/verify/page.tsx b/src/app/club/(user-handle)/verify/page.tsx deleted file mode 100644 index 17916c8..0000000 --- a/src/app/club/(user-handle)/verify/page.tsx +++ /dev/null @@ -1,150 +0,0 @@ -"use client"; - -import Field from "@/app/club/Components/Field"; -import React, { useEffect, useState } from "react"; -import Link from "next/link"; -import { auth, db } from "@/config/firebase"; - -import { - deleteUser, - reauthenticateWithPopup, - sendEmailVerification, - signInWithEmailAndPassword, -} from "firebase/auth"; - -import { toast } from "react-toastify"; -import { CgArrowLeft, CgArrowRight, CgSpinner } from "react-icons/cg"; -import { useRouter } from "next/navigation"; -import Image from "next/image"; -import { doc, DocumentReference, deleteDoc } from "firebase/firestore"; -import { useAuthState } from "react-firebase-hooks/auth"; - -const Page = () => { - const [loading, setLoading] = useState(false); - const [loading2, setLoading2] = useState(false); - const [user] = useAuthState(auth); - - const Router = useRouter(); - const handleSubmit = async (event: any) => { - event.preventDefault(); - setLoading(true); - if (user) { - try { - await sendEmailVerification(user); - toast.success("Verfication Email Sent! Verify and Login."); - } catch (err) { - console.error(err); - toast.error("Aww! Snap!"); - } - } else { - toast.error("User not signed in!"); - } - setLoading(false); - }; - const deleteAccount = async (event: any) => { - event.preventDefault(); - setLoading2(true); - try { - if (user) { - await deleteUser(user); - toast.info(`Please register again.`); - Router.push("/club/register"); - } - } catch (err: any) { - console.error(err); - if (err?.code === "auth/requires-recent-login") { - toast.error(`Login expired. Please register/login again.`); - auth.signOut(); - Router.push("/club/register"); - } else { - setLoading2(false); - toast.error("Aww! Snap!"); - } - } - }; - useEffect(() => { - if (user && user.emailVerified) { - Router.push("/club/profile"); - } else if (!user && !loading2) { - Router.push("/club/login"); - } - const x = setInterval(() => { - auth.currentUser?.reload(); - }, 3000); - - return () => { - clearInterval(x); - }; - }, [user, Router, loading2]); - return ( -
-
-
-

- ACCOUNT VERIFICATION -

-

- Please verify your account. An email has been sent to {user?.email}. - Don't forget to check you spam. -

-
-
- -
-
- -
-
- -
-
-
- -
-
- ); -}; - -export default Page; diff --git a/src/app/club/Components/Admin/AddQuestions.tsx b/src/app/club/Components/Admin/AddQuestions.tsx deleted file mode 100644 index a95f559..0000000 --- a/src/app/club/Components/Admin/AddQuestions.tsx +++ /dev/null @@ -1,598 +0,0 @@ -import { useEffect, useMemo, useState } from "react"; -import { FaPlus } from "react-icons/fa6"; -import { RiDeleteBin6Line } from "react-icons/ri"; -import { RxGear } from "react-icons/rx"; -import Markdown from "react-markdown"; -import { toast } from "react-toastify"; -import rehypeHighlight from "rehype-highlight"; -import rehypeKatex from "rehype-katex"; -import remarkGfm from "remark-gfm"; -import remarkMath from "remark-math"; -import "highlight.js/styles/atom-one-light.css"; -import "katex/dist/katex.min.css"; - -interface questionInterface { - mcq: boolean; - question: string; - option0: string; - option1: string; - option2: string; - option3: string; - point: number; - index: number; - correctOption: number; - correctAnswers: string; - onValueChange?: ( - i: number, - question: string, - point: number, - option0: string, - option1: string, - option2: string, - option3: string, - correctOption: number, - correctAnswers: string, - ) => void; - deleteQuestion?: (index: number) => void; -} - -interface answerInterface { - mcq: boolean; - point: number; - correctOption: number; - correctAnswers: string; -} - -const AddQuestions = ({ - questionsData, - answersData, - setData, - setQues, - setAns, -}: { - questionsData: any[]; - answersData: any[]; - setData: (questionData: any, answerData: any) => void; - setQues?: (s: any) => void; - setAns?: (s: any) => void; -}) => { - const [questions, setQuestions] = useState([]); - const [answers, setAnswers] = useState([]); - - useEffect(() => { - setAnswers(answersData); - setQuestions(questionsData); - }, [questionsData, answersData]); - - const [isMCQ, setMCQ] = useState(true); - - const optionsArr = ["A", "B", "C", "D"]; - - const [question, setQuestion] = useState(""); - const [option0, setOption0] = useState(""); - const [option1, setOption1] = useState(""); - const [option2, setOption2] = useState(""); - const [option3, setOption3] = useState(""); - const [correctOption, setCorrectOption] = useState(0); - const [correctAnswers, setCorrectAnswers] = useState(""); - - const [point, setPoint] = useState(1); - - const setOption = (i: number, value: string) => { - switch (i) { - case 0: - setOption0(value); - break; - - case 1: - setOption1(value); - break; - - case 2: - setOption2(value); - break; - - case 3: - setOption3(value); - break; - - default: - break; - } - }; - - const addQuestion = () => { - setQuestions((oldValue: any) => { - let sqd = [ - ...oldValue, - { - question: question, - mcq: isMCQ, - point: point, - option0: option0, - option1: option1, - option2: option2, - option3: option3, - }, - ]; - setQues && setQues(sqd); - return sqd; - }); - - setAnswers((oldValue: any) => { - let sad = [ - ...oldValue, - { - mcq: isMCQ, - point: point, - correctOption: correctOption, - correctAnswers: correctAnswers, - }, - ]; - - setAns && setAns(sad); - - return sad; - }); - - setQuestion(""); - setOption0(""); - setOption1(""); - setOption2(""); - setOption3(""); - setCorrectOption(0); - setCorrectAnswers(""); - setPoint(1); - - toast.success("Question Added"); - }; - - const onValueChange = ( - i: number, - question: string, - point: number, - option0: string, - option1: string, - option2: string, - option3: string, - correctOption: number, - correctAnswers: string, - ) => { - let arr = [...questions]; - arr[i].question = question; - arr[i].point = point; - arr[i].option0 = option0; - arr[i].option1 = option1; - arr[i].option2 = option2; - arr[i].option3 = option3; - - setQuestions(arr); - - let ansArr = [...answers]; - - ansArr[i].point = point; - ansArr[i].correctOption = correctOption; - ansArr[i].correctAnswers = correctAnswers; - - setAnswers(ansArr); - }; - - const deleteQuestion = (i: number) => { - setQuestions((arr) => { - let a = [...arr.slice(0, i), ...arr.slice(i + 1, arr.length)]; - setQues && setQues(a); - return a; - }); - - setAnswers((arr) => { - let a = [...arr.slice(0, i), ...arr.slice(i + 1, arr.length)]; - setAns && setAns(a); - return a; - }); - }; - - const modifiedText = useMemo(() => { - const lines = (question || "").split("\n"); - - return lines - .map((line, index) => { - // Check if the line is part of a list - const isListItem = /^\s*[*\-+]\s+|^\s*\d+\.\s+/.test(line); - const isNextLineListItem = - index < lines.length - 1 && - /^\s*[*\-+]\s+|^\s*\d+\.\s+/.test(lines[index + 1]); - - if (isListItem || isNextLineListItem) return line; - - return line + "\n"; - }) - .join("\n"); - }, [question]); - - return ( -
-
- --- Questions --- -
- -
- {questions.length != 0 && - answers.length != 0 && - questions.map((e, i) => { - return ( - - ); - })} -
- -
- --- New Question --- -
- -
-
- -