import { Box, Button, LinearProgress, Paper, Typography, FormControl, Select as MuiSelect, MenuItem, useTheme, } from "@mui/material"; import { useQuestionsStore } from "@root/questions/store"; import { decrementCurrentQuestionIndex, incrementCurrentQuestionIndex, useQuizPreviewStore, setCurrentQuestionIndex, } from "@root/quizPreview"; import { AnyTypedQuizQuestion, UntypedQuizQuestion } from "model/questionTypes/shared"; import {useEffect, useRef, useState} from "react"; import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft"; import Date from "./QuizPreviewQuestionTypes/Date"; import Emoji from "./QuizPreviewQuestionTypes/Emoji"; import File from "./QuizPreviewQuestionTypes/File"; import Images from "./QuizPreviewQuestionTypes/Images"; import Number from "./QuizPreviewQuestionTypes/Number"; import Page from "./QuizPreviewQuestionTypes/Page"; import Rating from "./QuizPreviewQuestionTypes/Rating"; import Select, {ArrowDownTheme} from "./QuizPreviewQuestionTypes/Select"; import Text from "./QuizPreviewQuestionTypes/Text"; import Variant from "./QuizPreviewQuestionTypes/Variant"; import Varimg from "./QuizPreviewQuestionTypes/Varimg"; import { notReachable } from "../../utils/notReachable"; import ArrowDownIcon from "@icons/ArrowDownIcon"; export default function QuizPreviewLayout() { const theme = useTheme(); const questions = useQuestionsStore((state) => state.questions); const currentQuizStep = useQuizPreviewStore((state) => state.currentQuestionIndex); const [widthPreview, setWidthPreview] = useState(null) const nonDeletedQuizQuestions = questions.filter((question) => !question.deleted && question.type !== "result" ); const maxCurrentQuizStep = nonDeletedQuizQuestions.length > 0 ? nonDeletedQuizQuestions.length - 1 : 0; const currentProgress = Math.floor((currentQuizStep / maxCurrentQuizStep) * 100); const PreviewWin = useRef(0); const currentQuestion = nonDeletedQuizQuestions[currentQuizStep]; useEffect( function resetCurrentQuizStep() { if (currentQuizStep > maxCurrentQuizStep) { decrementCurrentQuestionIndex(); } }, [currentQuizStep, maxCurrentQuizStep] ); const observer = useRef( new ResizeObserver((entries) => { const { width } = entries[0].contentRect; setWidthPreview(width) }) ); useEffect(() => { observer.current.observe(PreviewWin.current); }, [PreviewWin, observer]); console.log('current width state: ', widthPreview); return ( setCurrentQuestionIndex(window.Number(target.value))} sx={{ height: "48px", borderRadius: "8px", "& .MuiOutlinedInput-notchedOutline": { border: `1px solid ${theme.palette.primary.main} !important`, }, "& .MuiSelect-icon": { color: theme.palette.primary.main } }} MenuProps={{ PaperProps: { sx: { mt: "8px", p: "4px", borderRadius: "8px", border: "1px solid #EEE4FC", boxShadow: "0px 8px 24px rgba(210, 208, 225, 0.4)", backgroundColor: theme.palette.background.default, }, }, MenuListProps: { sx: { py: 0, display: "flex", flexDirection: "column", gap: "8px", "& .Mui-selected": { backgroundColor: theme.palette.background.default, color: theme.palette.primary.main, }, }, }, }} inputProps={{ sx: { color: theme.palette.primary.main, display: "flex", alignItems: "center", px: "9px", gap: "20px", }, }} IconComponent={ArrowDownTheme} > {Object.values(questions.filter(q=>q.type!=="result")).map(({ id, title }, index) => ( {`${index + 1}. ${title}`} ))} {nonDeletedQuizQuestions.length > 0 ? `Вопрос ${currentQuizStep + 1} из ${nonDeletedQuizQuestions.length}` : "Нет вопросов"} {nonDeletedQuizQuestions.length > 0 && ( )} ); } function QuestionPreviewComponent({ question, widthPreview }: { question: AnyTypedQuizQuestion | UntypedQuizQuestion | undefined, widthPreview?: number }) { if (!question || question.type === null) return null; switch (question.type) { case "variant": return ; case "images": return ; case "varimg": return ; case "emoji": return ; case "text": return ; case "select": return