2024-05-31 16:41:18 +00:00
|
|
|
import { Box, TextField as MuiTextField, TextFieldProps, Typography, useTheme } from "@mui/material";
|
2024-04-23 14:45:49 +00:00
|
|
|
|
|
|
|
import { Answer, useQuizViewStore } from "@stores/quizView";
|
2024-05-31 17:56:17 +00:00
|
|
|
import { useQuizSettings } from "@contexts/QuizDataContext";
|
2024-04-23 14:45:49 +00:00
|
|
|
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
|
|
|
|
|
|
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
|
|
|
|
|
|
|
import type { ChangeEvent, FC } from "react";
|
|
|
|
import type { QuizQuestionText } from "@model/questionTypes/text";
|
|
|
|
|
|
|
|
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
|
|
|
|
|
|
|
const ORIENTATION = [
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: false },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: false },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: false },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: false },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: false },
|
|
|
|
{ horizontal: false },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
{ horizontal: true },
|
|
|
|
];
|
|
|
|
|
|
|
|
interface TextSpecialProps {
|
|
|
|
currentQuestion: QuizQuestionText;
|
|
|
|
answer?: Answer;
|
|
|
|
stepNumber?: number | null;
|
|
|
|
}
|
|
|
|
|
2024-06-29 09:32:16 +00:00
|
|
|
export const TextSpecial = ({ currentQuestion, answer, stepNumber }: TextSpecialProps) => {
|
2024-05-31 17:56:17 +00:00
|
|
|
const { settings } = useQuizSettings();
|
2024-04-23 14:45:49 +00:00
|
|
|
const { updateAnswer } = useQuizViewStore((state) => state);
|
|
|
|
const isHorizontal = ORIENTATION[Number(stepNumber) - 1].horizontal;
|
|
|
|
const theme = useTheme();
|
|
|
|
const isMobile = useRootContainerSize() < 650;
|
|
|
|
|
|
|
|
const onInputChange = async ({ target }: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
updateAnswer(currentQuestion.id, target.value, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: isMobile ? "column" : undefined,
|
|
|
|
alignItems: isMobile ? "center" : undefined,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
width: "100%",
|
|
|
|
marginTop: "20px",
|
|
|
|
flexDirection: "column",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: "20px",
|
|
|
|
}}
|
|
|
|
>
|
2024-06-29 09:32:16 +00:00
|
|
|
<Typography
|
|
|
|
variant="h5"
|
|
|
|
color={theme.palette.text.primary}
|
|
|
|
sx={{ wordBreak: "break-word" }}
|
|
|
|
>
|
2024-04-23 14:45:49 +00:00
|
|
|
{currentQuestion.title}
|
|
|
|
</Typography>
|
2024-05-31 16:41:18 +00:00
|
|
|
{isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
2024-12-21 18:44:57 +00:00
|
|
|
<Box
|
|
|
|
sx={{ margin: "30px", width: "50vw", maxHeight: "550px" }}
|
|
|
|
onClick={(event) => event.preventDefault()}
|
|
|
|
>
|
2024-05-31 16:41:18 +00:00
|
|
|
<img
|
|
|
|
key={currentQuestion.id}
|
|
|
|
src={currentQuestion.content.back}
|
|
|
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
2024-04-23 14:45:49 +00:00
|
|
|
{
|
|
|
|
<TextField
|
|
|
|
autoFocus={true}
|
|
|
|
multiline
|
|
|
|
maxRows={4}
|
|
|
|
placeholder={currentQuestion.content.placeholder}
|
|
|
|
value={answer || ""}
|
|
|
|
onChange={onInputChange}
|
|
|
|
inputProps={{
|
|
|
|
maxLength: 400,
|
|
|
|
background: settings.cfg.design
|
|
|
|
? quizThemes[settings.cfg.theme].isLight
|
|
|
|
? "#F2F3F7"
|
|
|
|
: "rgba(154,154,175, 0.2)"
|
|
|
|
: "transparent",
|
|
|
|
}}
|
|
|
|
sx={{
|
|
|
|
width: "100%",
|
|
|
|
"& .MuiOutlinedInput-root": {
|
2024-05-31 16:41:18 +00:00
|
|
|
backgroundColor: settings.cfg.design ? "rgba(154,154,175, 0.2)" : "#FFFFFF",
|
2024-04-23 14:45:49 +00:00
|
|
|
},
|
|
|
|
"&:focus-visible": {
|
|
|
|
borderColor: theme.palette.primary.main,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</Box>
|
2024-05-31 16:41:18 +00:00
|
|
|
{!isHorizontal && currentQuestion.content.back && currentQuestion.content.back !== " " && (
|
2024-12-21 18:44:57 +00:00
|
|
|
<Box
|
|
|
|
sx={{ margin: "15px", width: "40vw" }}
|
|
|
|
onClick={(event) => event.preventDefault()}
|
|
|
|
>
|
2024-05-31 16:41:18 +00:00
|
|
|
<img
|
|
|
|
key={currentQuestion.id}
|
|
|
|
src={currentQuestion.content.back}
|
|
|
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
2024-04-23 14:45:49 +00:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|