Ленивая подгрузка страниц редактирования квиза
This commit is contained in:
parent
83a93574c0
commit
c49099b52e
@ -7,7 +7,7 @@ import {
|
|||||||
import { Box, Button } from "@mui/material";
|
import { Box, Button } from "@mui/material";
|
||||||
import ArrowLeft from "@icons/questionsPage/arrowLeft";
|
import ArrowLeft from "@icons/questionsPage/arrowLeft";
|
||||||
|
|
||||||
export const ResultPage = () => {
|
export default () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FirstEntry />
|
<FirstEntry />
|
||||||
|
@ -1,40 +1,24 @@
|
|||||||
import { quizApi } from "@api/quiz";
|
|
||||||
import EyeIcon from "@icons/EyeIcon";
|
|
||||||
import VisibilityIcon from "@mui/icons-material/Visibility";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
|
||||||
IconButton,
|
|
||||||
Switch,
|
|
||||||
Typography,
|
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { setQuizes, updateQuiz, setCurrentStep } from "@root/quizes/actions";
|
import { updateQuiz, setCurrentStep } from "@root/quizes/actions";
|
||||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||||
import { useQuizStore } from "@root/quizes/store";
|
import { useQuizStore } from "@root/quizes/store";
|
||||||
import Sidebar from "@ui_kit/Sidebar/Sidebar";
|
|
||||||
import Stepper from "@ui_kit/Stepper";
|
import Stepper from "@ui_kit/Stepper";
|
||||||
import SwitchStepPages from "@ui_kit/switchStepPages";
|
import SwitchStepPages from "@ui_kit/switchStepPages";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useDebouncedCallback } from "use-debounce";
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
import { SidebarMobile } from "../../ui_kit/Sidebar/SidebarMobile";
|
import { cleanQuestions } from "@root/questions/actions";
|
||||||
import {
|
|
||||||
cleanQuestions,
|
|
||||||
createResult,
|
|
||||||
setQuestions,
|
|
||||||
} from "@root/questions/actions";
|
|
||||||
import {
|
import {
|
||||||
updateCanCreatePublic,
|
updateCanCreatePublic,
|
||||||
updateModalInfoWhyCantCreate,
|
updateModalInfoWhyCantCreate,
|
||||||
setShowConfirmLeaveModal,
|
setShowConfirmLeaveModal,
|
||||||
updateSomeWorkBackend,
|
updateSomeWorkBackend,
|
||||||
} from "@root/uiTools/actions";
|
} from "@root/uiTools/actions";
|
||||||
import { Header } from "@ui_kit/Header/Header";
|
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import { questionApi } from "@api/question";
|
|
||||||
import { useUiTools } from "@root/uiTools/store";
|
import { useUiTools } from "@root/uiTools/store";
|
||||||
|
|
||||||
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
|
import type { SuspenseProps } from "react";
|
||||||
|
import { lazy, Suspense } from "react";
|
||||||
import {
|
import {
|
||||||
QuizResultsType,
|
QuizResultsType,
|
||||||
QuizStartpageType,
|
QuizStartpageType,
|
||||||
QuizType,
|
QuizType,
|
||||||
} from "@model/quizSettings";
|
} from "@model/quizSettings";
|
||||||
import ContactFormPage from "../pages/ContactFormPage/ContactFormPage";
|
|
||||||
import InstallQuiz from "../pages/InstallQuiz/InstallQuiz";
|
|
||||||
import FormQuestionsPage from "../pages/Questions/Form/FormQuestionsPage";
|
|
||||||
import QuestionsPage from "../pages/Questions/QuestionsPage";
|
|
||||||
import { QuestionsMap } from "../pages/QuestionsMap";
|
|
||||||
import { ResultPage } from "../pages/ResultPage/ResultPage";
|
|
||||||
import { ResultSettings } from "../pages/ResultPage/ResultSettings";
|
|
||||||
import StartPageSettings from "../pages/startPage/StartPageSettings";
|
|
||||||
import StepOne from "../pages/startPage/stepOne";
|
|
||||||
import Steptwo from "../pages/startPage/steptwo";
|
|
||||||
|
|
||||||
|
const ContactFormPage = lazy(() => import("../pages/ContactFormPage/ContactFormPage"));
|
||||||
|
const InstallQuiz = lazy(() => import("../pages/InstallQuiz/InstallQuiz"));
|
||||||
|
const FormQuestionsPage = lazy(() => import("../pages/Questions/Form/FormQuestionsPage"));
|
||||||
|
const QuestionsPage = lazy(() => import("../pages/Questions/QuestionsPage"));
|
||||||
|
const ResultPage = lazy(() => import("../pages/ResultPage/ResultPage"));
|
||||||
|
const StartPageSettings = lazy(() => import("../pages/startPage/StartPageSettings"));
|
||||||
|
const StepOne = lazy(() => import("../pages/startPage/stepOne"));
|
||||||
|
const Steptwo = lazy(() => import("../pages/startPage/steptwo"));
|
||||||
|
|
||||||
|
const LazyLoading = ({ children, fallback }: SuspenseProps) => (
|
||||||
|
<Suspense fallback={fallback ?? <></>}>{children}</Suspense>
|
||||||
|
);
|
||||||
interface Props {
|
interface Props {
|
||||||
activeStep: number;
|
activeStep: number;
|
||||||
quizType: QuizType;
|
quizType: QuizType;
|
||||||
@ -28,33 +32,32 @@ export default function SwitchStepPages({
|
|||||||
activeStep = 1,
|
activeStep = 1,
|
||||||
quizType,
|
quizType,
|
||||||
quizStartPageType,
|
quizStartPageType,
|
||||||
quizResults,
|
|
||||||
openBranchingPage,
|
openBranchingPage,
|
||||||
setOpenBranchingPage,
|
setOpenBranchingPage,
|
||||||
widthMain,
|
widthMain,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
switch (activeStep) {
|
switch (activeStep) {
|
||||||
case 0: {
|
case 0: {
|
||||||
if (!quizType) return <StepOne />;
|
if (!quizType) return <LazyLoading><StepOne /></LazyLoading>;
|
||||||
if (!quizStartPageType) return <Steptwo />;
|
if (!quizStartPageType) return <LazyLoading><Steptwo /></LazyLoading>;
|
||||||
return <StartPageSettings />;
|
return <LazyLoading><StartPageSettings /></LazyLoading>;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
return quizType === "form" ? (
|
return quizType === "form" ? (
|
||||||
<FormQuestionsPage />
|
<LazyLoading><FormQuestionsPage /></LazyLoading>
|
||||||
) : (
|
) : (
|
||||||
<QuestionsPage
|
<LazyLoading><QuestionsPage
|
||||||
openBranchingPage={openBranchingPage}
|
openBranchingPage={openBranchingPage}
|
||||||
setOpenBranchingPage={setOpenBranchingPage}
|
setOpenBranchingPage={setOpenBranchingPage}
|
||||||
widthMain={widthMain}
|
widthMain={widthMain}
|
||||||
/>
|
/></LazyLoading>
|
||||||
);
|
);
|
||||||
case 2:
|
case 2:
|
||||||
return <ResultPage />;
|
return <LazyLoading><ResultPage /></LazyLoading>;
|
||||||
case 3:
|
case 3:
|
||||||
return <ContactFormPage />;
|
return <LazyLoading><ContactFormPage /></LazyLoading>;
|
||||||
case 4:
|
case 4:
|
||||||
return <InstallQuiz />;
|
return <LazyLoading><InstallQuiz /></LazyLoading>;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Invalid quiz setup step: ${activeStep}`);
|
throw new Error(`Invalid quiz setup step: ${activeStep}`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user