frontPanel/src/pages/Questions/helpQuestions.tsx

104 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-11-29 13:49:52 +00:00
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
2023-09-05 13:54:41 +00:00
import { Box, ButtonBase, Typography } from "@mui/material";
2023-11-27 23:07:24 +00:00
import { updateQuestion } from "@root/questions/actions";
import CustomTextField from "@ui_kit/CustomTextField";
2023-11-15 18:38:02 +00:00
import SelectableButton from "@ui_kit/SelectableButton";
import UploadBox from "@ui_kit/UploadBox";
import { useState } from "react";
2023-09-20 09:07:33 +00:00
import { useDebouncedCallback } from "use-debounce";
import UploadIcon from "../../assets/icons/UploadIcon";
2023-09-05 13:54:41 +00:00
import { UploadVideoModal } from "./UploadVideoModal";
2023-08-15 11:00:45 +00:00
2023-10-03 14:03:57 +00:00
type BackgroundType = "text" | "video";
2023-08-24 11:09:47 +00:00
type HelpQuestionsProps = {
2023-11-29 13:49:52 +00:00
question: AnyTypedQuizQuestion;
2023-08-24 11:09:47 +00:00
};
2023-11-15 18:38:02 +00:00
export default function HelpQuestions({ question }: HelpQuestionsProps) {
const [open, setOpen] = useState(false);
const [backgroundType, setBackgroundType] = useState<BackgroundType>("text");
2023-08-15 11:00:45 +00:00
2023-11-15 18:38:02 +00:00
const updateQuestionHint = useDebouncedCallback((value) => {
2023-11-27 23:07:24 +00:00
updateQuestion(question.id, question => {
2023-11-15 18:38:02 +00:00
question.content.hint.text = value;
});
2023-11-27 23:07:24 +00:00
}, 200);
2023-11-15 18:38:02 +00:00
return (
<Box
sx={{
padding: "20px",
display: "flex",
flexDirection: "column",
gap: "20px",
}}
2023-08-15 09:51:18 +00:00
>
2023-11-15 18:38:02 +00:00
<Typography sx={{ fontWeight: "500" }}>Подсказка консультанта</Typography>
<Box
sx={{
display: "flex",
gap: "10px",
}}
>
<SelectableButton
isSelected={backgroundType === "text"}
onClick={() => setBackgroundType("text")}
sx={{ maxWidth: "130px" }}
>
Текст
</SelectableButton>
<SelectableButton
isSelected={backgroundType === "video"}
onClick={() => setBackgroundType("video")}
sx={{ maxWidth: "130px" }}
>
Видео
</SelectableButton>
</Box>
{backgroundType === "text" ? (
<>
<CustomTextField
placeholder={"Текст консультанта"}
text={question.content.hint.text}
onChange={({ target }) => updateQuestionHint(target.value || " ")}
2023-11-15 18:38:02 +00:00
/>
</>
) : (
2023-11-15 18:38:02 +00:00
<Box>
<Typography sx={{ paddingBottom: "15px", fontWeight: "500" }}>
Загрузите видео
</Typography>
<ButtonBase
onClick={() => setOpen(true)}
sx={{ justifyContent: "flex-start" }}
>
{question.content.hint.video ? (
<video src={question.content.hint.video} width="400" controls />
) : (
<>
<UploadBox
icon={<UploadIcon />}
sx={{
height: "48px",
width: "48px",
}}
/>
</>
)}
</ButtonBase>
<UploadVideoModal
open={open}
onClose={() => setOpen(false)}
video={question.content.hint.video}
2023-11-27 23:07:24 +00:00
onUpload={url => updateQuestion(question.id, question => {
2023-11-15 18:38:02 +00:00
question.content.hint.video = url;
})}
/>
</Box>
)}
</Box>
2023-11-15 18:38:02 +00:00
);
}