2023-09-20 09:07:33 +00:00
|
|
|
|
import { useState } from "react";
|
2023-09-05 13:54:41 +00:00
|
|
|
|
import { Box, ButtonBase, Typography } from "@mui/material";
|
2023-09-06 13:20:12 +00:00
|
|
|
|
import { useParams } from "react-router-dom";
|
2023-05-10 17:35:30 +00:00
|
|
|
|
import SelectableButton from "@ui_kit/SelectableButton";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
import CustomTextField from "@ui_kit/CustomTextField";
|
2023-09-20 09:07:33 +00:00
|
|
|
|
import { useDebouncedCallback } from "use-debounce";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import UploadIcon from "../../assets/icons/UploadIcon";
|
2023-05-10 17:35:30 +00:00
|
|
|
|
import UploadBox from "@ui_kit/UploadBox";
|
2023-08-24 11:09:47 +00:00
|
|
|
|
import { questionStore, updateQuestionsList } from "@root/questions";
|
2023-09-05 13:54:41 +00:00
|
|
|
|
import { UploadVideoModal } from "./UploadVideoModal";
|
2023-08-15 11:00:45 +00:00
|
|
|
|
|
2023-03-15 22:56:53 +00:00
|
|
|
|
type BackgroundType = "text" | "video";
|
|
|
|
|
|
2023-08-24 11:09:47 +00:00
|
|
|
|
type HelpQuestionsProps = {
|
|
|
|
|
totalIndex: number;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function HelpQuestions({ totalIndex }: HelpQuestionsProps) {
|
2023-08-15 11:00:45 +00:00
|
|
|
|
const [open, setOpen] = useState(false);
|
2023-07-30 21:25:47 +00:00
|
|
|
|
const [backgroundType, setBackgroundType] = useState<BackgroundType>("text");
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const quizId = Number(useParams().quizId);
|
2023-08-24 11:09:47 +00:00
|
|
|
|
const { listQuestions } = questionStore();
|
2023-09-20 09:07:33 +00:00
|
|
|
|
const debounced = useDebouncedCallback((value) => {
|
|
|
|
|
let clonContent = listQuestions[quizId][totalIndex].content;
|
|
|
|
|
clonContent.hint.text = value;
|
|
|
|
|
updateQuestionsList(quizId, totalIndex, { content: clonContent });
|
|
|
|
|
}, 1000);
|
2023-08-15 11:00:45 +00:00
|
|
|
|
|
2023-09-05 13:54:41 +00:00
|
|
|
|
const videoHC = (url: string) => {
|
2023-09-06 13:20:12 +00:00
|
|
|
|
const clonContent = listQuestions[quizId][totalIndex].content;
|
2023-09-05 13:54:41 +00:00
|
|
|
|
clonContent.hint.video = url;
|
2023-09-06 13:20:12 +00:00
|
|
|
|
updateQuestionsList(quizId, totalIndex, { content: clonContent });
|
2023-08-15 11:00:45 +00:00
|
|
|
|
};
|
2023-07-30 21:25:47 +00:00
|
|
|
|
|
|
|
|
|
return (
|
2023-08-15 09:51:18 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
padding: "20px",
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
gap: "20px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Typography sx={{ fontWeight: "500" }}>Подсказка консультанта</Typography>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
gap: "10px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-08-15 09:51:18 +00:00
|
|
|
|
<SelectableButton
|
|
|
|
|
isSelected={backgroundType === "text"}
|
|
|
|
|
onClick={() => setBackgroundType("text")}
|
|
|
|
|
sx={{ maxWidth: "130px" }}
|
|
|
|
|
>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
Текст
|
|
|
|
|
</SelectableButton>
|
2023-08-15 09:51:18 +00:00
|
|
|
|
<SelectableButton
|
|
|
|
|
isSelected={backgroundType === "video"}
|
|
|
|
|
onClick={() => setBackgroundType("video")}
|
|
|
|
|
sx={{ maxWidth: "130px" }}
|
|
|
|
|
>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
Видео
|
|
|
|
|
</SelectableButton>
|
|
|
|
|
</Box>
|
|
|
|
|
{backgroundType === "text" ? (
|
|
|
|
|
<>
|
2023-08-24 11:09:47 +00:00
|
|
|
|
<CustomTextField
|
|
|
|
|
placeholder={"Текст консультанта"}
|
2023-09-06 13:20:12 +00:00
|
|
|
|
text={listQuestions[quizId][totalIndex].content.hint.text}
|
2023-09-20 09:07:33 +00:00
|
|
|
|
onChange={({ target }) => debounced(target.value)}
|
2023-08-24 11:09:47 +00:00
|
|
|
|
/>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<Box>
|
2023-08-15 09:51:18 +00:00
|
|
|
|
<Typography sx={{ paddingBottom: "15px", fontWeight: "500" }}>
|
|
|
|
|
Загрузите видео
|
|
|
|
|
</Typography>
|
|
|
|
|
<ButtonBase
|
2023-09-05 13:54:41 +00:00
|
|
|
|
onClick={() => setOpen(true)}
|
2023-08-15 09:51:18 +00:00
|
|
|
|
sx={{ justifyContent: "flex-start" }}
|
|
|
|
|
>
|
2023-09-06 13:20:12 +00:00
|
|
|
|
{listQuestions[quizId][totalIndex].content.hint.video ? (
|
2023-08-24 11:09:47 +00:00
|
|
|
|
<video
|
2023-09-06 13:20:12 +00:00
|
|
|
|
src={listQuestions[quizId][totalIndex].content.hint.video}
|
2023-08-24 11:09:47 +00:00
|
|
|
|
width="400"
|
|
|
|
|
controls
|
|
|
|
|
/>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<UploadBox
|
|
|
|
|
icon={<UploadIcon />}
|
|
|
|
|
sx={{
|
|
|
|
|
height: "48px",
|
|
|
|
|
width: "48px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</ButtonBase>
|
2023-09-05 13:54:41 +00:00
|
|
|
|
<UploadVideoModal
|
2023-07-30 21:25:47 +00:00
|
|
|
|
open={open}
|
2023-09-05 13:54:41 +00:00
|
|
|
|
onClose={() => setOpen(false)}
|
2023-09-06 13:20:12 +00:00
|
|
|
|
video={listQuestions[quizId][totalIndex].content.hint.video}
|
2023-09-05 13:54:41 +00:00
|
|
|
|
onUpload={videoHC}
|
|
|
|
|
/>
|
2023-03-15 22:56:53 +00:00
|
|
|
|
</Box>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|