2024-02-14 11:03:35 +00:00
|
|
|
import { getQuizData } from "@api/quizRelase";
|
|
|
|
import { RootContainerWidthContext } from "@contexts/RootContainerWidthContext";
|
2024-02-01 13:18:16 +00:00
|
|
|
import { Box } from "@mui/material";
|
2024-02-14 11:03:35 +00:00
|
|
|
import LoadingSkeleton from "@ui_kit/LoadingSkeleton";
|
2024-02-08 13:42:31 +00:00
|
|
|
import { startTransition, useEffect, useState } from "react";
|
2024-02-01 13:18:16 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
2024-02-14 11:03:35 +00:00
|
|
|
import useSWR from "swr";
|
2024-02-12 10:58:51 +00:00
|
|
|
import QuizAnswerer from "../lib/components/QuizAnswerer";
|
2024-02-14 11:03:35 +00:00
|
|
|
import { ApologyPage } from "../lib/components/ViewPublicationPage/ApologyPage";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-02-15 01:20:35 +00:00
|
|
|
//const defaultQuizId = "0c568ac9-d176-491b-b6cd-5afd31254951"; // branching
|
|
|
|
const defaultQuizId = "d7c940fe-1e44-41a0-bbac-5f304c51a1e4"; //looooong header
|
2024-02-13 15:57:42 +00:00
|
|
|
// const defaultQuizId = "ad7f5a87-b833-4f5b-854e-453706ed655c"; // linear
|
2024-01-31 14:39:50 +00:00
|
|
|
|
2024-02-01 13:18:16 +00:00
|
|
|
export default function App() {
|
2024-02-14 11:03:35 +00:00
|
|
|
const quizId = useParams().quizId ?? defaultQuizId;
|
|
|
|
const [rootContainerSize, setRootContainerSize] = useState<number>(() => window.innerWidth);
|
|
|
|
const { data, error, isLoading } = useSWR(["quizData", quizId], params => getQuizData(params[1]), {
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
revalidateOnReconnect: false,
|
|
|
|
shouldRetryOnError: false,
|
|
|
|
refreshInterval: 0,
|
|
|
|
});
|
2024-02-05 10:10:02 +00:00
|
|
|
|
2024-02-14 19:26:03 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const handleWindowResize = () => {
|
|
|
|
startTransition(() => {
|
|
|
|
setRootContainerSize(window.innerWidth);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
window.addEventListener("resize", handleWindowResize);
|
2024-02-05 10:10:02 +00:00
|
|
|
|
2024-02-14 11:03:35 +00:00
|
|
|
return () => {
|
|
|
|
window.removeEventListener("resize", handleWindowResize);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (isLoading) return <LoadingSkeleton />;
|
2024-02-14 19:26:03 +00:00
|
|
|
if (error) return <ApologyPage error={error} />;
|
|
|
|
if (!data) throw new Error("Quiz data is null");
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-02-14 11:03:35 +00:00
|
|
|
return (
|
|
|
|
<RootContainerWidthContext.Provider value={rootContainerSize}>
|
|
|
|
<Box sx={{
|
|
|
|
height: "100dvh",
|
|
|
|
}}>
|
|
|
|
<QuizAnswerer quizSettings={data} quizId={quizId} />
|
|
|
|
</Box>
|
|
|
|
</RootContainerWidthContext.Provider>
|
|
|
|
);
|
2023-12-16 14:55:56 +00:00
|
|
|
}
|