new feature in quiz page

This commit is contained in:
Atash03 2025-04-14 16:14:44 +05:00
parent b059d2afd6
commit 875620b64e
3 changed files with 64 additions and 3 deletions

View File

@ -29,6 +29,8 @@ const page = ({ params }: IParams) => {
const { step, setStep } = useSteps();
useEffect(() => {
const local_info = sessionStorage.getItem("TURKMENTV_QUIZ_INFO");
if (!params.quiz_id) {
Queries.getQuizQuestions().then((res) => {
setData(res);
@ -39,7 +41,18 @@ const page = ({ params }: IParams) => {
: setQuizFinished(true)
);
} else if (res.data.steps && res.data.steps?.length > 0) {
if (local_info) {
if (
JSON.parse(local_info)?.tab &&
JSON.parse(local_info)?.uuid === res.data.uuid
) {
setStep(JSON.parse(local_info)?.tab);
} else {
setStep(res.data.steps[res.data.steps.length - 1].tapgyr);
}
} else {
setStep(res.data.steps[res.data.steps.length - 1].tapgyr);
}
for (let i = 0; i < res.data.steps.length; i++) {
res.data.steps[i].questions.map((question) =>
question.status === "active" || question.status === "new"
@ -59,7 +72,18 @@ const page = ({ params }: IParams) => {
: setQuizFinished(true)
);
} else if (res.data.steps && res.data.steps?.length > 0) {
if (local_info) {
if (
JSON.parse(local_info)?.tab &&
JSON.parse(local_info)?.uuid === res.data.uuid
) {
setStep(JSON.parse(local_info)?.tab);
} else {
setStep(res.data.steps[res.data.steps.length - 1].tapgyr);
}
} else {
setStep(res.data.steps[res.data.steps.length - 1].tapgyr);
}
for (let i = 0; i < res.data.steps.length; i++) {
res.data.steps[i].questions.map((question) =>
question.status === "active" || question.status === "new"
@ -72,6 +96,18 @@ const page = ({ params }: IParams) => {
}
}, []);
useEffect(() => {
if (data) {
sessionStorage.setItem(
"TURKMENTV_QUIZ_INFO",
JSON.stringify({
uuid: data.data.uuid,
tab: step,
})
);
}
}, [data, step]);
const mobile = useMediaQuery("(max-width: 768px)");
if (data) {

View File

@ -23,14 +23,26 @@ const Page = ({ params }: IParams) => {
const { resultData, error } = useQuizResults();
useEffect(() => {
const local_info = sessionStorage.getItem("TURKMENTV_QUIZ_RESULTS");
if (!resultData.length && !error) {
setLoading(true);
Queries.getQuizById(params.quiz_id)
.then((res) => {
setData(res.data);
if (res.data.steps?.length) {
if (local_info) {
if (
JSON.parse(local_info)?.tab &&
JSON.parse(local_info)?.uuid === res.data.uuid
) {
setTab(JSON.parse(local_info)?.tab);
} else {
setTab(res.data?.steps[res.data?.steps.length - 1].tapgyr - 1);
}
} else {
setTab(res.data?.steps[res.data?.steps.length - 1].tapgyr - 1);
}
}
setLoading(false);
})
.catch(() => {
@ -40,6 +52,18 @@ const Page = ({ params }: IParams) => {
}
}, [resultData, error]);
useEffect(() => {
if (data) {
sessionStorage.setItem(
"TURKMENTV_QUIZ_RESULTS",
JSON.stringify({
uuid: data?.uuid,
tab: tab,
})
);
}
}, [data, tab]);
return (
<section className="container py-[40px]">
<div className="flex flex-col w-full py-[40px] gap-[80px]">

View File

@ -5,6 +5,7 @@ export interface IQuizQuestions {
export interface Data {
id: number;
uuid?: number;
title: string;
date: string;
banner: string;