frontAnswerer/src/App.tsx

43 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Box } from "@mui/material";
import { startTransition, useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import { QuizIdContext } from "@contexts/QuizIdContext";
import { RootContainerWidthContext } from "@contexts/RootContainerWidthContext";
import QuizAnswerer from "../lib/components/QuizAnswerer";
2023-12-16 14:55:56 +00:00
2024-02-12 14:34:29 +00:00
const defaultQuizId = "ad7f5a87-b833-4f5b-854e-453706ed655c"; // branching
//const defaultQuizId = "ad7f5a87-b833-4f5b-854e-453706ed655c"; //looooong header
// const defaultQuizId = "a9d31460-132a-4479-a3f0-90241498b6f9"; // linear
export default function App() {
const quizId = useParams().quizId ?? defaultQuizId;
const [rootContainerSize, setRootContainerSize] = useState<number>(() => window.innerWidth);
2024-02-12 14:34:29 +00:00
useEffect(() => {
const handleWindowResize = () => {
startTransition(() => {
setRootContainerSize(window.innerWidth);
});
};
window.addEventListener("resize", handleWindowResize);
2024-02-12 14:34:29 +00:00
return () => {
window.removeEventListener("resize", handleWindowResize);
};
}, []);
2023-12-16 14:55:56 +00:00
2024-02-12 14:34:29 +00:00
return (
<RootContainerWidthContext.Provider value={rootContainerSize}>
<QuizIdContext.Provider value={quizId}>
<Box
sx={{
height: "100dvh",
}}
>
<QuizAnswerer />
</Box>
</QuizIdContext.Provider>
</RootContainerWidthContext.Provider>
);
2023-12-16 14:55:56 +00:00
}