2024-04-23 14:45:49 +00:00
|
|
|
import { Box, Typography, useTheme } from "@mui/material";
|
|
|
|
|
|
|
|
import CustomTextField from "@ui_kit/CustomTextField";
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
2024-11-14 21:29:28 +00:00
|
|
|
import { useMemo, type ChangeEvent } from "react";
|
2024-04-23 14:45:49 +00:00
|
|
|
import type { QuizQuestionText } from "@model/questionTypes/text";
|
|
|
|
|
|
|
|
interface TextNormalProps {
|
|
|
|
currentQuestion: QuizQuestionText;
|
|
|
|
answer?: Answer;
|
|
|
|
stepNumber?: number | null;
|
|
|
|
}
|
|
|
|
|
2024-06-29 09:32:16 +00:00
|
|
|
export const TextNormal = ({ currentQuestion, answer }: TextNormalProps) => {
|
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 isMobile = useRootContainerSize() < 650;
|
2024-11-14 21:29:28 +00:00
|
|
|
const isTablet = useRootContainerSize() < 850;
|
2024-04-23 14:45:49 +00:00
|
|
|
const theme = useTheme();
|
|
|
|
|
|
|
|
const onInputChange = async ({ target }: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
updateAnswer(currentQuestion.id, target.value, 0);
|
|
|
|
};
|
2024-11-14 21:29:28 +00:00
|
|
|
const choiceImgUrlQuestion = useMemo(() => {
|
2024-11-16 19:22:50 +00:00
|
|
|
if (
|
|
|
|
currentQuestion.content.editedUrlImagesList !== undefined &&
|
|
|
|
currentQuestion.content.editedUrlImagesList !== null
|
|
|
|
) {
|
2024-11-14 21:29:28 +00:00
|
|
|
return currentQuestion.content.editedUrlImagesList[isMobile ? "mobile" : isTablet ? "tablet" : "desktop"];
|
|
|
|
} else {
|
|
|
|
return currentQuestion.content.back;
|
|
|
|
}
|
|
|
|
}, [currentQuestion]);
|
2024-04-23 14:45:49 +00:00
|
|
|
return (
|
|
|
|
<Box>
|
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>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
|
|
|
width: "100%",
|
|
|
|
marginTop: "20px",
|
|
|
|
flexDirection: isMobile ? "column-reverse" : undefined,
|
|
|
|
alignItems: "center",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<CustomTextField
|
|
|
|
placeholder={currentQuestion.content.placeholder}
|
|
|
|
value={answer || ""}
|
|
|
|
onChange={onInputChange}
|
|
|
|
sx={{
|
|
|
|
"& .MuiOutlinedInput-root": {
|
|
|
|
background: settings.cfg.design
|
|
|
|
? quizThemes[settings.cfg.theme].isLight
|
|
|
|
? "#F2F3F7"
|
|
|
|
: "rgba(255,255,255, 0.3)"
|
|
|
|
: "transparent",
|
|
|
|
},
|
|
|
|
"& .MuiOutlinedInput-notchedOutline": { borderColor: "#9A9AAF" },
|
|
|
|
"&:focus-visible": { borderColor: theme.palette.primary.main },
|
|
|
|
}}
|
|
|
|
/>
|
2024-11-14 21:29:28 +00:00
|
|
|
{choiceImgUrlQuestion && choiceImgUrlQuestion !== " " && choiceImgUrlQuestion !== null && (
|
2024-05-31 16:41:18 +00:00
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
maxWidth: "400px",
|
|
|
|
width: "100%",
|
|
|
|
height: "300px",
|
|
|
|
margin: "15px",
|
|
|
|
}}
|
2024-12-21 18:44:57 +00:00
|
|
|
onClick={(event) => event.preventDefault()}
|
2024-05-31 16:41:18 +00:00
|
|
|
>
|
|
|
|
<img
|
|
|
|
key={currentQuestion.id}
|
2024-11-14 21:29:28 +00:00
|
|
|
src={choiceImgUrlQuestion}
|
2024-05-31 16:41:18 +00:00
|
|
|
style={{ width: "100%", height: "100%", objectFit: "cover" }}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
2024-04-23 14:45:49 +00:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|