frontPanel/src/pages/Questions/Emoji/Emoji.tsx

245 lines
7.9 KiB
TypeScript
Raw Normal View History

2023-09-21 10:07:30 +00:00
import { useState } from "react";
2023-09-06 13:20:12 +00:00
import { useParams } from "react-router-dom";
2023-09-28 12:29:48 +00:00
import {
Box,
Link,
Typography,
useMediaQuery,
useTheme,
2023-09-25 13:43:15 +00:00
Popover,
2023-09-28 12:29:48 +00:00
} from "@mui/material";
2023-09-25 13:43:15 +00:00
import { EnterIcon } from "../../../assets/icons/questionsPage/enterIcon";
import ButtonsOptions from "../ButtonsOptions";
import SwitchEmoji from "./switchEmoji";
2023-09-06 07:30:27 +00:00
import { AnswerDraggableList } from "../AnswerDraggableList";
2023-09-28 12:29:48 +00:00
import { EmojiPicker } from "@ui_kit/EmojiPicker";
import { EmojiIcons } from "@icons/EmojiIocns";
2023-10-05 14:03:54 +00:00
import AddEmoji from "@icons/questionsPage/addEmoji";
import PlusImage from "@icons/questionsPage/plus";
2023-09-28 12:29:48 +00:00
2023-09-06 07:30:27 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
2023-10-02 19:43:07 +00:00
import type { QuizQuestionEmoji } from "../../../model/questionTypes/emoji";
2023-08-24 11:09:47 +00:00
interface Props {
totalIndex: number;
}
2023-10-02 19:43:07 +00:00
2023-08-24 11:09:47 +00:00
export default function Emoji({ totalIndex }: Props) {
2023-09-21 10:07:30 +00:00
const [switchState, setSwitchState] = useState<string>("setting");
2023-09-28 12:29:48 +00:00
const [open, setOpen] = useState<boolean>(false);
2023-10-03 14:41:12 +00:00
const [anchorElement, setAnchorElement] = useState<HTMLDivElement | null>(null);
2023-09-28 12:29:48 +00:00
const [currentIndex, setCurrentIndex] = useState<number>(0);
2023-09-06 07:30:27 +00:00
const { listQuestions } = questionStore();
2023-09-06 13:20:12 +00:00
const quizId = Number(useParams().quizId);
2023-09-06 07:30:27 +00:00
const theme = useTheme();
2023-10-02 19:43:07 +00:00
const question = listQuestions[quizId][totalIndex] as QuizQuestionEmoji;
2023-09-15 12:37:12 +00:00
const isMobile = useMediaQuery(theme.breakpoints.down(790));
2023-09-25 13:43:15 +00:00
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
2023-09-06 07:30:27 +00:00
2023-10-06 19:28:30 +00:00
2023-08-24 11:09:47 +00:00
const SSHC = (data: string) => {
setSwitchState(data);
};
2023-09-06 07:30:27 +00:00
2023-08-24 11:09:47 +00:00
return (
<>
<Box sx={{ padding: "20px" }}>
2023-09-25 07:12:22 +00:00
<AnswerDraggableList
2023-10-02 19:43:07 +00:00
variants={question.content.variants}
2023-09-25 07:12:22 +00:00
totalIndex={totalIndex}
2023-09-28 12:29:48 +00:00
additionalContent={(variant, index) => (
<>
{!isTablet && (
2023-10-04 13:55:52 +00:00
<Box sx={{ cursor: "pointer" }}>
2023-09-28 12:29:48 +00:00
<Box
onClick={({ currentTarget }) => {
setAnchorElement(currentTarget);
setCurrentIndex(index);
setOpen(true);
}}
>
<Box
sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
gap: "5px",
}}
>
2023-10-05 14:03:54 +00:00
{variant.extendedText ? (
2023-09-28 13:52:50 +00:00
<Box
sx={{
2023-10-04 13:55:52 +00:00
height: "40px",
width: "60px",
2023-09-28 13:52:50 +00:00
display: "flex",
alignItems: "center",
2023-10-04 13:55:52 +00:00
justifyContent: "space-between",
2023-09-28 13:52:50 +00:00
background: "#EEE4FC",
borderRadius: "3px",
marginRight: "15px",
}}
>
2023-10-04 13:55:52 +00:00
<Box
sx={{
width: "100%",
display: "flex",
justifyContent: "center",
}}
>
2023-10-05 14:03:54 +00:00
{variant.extendedText}
2023-10-04 13:55:52 +00:00
</Box>
<Box>
2023-09-28 13:52:50 +00:00
<PlusImage />
</Box>
</Box>
) : (
<AddEmoji />
2023-09-28 12:29:48 +00:00
)}
</Box>
</Box>
</Box>
)}
</>
)}
additionalMobile={(variant, index) => (
<>
{isTablet && (
<Box
onClick={({ currentTarget }) => {
setAnchorElement(currentTarget);
setCurrentIndex(index);
setOpen(true);
}}
sx={{
display: "flex",
alignItems: "center",
m: "8px",
position: "relative",
}}
>
<Box
sx={{
width: "100%",
background: "#EEE4FC",
height: "40px",
}}
/>
2023-10-05 14:03:54 +00:00
{variant.extendedText ? (
2023-09-28 12:29:48 +00:00
<Box
sx={{
position: "absolute",
color: "#7E2AEA",
fontSize: "20px",
left: "45%",
right: "55%",
}}
>
2023-10-05 14:03:54 +00:00
{variant.extendedText}
2023-09-28 12:29:48 +00:00
</Box>
) : (
<EmojiIcons
style={{
position: "absolute",
color: "#7E2AEA",
fontSize: "20px",
left: "45%",
right: "55%",
}}
/>
)}
<Box
sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
width: "20px",
background: "#EEE4FC",
height: "40px",
color: "white",
backgroundColor: "#7E2AEA",
}}
>
+
</Box>
</Box>
)}
</>
)}
2023-09-25 07:12:22 +00:00
/>
2023-09-28 12:29:48 +00:00
<Popover
open={open}
anchorEl={anchorElement}
onClick={(event) => event.stopPropagation()}
onClose={() => setOpen(false)}
anchorOrigin={{
vertical: "bottom",
horizontal: "right",
}}
sx={{
".MuiPaper-root.MuiPaper-rounded": {
borderRadius: "10px",
},
}}
>
<EmojiPicker
onEmojiSelect={({ native }) => {
setOpen(false);
2023-10-05 14:03:54 +00:00
const cloneVariants = [...question.content.variants];
2023-09-28 12:29:48 +00:00
cloneVariants[currentIndex] = {
...cloneVariants[currentIndex],
2023-10-05 14:03:54 +00:00
extendedText: native,
2023-09-28 12:29:48 +00:00
};
2023-10-05 14:03:54 +00:00
updateQuestionsList<QuizQuestionEmoji>(quizId, totalIndex, {
content: { ...question.content, variants: cloneVariants },
2023-09-28 12:29:48 +00:00
});
}}
/>
</Popover>
2023-10-03 14:41:12 +00:00
<Box sx={{ display: "flex", alignItems: "center", gap: "10px", marginBottom: isMobile ? "17px" : "20px" }}>
2023-08-24 11:09:47 +00:00
<Link
component="button"
variant="body2"
sx={{ color: theme.palette.brightPurple.main }}
2023-09-06 07:30:27 +00:00
onClick={() => {
2023-10-02 19:43:07 +00:00
const answerNew = question.content.variants.slice();
2023-10-03 14:03:57 +00:00
answerNew.push({ answer: "", hints: "", extendedText: "" });
2023-09-06 07:30:27 +00:00
2023-10-04 11:35:02 +00:00
updateQuestionsList<QuizQuestionEmoji>(quizId, totalIndex, {
2023-10-04 09:45:51 +00:00
content: { ...question.content, variants: answerNew },
2023-09-06 07:30:27 +00:00
});
}}
2023-08-24 11:09:47 +00:00
>
Добавьте ответ
</Link>
2023-09-28 12:29:48 +00:00
{!isTablet && (
2023-09-15 12:37:12 +00:00
<>
<Typography
sx={{
fontWeight: 400,
lineHeight: "21.33px",
color: theme.palette.grey2.main,
2023-09-25 13:43:15 +00:00
fontSize: "16px",
2023-09-15 12:37:12 +00:00
}}
>
или нажмите Enter
</Typography>
2023-10-01 12:14:34 +00:00
<EnterIcon
style={{
color: "#7E2AEA",
fontSize: "24px",
marginLeft: "6px",
}}
/>
2023-09-15 12:37:12 +00:00
</>
)}
2023-08-24 11:09:47 +00:00
</Box>
</Box>
2023-10-03 14:41:12 +00:00
<ButtonsOptions switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
2023-08-24 11:09:47 +00:00
<SwitchEmoji switchState={switchState} totalIndex={totalIndex} />
</>
);
}