frontAnswerer/lib/components/ViewPublicationPage/StartPageViewPublication/StartPageMobile.tsx

267 lines
6.8 KiB
TypeScript
Raw Normal View History

2024-02-28 14:10:50 +00:00
import { Box } from "@mui/material";
2024-03-06 15:45:45 +00:00
import { useQuizData } from "@contexts/QuizDataContext";
2024-02-29 13:44:45 +00:00
import { notReachable } from "@utils/notReachable";
2024-03-06 15:45:45 +00:00
import { quizThemes } from "@utils/themes/Publication/themePublication";
2024-02-29 13:44:45 +00:00
import type { QuizStartpageType } from "@model/settingsData";
import { DESIGN_LIST } from "@/utils/designList";
2024-02-28 14:10:50 +00:00
type StartPageMobileProps = {
quizHeaderBlock: JSX.Element;
quizMainBlock: JSX.Element;
backgroundBlock: JSX.Element | null;
startpageType: QuizStartpageType;
2024-02-28 14:10:50 +00:00
};
2024-02-29 13:44:45 +00:00
type MobileLayoutProps = Omit<StartPageMobileProps, "startpageType">;
const StandartMobileLayout = ({
2024-02-28 14:10:50 +00:00
quizHeaderBlock,
quizMainBlock,
backgroundBlock,
2024-03-06 15:45:45 +00:00
}: MobileLayoutProps) => {
const { settings } = useQuizData();
return (
2024-02-28 14:10:50 +00:00
<Box
sx={{
display: "flex",
2024-03-06 15:45:45 +00:00
flexDirection: "column-reverse",
2024-02-28 14:10:50 +00:00
flexGrow: 1,
2024-03-06 15:45:45 +00:00
justifyContent: "flex-end",
2024-04-02 17:21:31 +00:00
minHeight: "100%",
2024-02-28 14:10:50 +00:00
height: "100%",
2024-03-06 15:45:45 +00:00
"&::-webkit-scrollbar": { width: 0 },
backgroundPosition: "center",
backgroundSize: "cover",
backgroundImage: settings.cfg.design
? `url(${DESIGN_LIST[settings.cfg.theme]})`
: null,
2024-02-28 14:10:50 +00:00
}}
>
<Box
sx={{
2024-03-06 15:45:45 +00:00
width: "100%",
2024-02-29 13:44:45 +00:00
display: "flex",
flexGrow: 1,
flexDirection: "column",
justifyContent: "space-between",
2024-03-06 15:45:45 +00:00
alignItems: "flex-start",
p: "25px",
height: "100%",
overflowY: "auto",
overflowX: "hidden",
background:
settings.cfg.design && !quizThemes[settings.cfg.theme].isLight
? "linear-gradient(90deg,#272626,transparent)"
: null,
"&::-webkit-scrollbar": {
width: "4px",
},
"&::-webkit-scrollbar-thumb": {
backgroundColor: "#b8babf",
},
2024-02-29 13:44:45 +00:00
}}
>
2024-03-06 15:45:45 +00:00
{quizHeaderBlock}
<Box
sx={{
height: "80%",
display: "flex",
flexGrow: 1,
flexDirection: "column",
justifyContent: "space-between",
width: "100%",
}}
>
{quizMainBlock}
</Box>
2024-02-29 13:44:45 +00:00
</Box>
2024-03-06 15:45:45 +00:00
{settings.cfg.startpage.background.desktop && (
<Box sx={{ width: "100%", overflow: "hidden" }}>{backgroundBlock}</Box>
)}
2024-02-29 13:44:45 +00:00
</Box>
2024-03-06 15:45:45 +00:00
);
};
2024-02-29 13:44:45 +00:00
const ExpandedMobileLayout = ({
quizHeaderBlock,
quizMainBlock,
backgroundBlock,
}: MobileLayoutProps) => (
<Box
sx={{
display: "flex",
flexDirection: "column-reverse",
flexGrow: 1,
justifyContent: "flex-end",
2024-04-02 17:21:31 +00:00
minHeight: "100%",
2024-02-29 13:44:45 +00:00
height: "100%",
"&::-webkit-scrollbar": { width: 0 },
}}
>
<Box
sx={{
zIndex: 3,
width: "100%",
display: "flex",
flexGrow: 1,
flexDirection: "column",
justifyContent: "space-between",
alignItems: "flex-start",
height: "100%",
overflowY: "auto",
overflowX: "hidden",
"&::-webkit-scrollbar": { width: "4px" },
"&::-webkit-scrollbar-thumb": { backgroundColor: "#b8babf" },
}}
>
{quizHeaderBlock}
<Box
sx={{
padding: "16px",
height: "80%",
2024-02-28 14:10:50 +00:00
display: "flex",
flexGrow: 1,
flexDirection: "column",
justifyContent: "space-between",
2024-02-29 13:44:45 +00:00
width: "100%",
2024-02-28 14:10:50 +00:00
}}
>
2024-02-29 13:44:45 +00:00
{quizMainBlock}
2024-02-28 14:10:50 +00:00
</Box>
2024-02-29 13:44:45 +00:00
</Box>
<Box
sx={{
zIndex: -1,
position: "absolute",
left: 0,
top: 0,
width: "100%",
height: "100%",
// minHeight: "100%",
2024-02-29 13:44:45 +00:00
overflow: "hidden",
"& > img": {
display: "block",
2024-04-02 17:21:31 +00:00
minHeight: "100%",
2024-02-29 13:44:45 +00:00
},
}}
>
{backgroundBlock}
</Box>
</Box>
);
const CenteredMobileLayout = ({
quizHeaderBlock,
quizMainBlock,
backgroundBlock,
}: MobileLayoutProps) => {
const {settings} = useQuizData();
return (
<Box
sx={{
display: "flex",
flexDirection: "column-reverse",
flexGrow: 1,
justifyContent: "flex-end",
2024-04-02 17:21:31 +00:00
minHeight: "100%",
height: "100%",
backgroundPosition: "center",
backgroundSize: "cover",
backgroundImage: settings.cfg.design
? `url(${DESIGN_LIST[settings.cfg.theme]})`
: null,
"&::-webkit-scrollbar": {width: 0},
}}
>
<Box
sx={{
width: "100%",
display: "flex",
flexGrow: 1,
flexDirection: "column",
justifyContent: "space-between",
alignItems: "flex-start",
padding: "10px 25px 25px",
height: "100%",
overflowY: "auto",
overflowX: "hidden",
"&::-webkit-scrollbar": {width: "4px"},
"&::-webkit-scrollbar-thumb": {backgroundColor: "#b8babf"},
}}
>
{quizHeaderBlock}
{settings.cfg.startpage.background.desktop && (
<Box
sx={{
width: "100%",
overflow: "hidden",
"& > img": {width: "100%", borderRadius: "12px"},
}}
>
{backgroundBlock}
</Box>
)}
<Box
sx={{
height: "80%",
display: "flex",
flexGrow: 1,
flexDirection: "column",
justifyContent: "space-between",
width: "100%",
}}
>
{quizMainBlock}
</Box>
</Box>
</Box>
);
}
2024-02-29 13:44:45 +00:00
export const StartPageMobile = ({
quizHeaderBlock,
quizMainBlock,
backgroundBlock,
startpageType,
}: StartPageMobileProps) => {
switch (startpageType) {
case null:
case "standard": {
return (
<StandartMobileLayout
quizHeaderBlock={quizHeaderBlock}
quizMainBlock={quizMainBlock}
backgroundBlock={backgroundBlock}
/>
);
}
case "expanded": {
return (
<ExpandedMobileLayout
quizHeaderBlock={quizHeaderBlock}
quizMainBlock={quizMainBlock}
backgroundBlock={backgroundBlock}
/>
);
}
case "centered": {
return (
<CenteredMobileLayout
quizHeaderBlock={quizHeaderBlock}
quizMainBlock={quizMainBlock}
backgroundBlock={backgroundBlock}
/>
);
}
default:
notReachable(startpageType);
}
2024-02-28 14:10:50 +00:00
};