2023-08-25 08:29:42 +00:00
|
|
|
|
import { useState } from "react";
|
2023-09-06 13:20:12 +00:00
|
|
|
|
import { useParams } from "react-router-dom";
|
2023-09-25 13:43:15 +00:00
|
|
|
|
import { Box, Typography, Tooltip, useTheme, useMediaQuery } from "@mui/material";
|
2023-09-20 09:07:33 +00:00
|
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
2023-08-25 08:29:42 +00:00
|
|
|
|
|
|
|
|
|
import CustomTextField from "@ui_kit/CustomTextField";
|
2023-03-31 15:48:49 +00:00
|
|
|
|
import ButtonsOptions from "../ButtonsOptions";
|
|
|
|
|
import SwitchTextField from "./switchTextField";
|
2023-08-25 08:29:42 +00:00
|
|
|
|
|
|
|
|
|
import { questionStore, updateQuestionsList } from "@root/questions";
|
|
|
|
|
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import InfoIcon from "../../../assets/icons/InfoIcon";
|
2023-03-31 15:48:49 +00:00
|
|
|
|
|
2023-10-03 14:03:57 +00:00
|
|
|
|
import type { QuizQuestionText } from "../../../model/questionTypes/text";
|
|
|
|
|
|
2023-06-30 14:39:07 +00:00
|
|
|
|
interface Props {
|
2023-08-24 11:09:47 +00:00
|
|
|
|
totalIndex: number;
|
|
|
|
|
}
|
|
|
|
|
export default function OwnTextField({ totalIndex }: Props) {
|
2023-08-25 08:29:42 +00:00
|
|
|
|
const [switchState, setSwitchState] = useState("setting");
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const quizId = Number(useParams().quizId);
|
2023-08-25 08:29:42 +00:00
|
|
|
|
const { listQuestions } = questionStore();
|
2023-08-24 11:09:47 +00:00
|
|
|
|
const theme = useTheme();
|
2023-10-03 14:03:57 +00:00
|
|
|
|
const question = listQuestions[quizId][totalIndex] as QuizQuestionText;
|
2023-09-25 13:43:15 +00:00
|
|
|
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
|
|
|
|
const isFigmaTablte = useMediaQuery(theme.breakpoints.down(990));
|
2023-09-20 09:07:33 +00:00
|
|
|
|
const debounced = useDebouncedCallback((value) => {
|
2023-10-04 11:35:02 +00:00
|
|
|
|
updateQuestionsList<QuizQuestionText>(quizId, totalIndex, {
|
2023-10-03 14:03:57 +00:00
|
|
|
|
content: { ...question.content, placeholder: value },
|
|
|
|
|
});
|
2023-09-20 09:07:33 +00:00
|
|
|
|
}, 1000);
|
2023-08-25 08:29:42 +00:00
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
const SSHC = (data: string) => {
|
|
|
|
|
setSwitchState(data);
|
|
|
|
|
};
|
2023-08-25 08:29:42 +00:00
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
2023-09-15 12:37:12 +00:00
|
|
|
|
width: "auto",
|
|
|
|
|
maxWidth: "745px",
|
2023-08-24 11:09:47 +00:00
|
|
|
|
display: "flex",
|
2023-10-03 14:41:12 +00:00
|
|
|
|
pb: "20px",
|
2023-09-25 13:43:15 +00:00
|
|
|
|
pl: "20px",
|
|
|
|
|
pr: "20px",
|
2023-08-24 11:09:47 +00:00
|
|
|
|
flexDirection: "column",
|
2023-09-26 23:38:26 +00:00
|
|
|
|
gap: isMobile ? "15px" : "20px",
|
2023-08-24 11:09:47 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-08-25 08:29:42 +00:00
|
|
|
|
<CustomTextField
|
|
|
|
|
placeholder={"Пример ответа"}
|
2023-10-03 14:03:57 +00:00
|
|
|
|
text={question.content.placeholder}
|
2023-09-20 09:07:33 +00:00
|
|
|
|
onChange={({ target }) => debounced(target.value)}
|
2023-10-03 14:41:12 +00:00
|
|
|
|
sx={{ maxWidth: isFigmaTablte ? "549px" : "640px", width: "100%", mt: isMobile ? "15px" : "0px" }}
|
2023-08-25 08:29:42 +00:00
|
|
|
|
/>
|
2023-10-03 14:41:12 +00:00
|
|
|
|
<Box sx={{ display: "flex", alignItems: isMobile ? "flex-start" : "center", gap: "12px" }}>
|
2023-08-24 11:09:47 +00:00
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontWeight: 400,
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
lineHeight: "18.96px",
|
|
|
|
|
color: theme.palette.grey2.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-09-25 13:43:15 +00:00
|
|
|
|
Пользователю будет дано поле для ввода значения
|
2023-08-24 11:09:47 +00:00
|
|
|
|
</Typography>
|
2023-09-25 13:43:15 +00:00
|
|
|
|
<Tooltip title="Будет использоваться для ввода значения." placement="top">
|
2023-09-18 12:34:41 +00:00
|
|
|
|
<Box>
|
|
|
|
|
<InfoIcon />
|
|
|
|
|
</Box>
|
|
|
|
|
</Tooltip>
|
2023-08-24 11:09:47 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-09-25 13:43:15 +00:00
|
|
|
|
<ButtonsOptions switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
2023-08-24 11:09:47 +00:00
|
|
|
|
<SwitchTextField switchState={switchState} totalIndex={totalIndex} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-06-30 14:39:07 +00:00
|
|
|
|
}
|