Skip to content

Commit

Permalink
Merge pull request #51 from nditc/rafsan
Browse files Browse the repository at this point in the history
run
  • Loading branch information
RafsanAmin authored Oct 12, 2024
2 parents 4d1b841 + 9ee8ebc commit 0f63593
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 57 deletions.
17 changes: 6 additions & 11 deletions src/app/club/Components/Admin/AddQuestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/app/club/Components/Home/DamianPopUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DamianPopUp = () => {
const [roll, setRoll] = useState("");

useEffect(() => {
if (!userDataLoading && !userData?.ndc_roll) {
if (!userDataLoading && !userData?.ndc_roll && userAuth) {
onOpen();
}
}, [userData, userDataLoading]);
Expand Down
27 changes: 25 additions & 2 deletions src/app/club/Components/Participate/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -71,7 +73,7 @@ const Question = ({

return (
<div className="flex w-full flex-col rounded-xl bg-white p-5">
<div className="flex items-center justify-between pb-3 text-base md:text-lg">
<div className="flex max-w-full items-center justify-between overflow-x-scroll pb-3 text-base md:text-lg">
<div className="flex flex-col items-start gap-2 font-medium leading-[1.3] sm:flex-row">
<p className="Inter grid h-9 w-9 shrink-0 place-items-center rounded-full bg-primary text-white">
{index + 1}
Expand Down Expand Up @@ -114,12 +116,33 @@ const Question = ({
<input
className="h-16 rounded-xl border border-gray-300 px-5 py-3 focus:border-primary focus:outline-none"
onChange={(e) => {
setAnswerData(selectedVal, e.target.value, index);
setAnswer(e.target.value);
}}
value={answer}
name="answer"
placeholder="Your Answer ..."
/>
<div className="flex items-center justify-between">
<div className="ml-2 mt-2 text-sm text-gray-600">
{savedOnce ? (
<i>
<b>Saved as:</b> {givenAnswer}
</i>
) : (
<i>Not Saved Once</i>
)}
</div>
<button
className="mt-3 rounded-xl bg-primary px-5 py-3 text-white transition hover:opacity-85 active:scale-95"
onClick={() => {
setAnswerData(selectedVal, answer, index);
toast.info("Saved Response!");
setSavedOnce(true);
}}
>
Save
</button>
</div>
</div>
</div>
)}
Expand Down
94 changes: 51 additions & 43 deletions src/app/club/admin/eventEdit/[eventID]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>();
Expand Down Expand Up @@ -680,28 +671,30 @@ const Page = ({ params }: { params: { eventID: string } }) => {
) : null}
</Modal>
<InfoBox icon={<CiWarning />} 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.
</InfoBox>
<div className="flex items-stretch justify-between gap-5">
<div className="flex flex-col items-stretch justify-between gap-5 lg:flex-row">
<div className="flex h-full w-full py-3 md:w-auto md:py-0">
{params.eventID != "new" && (
<Link
href={`/club/admin/rankers/${publicQuiz ? "public" : eventUID}`}
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
</Link>
)}
</div>

<div className="flex flex-wrap items-center justify-end gap-5">
<div className="flex flex-col items-stretch justify-end gap-5 lg:flex-row">
{loading ? (
<CgSpinner className="mx-auto h-9 w-9 animate-spin justify-self-end text-primary" />
) : null}
Expand All @@ -724,6 +717,21 @@ const Page = ({ params }: { params: { eventID: string } }) => {
</button>
</div>

<div className="w-full justify-self-end py-3 md:w-auto md:py-0">
<button
style={{
pointerEvents: loading ? "none" : "auto",
opacity: loading ? "0.65" : "1",
}}
className="w-full rounded-xl bg-primary px-8 py-2 text-lg text-white transition-all hover:bg-secondary_light hover:text-primary"
onClick={save}
type="button"
>
<div className="flex items-center justify-center gap-3">
Save Local
</div>
</button>
</div>
<div className="w-full justify-self-end py-3 md:w-auto md:py-0">
<button
style={{
Expand Down

0 comments on commit 0f63593

Please sign in to comment.