feat: decompose
This commit is contained in:
parent
33e0492719
commit
e3900506ee
@ -0,0 +1,72 @@
|
|||||||
|
import { Box } from "@mui/material";
|
||||||
|
|
||||||
|
type StartPageMobileProps = {
|
||||||
|
quizHeaderBlock: JSX.Element;
|
||||||
|
quizMainBlock: JSX.Element;
|
||||||
|
backgroundBlock: JSX.Element | null;
|
||||||
|
startpageType: "standard" | "expanded" | "centered";
|
||||||
|
};
|
||||||
|
|
||||||
|
export const StartPageMobile = ({
|
||||||
|
quizHeaderBlock,
|
||||||
|
quizMainBlock,
|
||||||
|
backgroundBlock,
|
||||||
|
startpageType,
|
||||||
|
}: StartPageMobileProps) => {
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column-reverse",
|
||||||
|
flexGrow: 1,
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
minHeight: "100vh",
|
||||||
|
height: "100%",
|
||||||
|
"&::-webkit-scrollbar": { width: 0 },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flexGrow: 1,
|
||||||
|
flexDirection: "column",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
alignItems: "flex-start",
|
||||||
|
p: "25px",
|
||||||
|
height: "100%",
|
||||||
|
overflowY: "auto",
|
||||||
|
overflowX: "hidden",
|
||||||
|
"&::-webkit-scrollbar": {
|
||||||
|
width: "4px",
|
||||||
|
},
|
||||||
|
"&::-webkit-scrollbar-thumb": {
|
||||||
|
backgroundColor: "#b8babf",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{quizHeaderBlock}
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
height: "80%",
|
||||||
|
display: "flex",
|
||||||
|
flexGrow: 1,
|
||||||
|
flexDirection: "column",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{quizMainBlock}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
overflow: "hidden",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{backgroundBlock}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
@ -11,88 +11,94 @@ import { Question } from "./Question";
|
|||||||
import { ResultForm } from "./ResultForm";
|
import { ResultForm } from "./ResultForm";
|
||||||
import { StartPageViewPublication } from "./StartPageViewPublication";
|
import { StartPageViewPublication } from "./StartPageViewPublication";
|
||||||
|
|
||||||
|
|
||||||
export default function ViewPublicationPage() {
|
export default function ViewPublicationPage() {
|
||||||
const { settings, recentlyCompleted } = useQuizData();
|
const { settings, recentlyCompleted } = useQuizData();
|
||||||
let currentQuizStep = useQuizViewStore(state => state.currentQuizStep);
|
let currentQuizStep = useQuizViewStore((state) => state.currentQuizStep);
|
||||||
const isMobileMini = useRootContainerSize() < 382;
|
const isMobileMini = useRootContainerSize() < 382;
|
||||||
const {
|
const {
|
||||||
currentQuestion,
|
currentQuestion,
|
||||||
currentQuestionStepNumber,
|
currentQuestionStepNumber,
|
||||||
isNextButtonEnabled,
|
isNextButtonEnabled,
|
||||||
isPreviousButtonEnabled,
|
isPreviousButtonEnabled,
|
||||||
moveToPrevQuestion,
|
moveToPrevQuestion,
|
||||||
moveToNextQuestion,
|
moveToNextQuestion,
|
||||||
showResultAfterContactForm,
|
showResultAfterContactForm,
|
||||||
} = useQuestionFlowControl();
|
} = useQuestionFlowControl();
|
||||||
|
|
||||||
useEffect(function setFaviconAndTitle() {
|
useEffect(
|
||||||
const link = document.querySelector('link[rel="icon"]');
|
function setFaviconAndTitle() {
|
||||||
if (link && settings.cfg.startpage.favIcon) {
|
const link = document.querySelector('link[rel="icon"]');
|
||||||
link.setAttribute("href", settings.cfg.startpage.favIcon);
|
if (link && settings.cfg.startpage.favIcon) {
|
||||||
}
|
link.setAttribute("href", settings.cfg.startpage.favIcon);
|
||||||
|
}
|
||||||
|
|
||||||
document.title = settings.name;
|
document.title = settings.name;
|
||||||
}, [settings]);
|
},
|
||||||
|
[settings]
|
||||||
|
);
|
||||||
|
|
||||||
if (recentlyCompleted) throw new Error("Quiz already completed");
|
if (recentlyCompleted) throw new Error("Quiz already completed");
|
||||||
if (currentQuizStep === "startpage" && settings.cfg.noStartPage) currentQuizStep = "question";
|
if (currentQuizStep === "startpage" && settings.cfg.noStartPage)
|
||||||
|
currentQuizStep = "question";
|
||||||
|
|
||||||
let quizStepElement: ReactElement;
|
let quizStepElement: ReactElement;
|
||||||
switch (currentQuizStep) {
|
switch (currentQuizStep) {
|
||||||
case "startpage": {
|
case "startpage": {
|
||||||
quizStepElement = <StartPageViewPublication />;
|
quizStepElement = <StartPageViewPublication />;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case "question": {
|
|
||||||
if (currentQuestion.type === "result") {
|
|
||||||
quizStepElement = <ResultForm resultQuestion={currentQuestion} />;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
quizStepElement = (
|
|
||||||
<Question
|
|
||||||
currentQuestion={currentQuestion}
|
|
||||||
currentQuestionStepNumber={currentQuestionStepNumber}
|
|
||||||
prevButton={
|
|
||||||
<Button
|
|
||||||
disabled={!isPreviousButtonEnabled}
|
|
||||||
variant="contained"
|
|
||||||
sx={{ fontSize: "16px", padding: "10px 15px" }}
|
|
||||||
onClick={moveToPrevQuestion}
|
|
||||||
>
|
|
||||||
{isMobileMini ? "←" : "← Назад"}
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
nextButton={
|
|
||||||
<Button
|
|
||||||
disabled={!isNextButtonEnabled}
|
|
||||||
variant="contained"
|
|
||||||
sx={{ fontSize: "16px", padding: "10px 15px" }}
|
|
||||||
onClick={moveToNextQuestion}
|
|
||||||
>
|
|
||||||
Далее →
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "contactform": {
|
|
||||||
quizStepElement = (
|
|
||||||
<ContactForm
|
|
||||||
currentQuestion={currentQuestion}
|
|
||||||
onShowResult={showResultAfterContactForm}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: notReachable(currentQuizStep);
|
|
||||||
}
|
}
|
||||||
|
case "question": {
|
||||||
|
if (currentQuestion.type === "result") {
|
||||||
|
quizStepElement = <ResultForm resultQuestion={currentQuestion} />;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
quizStepElement = (
|
||||||
<ThemeProvider theme={quizThemes[settings.cfg.theme || "StandardTheme"].theme}>
|
<Question
|
||||||
{quizStepElement}
|
currentQuestion={currentQuestion}
|
||||||
</ThemeProvider>
|
currentQuestionStepNumber={currentQuestionStepNumber}
|
||||||
);
|
prevButton={
|
||||||
}
|
<Button
|
||||||
|
disabled={!isPreviousButtonEnabled}
|
||||||
|
variant="contained"
|
||||||
|
sx={{ fontSize: "16px", padding: "10px 15px" }}
|
||||||
|
onClick={moveToPrevQuestion}
|
||||||
|
>
|
||||||
|
{isMobileMini ? "←" : "← Назад"}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
nextButton={
|
||||||
|
<Button
|
||||||
|
disabled={!isNextButtonEnabled}
|
||||||
|
variant="contained"
|
||||||
|
sx={{ fontSize: "16px", padding: "10px 15px" }}
|
||||||
|
onClick={moveToNextQuestion}
|
||||||
|
>
|
||||||
|
Далее →
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "contactform": {
|
||||||
|
quizStepElement = (
|
||||||
|
<ContactForm
|
||||||
|
currentQuestion={currentQuestion}
|
||||||
|
onShowResult={showResultAfterContactForm}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
notReachable(currentQuizStep);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThemeProvider
|
||||||
|
theme={quizThemes[settings.cfg.theme || "StandardTheme"].theme}
|
||||||
|
>
|
||||||
|
{quizStepElement}
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user