47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { Box, Skeleton } from "@mui/material";
|
|
|
|
import { StartPageViewPublication } from "./StartPageViewPublication";
|
|
import { Question } from "./Question";
|
|
import { ApologyPage } from "./ApologyPage"
|
|
|
|
import { useQuestionsStore } from "@root/quizData/store"
|
|
|
|
import type { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
|
|
|
export const ViewPage = () => {
|
|
const { settings, cnt, items } = useQuestionsStore()
|
|
|
|
const [visualStartPage, setVisualStartPage] = useState<boolean>();
|
|
|
|
useEffect(() => {
|
|
|
|
const link = document.querySelector('link[rel="icon"]');
|
|
if (link && settings.cfg.startpage.favIcon) {
|
|
link.setAttribute("href", settings.cfg.startpage.favIcon);
|
|
}
|
|
|
|
setVisualStartPage(!settings.cfg.noStartPage);
|
|
}, [settings]);
|
|
|
|
|
|
|
|
const filteredQuestions = (
|
|
items.filter(({ type }) => type) as AnyTypedQuizQuestion[]
|
|
).sort((previousItem, item) => previousItem.page - item.page);
|
|
|
|
|
|
if (visualStartPage === undefined) return <Skeleton sx={{ bgcolor: 'grey', width: "100vw", height: "100vh" }} variant="rectangular" />;
|
|
if (cnt === 0) return <ApologyPage message="Нет созданных вопросов" />
|
|
return (
|
|
<Box>
|
|
{
|
|
visualStartPage ?
|
|
<StartPageViewPublication setVisualStartPage={setVisualStartPage} />
|
|
:
|
|
<Question questions={filteredQuestions} />
|
|
}
|
|
</Box>
|
|
);
|
|
};
|