2024-02-01 13:18:16 +00:00
|
|
|
import { Box } from "@mui/material";
|
2024-02-08 13:42:31 +00:00
|
|
|
import { startTransition, useEffect, useRef, useState } from "react";
|
2024-02-02 14:35:02 +00:00
|
|
|
import QuizAnswerer from "./QuizAnswerer";
|
2024-02-01 19:14:27 +00:00
|
|
|
import { QuizIdContext } from "./contexts/QuizIdContext";
|
2024-02-05 10:10:02 +00:00
|
|
|
import { RootContainerWidthContext } from "./contexts/RootContainerWidthContext";
|
2024-02-01 13:18:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
quizId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function WidgetApp({ quizId }: Props) {
|
2024-02-08 13:42:31 +00:00
|
|
|
const [rootContainerSize, setRootContainerSize] = useState<number>(() => window.innerWidth);
|
2024-02-05 10:10:02 +00:00
|
|
|
const rootContainerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const handleWindowResize = () => {
|
2024-02-08 13:42:31 +00:00
|
|
|
startTransition(() => {
|
|
|
|
if (rootContainerRef.current) setRootContainerSize(rootContainerRef.current.clientWidth);
|
|
|
|
});
|
2024-02-05 10:10:02 +00:00
|
|
|
};
|
|
|
|
window.addEventListener("resize", handleWindowResize);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener("resize", handleWindowResize);
|
|
|
|
};
|
|
|
|
}, []);
|
2024-02-01 13:18:16 +00:00
|
|
|
|
|
|
|
return (
|
2024-02-05 10:10:02 +00:00
|
|
|
<RootContainerWidthContext.Provider value={rootContainerSize}>
|
|
|
|
<QuizIdContext.Provider value={quizId}>
|
|
|
|
<Box
|
|
|
|
ref={rootContainerRef}
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<QuizAnswerer />
|
|
|
|
</Box>
|
|
|
|
</QuizIdContext.Provider>
|
|
|
|
</RootContainerWidthContext.Provider>
|
2024-02-01 13:18:16 +00:00
|
|
|
);
|
|
|
|
}
|