2024-01-30 16:49:33 +00:00
|
|
|
import { Box, useMediaQuery, useTheme } from "@mui/material";
|
|
|
|
import { useEffect, useState } from "react";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
import { ContactForm } from "./ContactForm";
|
|
|
|
import { Footer } from "./Footer";
|
|
|
|
import { ResultForm } from "./ResultForm";
|
2023-12-16 14:55:56 +00:00
|
|
|
import { Date } from "./questions/Date";
|
2024-01-30 16:49:33 +00:00
|
|
|
import { Emoji } from "./questions/Emoji";
|
2023-12-16 14:55:56 +00:00
|
|
|
import { File } from "./questions/File";
|
2024-01-30 16:49:33 +00:00
|
|
|
import { Images } from "./questions/Images";
|
|
|
|
import { Number } from "./questions/Number";
|
2023-12-16 14:55:56 +00:00
|
|
|
import { Page } from "./questions/Page";
|
|
|
|
import { Rating } from "./questions/Rating";
|
2024-01-30 16:49:33 +00:00
|
|
|
import { Select } from "./questions/Select";
|
|
|
|
import { Text } from "./questions/Text";
|
|
|
|
import { Variant } from "./questions/Variant";
|
|
|
|
import { Varimg } from "./questions/Varimg";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
|
|
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
import { NameplateLogoFQ } from "@icons/NameplateLogoFQ";
|
|
|
|
import { NameplateLogoFQDark } from "@icons/NameplateLogoFQDark";
|
|
|
|
import { QuizQuestionResult } from "@model/questionTypes/result";
|
|
|
|
import { notReachable } from "@utils/notReachable";
|
|
|
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
2024-02-02 14:35:02 +00:00
|
|
|
import { useQuizData } from "@utils/hooks/useQuizData";
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
export const Question = () => {
|
|
|
|
const theme = useTheme();
|
2024-02-02 14:35:02 +00:00
|
|
|
const { settings, questions } = useQuizData();
|
2024-01-30 16:49:33 +00:00
|
|
|
const [currentQuestion, setCurrentQuestion] = useState<AnyTypedQuizQuestion>();
|
|
|
|
const [showContactForm, setShowContactForm] = useState<boolean>(false);
|
|
|
|
const [showResultForm, setShowResultForm] = useState<boolean>(false);
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(650));
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (settings?.cfg.haveRoot) {//ветвимся
|
2024-02-02 14:35:02 +00:00
|
|
|
const questionId = settings?.cfg.haveRoot || "";
|
|
|
|
const nextQuestion = questions.find(q => q.id === questionId || q.content.id === questionId) || null;
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
if (nextQuestion?.type) {
|
|
|
|
setCurrentQuestion(nextQuestion);
|
|
|
|
return;
|
|
|
|
}
|
2023-12-16 14:55:56 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
} else {//идём прямо
|
|
|
|
setCurrentQuestion(questions[0]);
|
|
|
|
}
|
|
|
|
}, []);
|
2024-01-05 21:15:59 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
if (!currentQuestion || currentQuestion.type === "result") return "не смог отобразить вопрос";
|
2023-12-29 00:58:19 +00:00
|
|
|
|
2024-01-30 16:49:33 +00:00
|
|
|
return (
|
2023-12-17 13:22:21 +00:00
|
|
|
<Box
|
2024-01-30 16:49:33 +00:00
|
|
|
sx={{
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
height: isMobile ? undefined : "100vh"
|
|
|
|
}}
|
2023-12-17 13:22:21 +00:00
|
|
|
>
|
2024-01-30 16:49:33 +00:00
|
|
|
{!showContactForm && !showResultForm && (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
height: "calc(100vh - 75px)",
|
|
|
|
width: "100%",
|
|
|
|
maxWidth: "1440px",
|
|
|
|
padding: "40px 25px 20px",
|
|
|
|
margin: "0 auto",
|
|
|
|
overflow: "auto",
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "column",
|
|
|
|
justifyContent: "space-between"
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<QuestionByType question={currentQuestion} />
|
|
|
|
{quizThemes[settings.cfg.theme].isLight ? (
|
|
|
|
<NameplateLogoFQ style={{ fontSize: "34px", width: "200px", height: "auto" }} />
|
|
|
|
) : (
|
|
|
|
<NameplateLogoFQDark style={{ fontSize: "34px", width: "200px", height: "auto" }} />
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
{showResultForm && settings?.cfg.resultInfo.showResultForm === "before" && (
|
|
|
|
<ResultForm
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
showContactForm={showContactForm}
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{showContactForm && (
|
|
|
|
<ContactForm
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
showResultForm={showResultForm}
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{showResultForm && settings?.cfg.resultInfo.showResultForm === "after" && (
|
|
|
|
<ResultForm
|
|
|
|
currentQuestion={currentQuestion}
|
|
|
|
showContactForm={showContactForm}
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{!showContactForm && !showResultForm && (
|
|
|
|
<Footer
|
|
|
|
question={currentQuestion}
|
|
|
|
setCurrentQuestion={setCurrentQuestion}
|
|
|
|
setShowContactForm={setShowContactForm}
|
|
|
|
setShowResultForm={setShowResultForm}
|
|
|
|
/>
|
|
|
|
)}
|
2023-12-17 13:22:21 +00:00
|
|
|
</Box>
|
2024-01-30 16:49:33 +00:00
|
|
|
);
|
2023-12-16 14:55:56 +00:00
|
|
|
};
|
2024-01-30 16:49:33 +00:00
|
|
|
|
|
|
|
function QuestionByType({ question }: {
|
|
|
|
question: Exclude<AnyTypedQuizQuestion, QuizQuestionResult>;
|
|
|
|
}) {
|
|
|
|
switch (question.type) {
|
|
|
|
case "variant": return <Variant currentQuestion={question} />;
|
|
|
|
case "images": return <Images currentQuestion={question} />;
|
|
|
|
case "varimg": return <Varimg currentQuestion={question} />;
|
|
|
|
case "emoji": return <Emoji currentQuestion={question} />;
|
|
|
|
case "text": return <Text currentQuestion={question} />;
|
|
|
|
case "select": return <Select currentQuestion={question} />;
|
|
|
|
case "date": return <Date currentQuestion={question} />;
|
|
|
|
case "number": return <Number currentQuestion={question} />;
|
|
|
|
case "file": return <File currentQuestion={question} />;
|
|
|
|
case "page": return <Page currentQuestion={question} />;
|
|
|
|
case "rating": return <Rating currentQuestion={question} />;
|
|
|
|
default: return notReachable(question);
|
|
|
|
}
|
|
|
|
}
|