2024-06-22 15:35:11 +00:00
|
|
|
|
import { ContactForm } from "@/components/ViewPublicationPage/ContactForm/ContactForm.tsx";
|
|
|
|
|
import { extractImageLinksFromQuestion } from "@/utils/extractImageLinks";
|
|
|
|
|
import { useVKMetrics } from "@/utils/hooks/metrics/useVKMetrics";
|
|
|
|
|
import { useYandexMetrics } from "@/utils/hooks/metrics/useYandexMetrics";
|
2024-06-29 09:32:16 +00:00
|
|
|
|
import { sendQuestionAnswer } from "@/utils/sendQuestionAnswer";
|
2024-05-06 13:47:19 +00:00
|
|
|
|
import { ThemeProvider, Typography } from "@mui/material";
|
|
|
|
|
import { useQuizViewStore } from "@stores/quizView";
|
|
|
|
|
import { useQuestionFlowControl } from "@utils/hooks/useQuestionFlowControl";
|
|
|
|
|
import { notReachable } from "@utils/notReachable";
|
|
|
|
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import { ReactElement, useEffect } from "react";
|
2024-06-25 12:54:17 +00:00
|
|
|
|
import { Helmet } from "react-helmet-async";
|
2024-05-06 13:47:19 +00:00
|
|
|
|
import { Question } from "./Question";
|
2024-06-22 15:35:11 +00:00
|
|
|
|
import QuestionSelect from "./QuestionSelect";
|
2024-05-06 13:47:19 +00:00
|
|
|
|
import { ResultForm } from "./ResultForm";
|
|
|
|
|
import { StartPageViewPublication } from "./StartPageViewPublication";
|
2024-03-26 00:06:54 +00:00
|
|
|
|
import NextButton from "./tools/NextButton";
|
2024-04-02 13:09:13 +00:00
|
|
|
|
import PrevButton from "./tools/PrevButton";
|
2024-12-22 11:49:56 +00:00
|
|
|
|
import unscreen from "@/ui_kit/unscreen";
|
2025-05-01 13:15:54 +00:00
|
|
|
|
import { useQuizStore } from "@/stores/useQuizStore";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
2024-02-08 13:42:31 +00:00
|
|
|
|
export default function ViewPublicationPage() {
|
2025-05-01 13:15:54 +00:00
|
|
|
|
const { settings, recentlyCompleted, quizId, preview, changeFaviconAndTitle } = useQuizStore();
|
2024-04-22 08:55:19 +00:00
|
|
|
|
const answers = useQuizViewStore((state) => state.answers);
|
2024-09-12 08:43:50 +00:00
|
|
|
|
const ownVariants = useQuizViewStore((state) => state.ownVariants);
|
2024-04-22 08:55:19 +00:00
|
|
|
|
let currentQuizStep = useQuizViewStore((state) => state.currentQuizStep);
|
|
|
|
|
const {
|
|
|
|
|
currentQuestion,
|
|
|
|
|
currentQuestionStepNumber,
|
2024-06-22 15:35:11 +00:00
|
|
|
|
nextQuestion,
|
2024-04-22 08:55:19 +00:00
|
|
|
|
isNextButtonEnabled,
|
|
|
|
|
isPreviousButtonEnabled,
|
|
|
|
|
moveToPrevQuestion,
|
|
|
|
|
moveToNextQuestion,
|
|
|
|
|
showResultAfterContactForm,
|
|
|
|
|
setQuestion,
|
|
|
|
|
} = useQuestionFlowControl();
|
2024-07-17 00:49:56 +00:00
|
|
|
|
useYandexMetrics(settings?.cfg?.yandexMetricsNumber, preview);
|
|
|
|
|
useVKMetrics(settings?.cfg?.vkMetricsNumber, preview);
|
2024-01-30 16:49:33 +00:00
|
|
|
|
|
2024-12-22 11:49:56 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
const root = document.getElementById("root");
|
|
|
|
|
const overlay = document.getElementById("hideoverlay");
|
|
|
|
|
|
2025-01-08 17:27:44 +00:00
|
|
|
|
if (!settings.cfg?.isUnSc) overlay?.remove();
|
|
|
|
|
|
2024-12-22 11:49:56 +00:00
|
|
|
|
if (root !== null && overlay !== null && settings.cfg?.isUnSc) {
|
|
|
|
|
unscreen(overlay, root);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
2024-04-22 08:55:19 +00:00
|
|
|
|
useEffect(
|
|
|
|
|
function setFaviconAndTitle() {
|
|
|
|
|
if (!changeFaviconAndTitle) return;
|
2024-04-18 15:23:27 +00:00
|
|
|
|
|
2024-04-22 08:55:19 +00:00
|
|
|
|
const link = document.querySelector('link[rel="icon"]');
|
|
|
|
|
if (link && settings.cfg.startpage.favIcon) {
|
|
|
|
|
link.setAttribute("href", settings.cfg.startpage.favIcon);
|
|
|
|
|
}
|
2024-02-02 14:35:02 +00:00
|
|
|
|
|
2024-04-22 08:55:19 +00:00
|
|
|
|
document.title = settings.name;
|
|
|
|
|
},
|
|
|
|
|
[changeFaviconAndTitle, settings.cfg.startpage.favIcon, settings.name]
|
|
|
|
|
);
|
2024-04-06 14:01:04 +00:00
|
|
|
|
|
2024-05-31 17:56:17 +00:00
|
|
|
|
if (settings.cfg.antifraud && recentlyCompleted) throw new Error("Quiz already completed");
|
2024-05-31 16:41:18 +00:00
|
|
|
|
if (currentQuizStep === "startpage" && settings.cfg.noStartPage) currentQuizStep = "question";
|
2024-01-15 17:41:15 +00:00
|
|
|
|
|
2024-04-22 08:55:19 +00:00
|
|
|
|
if (!currentQuestion)
|
|
|
|
|
return (
|
2024-05-31 16:41:18 +00:00
|
|
|
|
<ThemeProvider theme={quizThemes[settings.cfg.theme || "StandardTheme"].theme}>
|
2024-06-22 15:35:11 +00:00
|
|
|
|
<Typography
|
|
|
|
|
textAlign={"center"}
|
|
|
|
|
mt="50px"
|
|
|
|
|
>
|
2024-04-22 08:55:19 +00:00
|
|
|
|
Вопрос не выбран
|
|
|
|
|
</Typography>
|
|
|
|
|
</ThemeProvider>
|
2024-04-12 11:29:37 +00:00
|
|
|
|
);
|
2024-02-14 11:03:35 +00:00
|
|
|
|
|
2024-06-29 09:32:16 +00:00
|
|
|
|
const currentAnswer = answers.find(({ questionId }) => questionId === currentQuestion.id);
|
|
|
|
|
|
2024-04-22 08:55:19 +00:00
|
|
|
|
let quizStepElement: ReactElement;
|
|
|
|
|
switch (currentQuizStep) {
|
|
|
|
|
case "startpage": {
|
|
|
|
|
quizStepElement = <StartPageViewPublication />;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case "question": {
|
|
|
|
|
if (currentQuestion.type === "result") {
|
|
|
|
|
quizStepElement = <ResultForm resultQuestion={currentQuestion} />;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-02-08 13:42:31 +00:00
|
|
|
|
|
2024-04-22 08:55:19 +00:00
|
|
|
|
quizStepElement = (
|
|
|
|
|
<Question
|
2024-05-07 14:44:51 +00:00
|
|
|
|
key={currentQuestion.id}
|
2024-04-22 08:55:19 +00:00
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
currentQuestionStepNumber={currentQuestionStepNumber}
|
|
|
|
|
prevButton={
|
2024-06-22 15:35:11 +00:00
|
|
|
|
<PrevButton
|
|
|
|
|
isPreviousButtonEnabled={isPreviousButtonEnabled}
|
|
|
|
|
moveToPrevQuestion={moveToPrevQuestion}
|
|
|
|
|
/>
|
2024-04-22 08:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
nextButton={
|
|
|
|
|
<NextButton
|
2025-04-22 19:29:34 +00:00
|
|
|
|
isNextButtonEnabled={settings.status === "ai" || isNextButtonEnabled}
|
2025-05-01 13:23:10 +00:00
|
|
|
|
moveToNextQuestion={async () => {
|
|
|
|
|
if (!preview) {
|
|
|
|
|
await sendQuestionAnswer(quizId, currentQuestion, currentAnswer, ownVariants)?.catch((e) => {
|
|
|
|
|
enqueueSnackbar("Ошибка при отправке ответа");
|
|
|
|
|
console.error("Error sending answer", e);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-22 08:55:19 +00:00
|
|
|
|
moveToNextQuestion();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
}
|
2024-06-22 15:35:11 +00:00
|
|
|
|
questionSelect={
|
|
|
|
|
<QuestionSelect
|
|
|
|
|
selectedQuestion={currentQuestion}
|
|
|
|
|
setQuestion={setQuestion}
|
|
|
|
|
/>
|
|
|
|
|
}
|
2024-04-22 08:55:19 +00:00
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
break;
|
2024-02-08 13:42:31 +00:00
|
|
|
|
}
|
2024-04-22 08:55:19 +00:00
|
|
|
|
case "contactform": {
|
2024-06-22 15:35:11 +00:00
|
|
|
|
quizStepElement = (
|
|
|
|
|
<ContactForm
|
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
|
onShowResult={showResultAfterContactForm}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2024-04-22 08:55:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
notReachable(currentQuizStep);
|
|
|
|
|
}
|
2024-01-30 16:49:33 +00:00
|
|
|
|
|
2024-06-22 15:35:11 +00:00
|
|
|
|
const preloadLinks = new Set([
|
|
|
|
|
...extractImageLinksFromQuestion(currentQuestion),
|
|
|
|
|
...extractImageLinksFromQuestion(nextQuestion),
|
|
|
|
|
]);
|
|
|
|
|
|
2024-04-22 08:55:19 +00:00
|
|
|
|
return (
|
2024-06-22 15:35:11 +00:00
|
|
|
|
<ThemeProvider theme={quizThemes[settings.cfg.theme || "StandardTheme"].theme}>
|
|
|
|
|
<Helmet>
|
|
|
|
|
{Array.from(preloadLinks).map((link) => (
|
|
|
|
|
<link
|
|
|
|
|
key={link}
|
|
|
|
|
rel="preload"
|
|
|
|
|
as="image"
|
|
|
|
|
href={link}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</Helmet>
|
|
|
|
|
{quizStepElement}
|
|
|
|
|
</ThemeProvider>
|
2024-04-22 08:55:19 +00:00
|
|
|
|
);
|
2024-02-28 14:10:50 +00:00
|
|
|
|
}
|