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