commit
6cf187703e
@ -3,7 +3,7 @@ import type { QuizQuestionInitial } from "../model/questionTypes/shared";
|
||||
export const QUIZ_QUESTION_BASE: Omit<QuizQuestionInitial, "id"> = {
|
||||
title: "",
|
||||
type: "nonselected",
|
||||
expanded: false,
|
||||
expanded: true,
|
||||
required: false,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
|
||||
@ -15,7 +15,6 @@ export const QUIZ_QUESTION_EMOJI: Omit<QuizQuestionEmoji, "id"> = {
|
||||
variants: [
|
||||
{
|
||||
answer: "",
|
||||
hints: "",
|
||||
extendedText: "",
|
||||
},
|
||||
],
|
||||
|
||||
@ -18,7 +18,6 @@ export const QUIZ_QUESTION_IMAGES: Omit<QuizQuestionImages, "id"> = {
|
||||
variants: [
|
||||
{
|
||||
answer: "",
|
||||
hints: "",
|
||||
extendedText: "",
|
||||
},
|
||||
],
|
||||
|
||||
@ -12,6 +12,6 @@ export const QUIZ_QUESTION_SELECT: Omit<QuizQuestionSelect, "id"> = {
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
default: "",
|
||||
variants: [{ answer: "", hints: "", extendedText: "" }],
|
||||
variants: [{ answer: "", extendedText: "" }],
|
||||
},
|
||||
};
|
||||
|
||||
@ -13,6 +13,6 @@ export const QUIZ_QUESTION_VARIANT: Omit<QuizQuestionVariant, "id"> = {
|
||||
innerNameCheck: false,
|
||||
required: false,
|
||||
innerName: "",
|
||||
variants: [{ answer: "", hints: "", extendedText: "" }],
|
||||
variants: [{ answer: "", extendedText: "" }],
|
||||
},
|
||||
};
|
||||
|
||||
@ -11,7 +11,7 @@ export const QUIZ_QUESTION_VARIMG: Omit<QuizQuestionVarImg, "id"> = {
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
required: false,
|
||||
variants: [{ answer: "", hints: "", extendedText: "" }],
|
||||
variants: [{ answer: "", extendedText: "" }],
|
||||
largeCheck: false,
|
||||
replText: "",
|
||||
},
|
||||
|
||||
@ -32,8 +32,6 @@ export interface QuestionHint {
|
||||
export type QuestionVariant = {
|
||||
/** Текст */
|
||||
answer: string;
|
||||
/** Текст подсказки */
|
||||
hints: string;
|
||||
/** Дополнительное поле для текста, emoji, ссылки на картинку */
|
||||
extendedText: string;
|
||||
};
|
||||
|
||||
@ -7,7 +7,6 @@ import {
|
||||
FormControl,
|
||||
InputAdornment,
|
||||
IconButton,
|
||||
Popover,
|
||||
useTheme,
|
||||
useMediaQuery,
|
||||
} from "@mui/material";
|
||||
@ -17,10 +16,9 @@ import { questionStore, updateQuestionsList } from "@root/questions";
|
||||
|
||||
import { PointsIcon } from "@icons/questionsPage/PointsIcon";
|
||||
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
|
||||
import { MessageIcon } from "@icons/messagIcon";
|
||||
import TextareaAutosize from "@mui/base/TextareaAutosize";
|
||||
|
||||
import type { ChangeEvent, KeyboardEvent, ReactNode } from "react";
|
||||
import type { KeyboardEvent, ReactNode } from "react";
|
||||
import type { DroppableProvided } from "react-beautiful-dnd";
|
||||
import type { QuizQuestionVariant } from "../../../model/questionTypes/variant";
|
||||
import type { QuestionVariant } from "../../../model/questionTypes/shared";
|
||||
|
||||
@ -29,9 +27,9 @@ type AnswerItemProps = {
|
||||
totalIndex: number;
|
||||
variants: QuestionVariant[];
|
||||
variant: QuestionVariant;
|
||||
provided: DroppableProvided;
|
||||
additionalContent?: ReactNode;
|
||||
additionalMobile?: ReactNode;
|
||||
icon?: ReactNode;
|
||||
};
|
||||
|
||||
export const AnswerItem = ({
|
||||
@ -39,6 +37,7 @@ export const AnswerItem = ({
|
||||
totalIndex,
|
||||
variants,
|
||||
variant,
|
||||
provided,
|
||||
additionalContent,
|
||||
additionalMobile,
|
||||
}: AnswerItemProps) => {
|
||||
@ -59,21 +58,9 @@ export const AnswerItem = ({
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
|
||||
|
||||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
setIsOpen(true);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
const addNewAnswer = () => {
|
||||
const answerNew = variants.slice();
|
||||
answerNew.push({ answer: "", hints: "", extendedText: "" });
|
||||
answerNew.push({ answer: "", extendedText: "" });
|
||||
|
||||
updateQuestionsList<QuizQuestionVariant>(quizId, totalIndex, {
|
||||
content: { ...question.content, variants: answerNew },
|
||||
@ -89,123 +76,79 @@ export const AnswerItem = ({
|
||||
});
|
||||
};
|
||||
|
||||
const changeAnswerHint = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const answerNew = variants.slice();
|
||||
answerNew[index].hints = event.target.value;
|
||||
|
||||
updateQuestionsList<QuizQuestionVariant>(quizId, totalIndex, {
|
||||
content: { ...question.content, variants: answerNew },
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Draggable draggableId={String(index)} index={index}>
|
||||
{(provided) => (
|
||||
<Box ref={provided.innerRef} {...provided.draggableProps}>
|
||||
<FormControl
|
||||
key={index}
|
||||
fullWidth
|
||||
variant="standard"
|
||||
sx={{
|
||||
margin: isTablet ? " 15px 0 20px 0" : "0 0 20px 0",
|
||||
<Box>
|
||||
<FormControl
|
||||
key={index}
|
||||
fullWidth
|
||||
variant="standard"
|
||||
sx={{
|
||||
margin: isTablet ? " 15px 0 20px 0" : "0 0 20px 0",
|
||||
borderRadius: "10px",
|
||||
border: "1px solid rgba(0, 0, 0, 0.23)",
|
||||
background: "white",
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
defaultValue={variant.answer}
|
||||
fullWidth
|
||||
focused={false}
|
||||
placeholder={"Добавьте ответ"}
|
||||
multiline={question.content.largeCheck}
|
||||
onChange={({ target }) => debounced(target.value)}
|
||||
onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.code === "Enter" && !question.content.largeCheck) {
|
||||
addNewAnswer();
|
||||
}
|
||||
}}
|
||||
InputProps={{
|
||||
startAdornment: (
|
||||
<>
|
||||
<InputAdornment {...provided.droppableProps} position="start">
|
||||
<PointsIcon style={{ color: "#9A9AAF", fontSize: "30px" }} />
|
||||
</InputAdornment>
|
||||
{additionalContent}
|
||||
</>
|
||||
),
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<IconButton sx={{ padding: "0" }} onClick={deleteAnswer}>
|
||||
<DeleteIcon
|
||||
style={{
|
||||
color: theme.palette.grey2.main,
|
||||
marginRight: "-1px",
|
||||
}}
|
||||
/>
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
sx={{
|
||||
"& .MuiInputBase-root": {
|
||||
padding: additionalContent
|
||||
? isTablet
|
||||
? "13px"
|
||||
: "5px 13px"
|
||||
: "13px",
|
||||
borderRadius: "10px",
|
||||
border: "1px solid rgba(0, 0, 0, 0.23)",
|
||||
background: "white",
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
defaultValue={variant.answer}
|
||||
fullWidth
|
||||
focused={false}
|
||||
placeholder={"Добавьте ответ"}
|
||||
multiline={question.content.largeCheck}
|
||||
onChange={({ target }) => debounced(target.value)}
|
||||
onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.code === "Enter" && !question.content.largeCheck) {
|
||||
addNewAnswer();
|
||||
}
|
||||
}}
|
||||
InputProps={{
|
||||
startAdornment: (
|
||||
<>
|
||||
<InputAdornment
|
||||
{...provided.dragHandleProps}
|
||||
position="start"
|
||||
>
|
||||
<PointsIcon
|
||||
style={{ color: "#9A9AAF", fontSize: "30px" }}
|
||||
/>
|
||||
</InputAdornment>
|
||||
{additionalContent}
|
||||
</>
|
||||
),
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
sx={{ padding: "0" }}
|
||||
aria-describedby="my-popover-id"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<MessageIcon
|
||||
style={{
|
||||
color: "#9A9AAF",
|
||||
fontSize: "30px",
|
||||
marginRight: "6.5px",
|
||||
}}
|
||||
/>
|
||||
</IconButton>
|
||||
<Popover
|
||||
id="my-popover-id"
|
||||
open={isOpen}
|
||||
anchorEl={anchorEl}
|
||||
onClose={handleClose}
|
||||
anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
|
||||
>
|
||||
<TextareaAutosize
|
||||
style={{ margin: "10px" }}
|
||||
placeholder="Подсказка для этого ответа"
|
||||
value={variant.hints}
|
||||
onChange={changeAnswerHint}
|
||||
onKeyDown={(
|
||||
event: KeyboardEvent<HTMLTextAreaElement>
|
||||
) => event.stopPropagation()}
|
||||
/>
|
||||
</Popover>
|
||||
<IconButton sx={{ padding: "0" }} onClick={deleteAnswer}>
|
||||
<DeleteIcon
|
||||
style={{
|
||||
color: theme.palette.grey2.main,
|
||||
marginRight: "-1px",
|
||||
}}
|
||||
/>
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
sx={{
|
||||
"& .MuiInputBase-root": {
|
||||
padding: additionalContent ? "5px 13px" : "13px",
|
||||
borderRadius: "10px",
|
||||
background: "#ffffff",
|
||||
"& input.MuiInputBase-input": {
|
||||
height: "22px",
|
||||
},
|
||||
"& textarea.MuiInputBase-input": {
|
||||
marginTop: "1px",
|
||||
},
|
||||
"& .MuiOutlinedInput-notchedOutline": {
|
||||
border: "none",
|
||||
},
|
||||
},
|
||||
}}
|
||||
inputProps={{
|
||||
sx: { fontSize: "18px", lineHeight: "21px", py: 0, ml: "13px" },
|
||||
}}
|
||||
/>
|
||||
{additionalMobile}
|
||||
</FormControl>
|
||||
</Box>
|
||||
)}
|
||||
</Draggable>
|
||||
background: "#ffffff",
|
||||
"& input.MuiInputBase-input": {
|
||||
height: "22px",
|
||||
},
|
||||
"& textarea.MuiInputBase-input": {
|
||||
marginTop: "1px",
|
||||
},
|
||||
"& .MuiOutlinedInput-notchedOutline": {
|
||||
border: "none",
|
||||
},
|
||||
},
|
||||
}}
|
||||
inputProps={{
|
||||
sx: { fontSize: "18px", lineHeight: "21px", py: 0, ml: "13px" },
|
||||
}}
|
||||
/>
|
||||
{additionalMobile}
|
||||
</FormControl>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
@ -47,6 +47,7 @@ export const AnswerDraggableList = ({
|
||||
totalIndex={totalIndex}
|
||||
variants={variants}
|
||||
variant={variant}
|
||||
provided={provided}
|
||||
additionalContent={additionalContent?.(variant, index)}
|
||||
additionalMobile={additionalMobile?.(variant, index)}
|
||||
/>
|
||||
|
||||
@ -225,7 +225,7 @@ export default function QuestionsPageCard({
|
||||
sx={{
|
||||
margin: isMobile ? "10px 0" : 0,
|
||||
"& .MuiInputBase-root": {
|
||||
color: question.expanded ? "#9A9AAF" : "#4D4D4D",
|
||||
color: question.expanded ? "#000000" : "#4D4D4D",
|
||||
backgroundColor: question.expanded
|
||||
? theme.palette.background.default
|
||||
: "transparent",
|
||||
|
||||
@ -29,7 +29,7 @@ export default function DropDown({ totalIndex }: Props) {
|
||||
|
||||
const addNewAnswer = () => {
|
||||
const answerNew = question.content.variants.slice();
|
||||
answerNew.push({ answer: "", hints: "", extendedText: "" });
|
||||
answerNew.push({ answer: "", extendedText: "" });
|
||||
|
||||
updateQuestionsList<QuizQuestionSelect>(quizId, totalIndex, {
|
||||
content: { ...question.content, variants: answerNew },
|
||||
@ -94,12 +94,22 @@ export default function DropDown({ totalIndex }: Props) {
|
||||
>
|
||||
или нажмите Enter
|
||||
</Typography>
|
||||
<EnterIcon style={{ color: "#7E2AEA", fontSize: "24px", marginLeft: "6px" }} />
|
||||
<EnterIcon
|
||||
style={{
|
||||
color: "#7E2AEA",
|
||||
fontSize: "24px",
|
||||
marginLeft: "6px",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
<ButtonsOptions switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
||||
<ButtonsOptions
|
||||
switchState={switchState}
|
||||
SSHC={SSHC}
|
||||
totalIndex={totalIndex}
|
||||
/>
|
||||
<SwitchDropDown switchState={switchState} totalIndex={totalIndex} />
|
||||
</>
|
||||
);
|
||||
|
||||
@ -28,7 +28,9 @@ interface Props {
|
||||
export default function Emoji({ totalIndex }: Props) {
|
||||
const [switchState, setSwitchState] = useState<string>("setting");
|
||||
const [open, setOpen] = useState<boolean>(false);
|
||||
const [anchorElement, setAnchorElement] = useState<HTMLDivElement | null>(null);
|
||||
const [anchorElement, setAnchorElement] = useState<HTMLDivElement | null>(
|
||||
null
|
||||
);
|
||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||
const { listQuestions } = questionStore();
|
||||
const quizId = Number(useParams().quizId);
|
||||
@ -37,7 +39,6 @@ export default function Emoji({ totalIndex }: Props) {
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
||||
|
||||
|
||||
const SSHC = (data: string) => {
|
||||
setSwitchState(data);
|
||||
};
|
||||
@ -198,14 +199,21 @@ export default function Emoji({ totalIndex }: Props) {
|
||||
}}
|
||||
/>
|
||||
</Popover>
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: "10px", marginBottom: isMobile ? "17px" : "20px" }}>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "10px",
|
||||
marginBottom: isMobile ? "17px" : "20px",
|
||||
}}
|
||||
>
|
||||
<Link
|
||||
component="button"
|
||||
variant="body2"
|
||||
sx={{ color: theme.palette.brightPurple.main }}
|
||||
onClick={() => {
|
||||
const answerNew = question.content.variants.slice();
|
||||
answerNew.push({ answer: "", hints: "", extendedText: "" });
|
||||
answerNew.push({ answer: "", extendedText: "" });
|
||||
|
||||
updateQuestionsList<QuizQuestionEmoji>(quizId, totalIndex, {
|
||||
content: { ...question.content, variants: answerNew },
|
||||
@ -237,7 +245,11 @@ export default function Emoji({ totalIndex }: Props) {
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
<ButtonsOptions switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
||||
<ButtonsOptions
|
||||
switchState={switchState}
|
||||
SSHC={SSHC}
|
||||
totalIndex={totalIndex}
|
||||
/>
|
||||
<SwitchEmoji switchState={switchState} totalIndex={totalIndex} />
|
||||
</>
|
||||
);
|
||||
|
||||
@ -27,7 +27,7 @@ export default memo(
|
||||
{(provided) => (
|
||||
<ListItem
|
||||
ref={provided.innerRef}
|
||||
{...provided.draggableProps}
|
||||
{...(index !== 0 ? provided.draggableProps : {})}
|
||||
sx={{ userSelect: "none", padding: 0 }}
|
||||
>
|
||||
{questionData.deleted ? (
|
||||
|
||||
@ -147,11 +147,13 @@ export default function QuestionsPageCard({
|
||||
),
|
||||
endAdornment: (
|
||||
<>
|
||||
<InputAdornment {...draggableProps} position="start">
|
||||
<PointsIcon
|
||||
style={{ color: "#9A9AAF", fontSize: "30px" }}
|
||||
/>
|
||||
</InputAdornment>
|
||||
{totalIndex !== 0 && (
|
||||
<InputAdornment {...draggableProps} position="start">
|
||||
<PointsIcon
|
||||
style={{ color: "#9A9AAF", fontSize: "30px" }}
|
||||
/>
|
||||
</InputAdornment>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
}}
|
||||
|
||||
@ -15,6 +15,10 @@ export const FormDraggableList = () => {
|
||||
const { listQuestions } = questionStore();
|
||||
|
||||
const onDragEnd = ({ destination, source }: DropResult) => {
|
||||
if (destination?.index === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (destination) {
|
||||
const newItems = reorder(
|
||||
listQuestions[quizId],
|
||||
|
||||
@ -93,13 +93,6 @@ export default function FormQuestionsPage() {
|
||||
}}
|
||||
onClick={() => {
|
||||
createQuestion(quizId);
|
||||
updateQuestionsList<QuizQuestionBase>(
|
||||
quizId,
|
||||
listQuestions[quizId].length - 1 || 0,
|
||||
{
|
||||
expanded: true,
|
||||
}
|
||||
);
|
||||
}}
|
||||
>
|
||||
<AddAnswer color="#EEE4FC" />
|
||||
|
||||
@ -5,18 +5,14 @@ import { Box } from "@mui/material";
|
||||
import QuestionsMiniButton from "@ui_kit/QuestionsMiniButton";
|
||||
import ButtonsOptions from "../ButtonsOptions";
|
||||
import SwitchAnswerOptions from "../answerOptions/switchAnswerOptions";
|
||||
import { BUTTON_TYPE_QUESTIONS } from "../TypeQuestions";
|
||||
|
||||
import Answer from "../../../assets/icons/questionsPage/answer";
|
||||
import OptionsPict from "../../../assets/icons/questionsPage/options_pict";
|
||||
import OptionsAndPict from "../../../assets/icons/questionsPage/options_and_pict";
|
||||
import Emoji from "../../../assets/icons/questionsPage/emoji";
|
||||
import Input from "../../../assets/icons/questionsPage/input";
|
||||
import DropDown from "../../../assets/icons/questionsPage/drop_down";
|
||||
import Date from "../../../assets/icons/questionsPage/date";
|
||||
import Slider from "../../../assets/icons/questionsPage/slider";
|
||||
import Download from "../../../assets/icons/questionsPage/download";
|
||||
import Page from "../../../assets/icons/questionsPage/page";
|
||||
import RatingIcon from "../../../assets/icons/questionsPage/rating";
|
||||
|
||||
import {
|
||||
questionStore,
|
||||
@ -40,27 +36,12 @@ type ButtonTypeQuestion = {
|
||||
value: QuizQuestionType;
|
||||
};
|
||||
|
||||
export const BUTTON_TYPE_QUESTIONS: ButtonTypeQuestion[] = [
|
||||
const BUTTON_TYPE_SHORT_QUESTIONS: ButtonTypeQuestion[] = [
|
||||
{
|
||||
icon: <Answer color="#9A9AAF" />,
|
||||
title: "Варианты ответов",
|
||||
value: "variant",
|
||||
},
|
||||
{
|
||||
icon: <OptionsPict color="#9A9AAF" />,
|
||||
title: "Варианты с картинками",
|
||||
value: "images",
|
||||
},
|
||||
{
|
||||
icon: <OptionsAndPict color="#9A9AAF" />,
|
||||
title: "Варианты и картинка",
|
||||
value: "varimg",
|
||||
},
|
||||
{
|
||||
icon: <Emoji color="#9A9AAF" />,
|
||||
title: "Эмоджи",
|
||||
value: "emoji",
|
||||
},
|
||||
{
|
||||
icon: <Input color="#9A9AAF" />,
|
||||
title: "Своё поле для ввода",
|
||||
@ -86,16 +67,6 @@ export const BUTTON_TYPE_QUESTIONS: ButtonTypeQuestion[] = [
|
||||
title: "Загрузка файла",
|
||||
value: "file",
|
||||
},
|
||||
{
|
||||
icon: <Page color="#9A9AAF" />,
|
||||
title: "Страница",
|
||||
value: "page",
|
||||
},
|
||||
{
|
||||
icon: <RatingIcon color="#9A9AAF" />,
|
||||
title: "Рейтинг",
|
||||
value: "rating",
|
||||
},
|
||||
];
|
||||
|
||||
export default function FormTypeQuestions({ totalIndex }: Props) {
|
||||
@ -114,7 +85,10 @@ export default function FormTypeQuestions({ totalIndex }: Props) {
|
||||
margin: "20px",
|
||||
}}
|
||||
>
|
||||
{BUTTON_TYPE_QUESTIONS.map(({ icon, title, value }) => (
|
||||
{(totalIndex === 0
|
||||
? BUTTON_TYPE_QUESTIONS
|
||||
: BUTTON_TYPE_SHORT_QUESTIONS
|
||||
).map(({ icon, title, value }) => (
|
||||
<QuestionsMiniButton
|
||||
key={title}
|
||||
onClick={() => {
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
import { useState } from "react";
|
||||
import {
|
||||
Box,
|
||||
Link,
|
||||
Typography,
|
||||
useTheme,
|
||||
useMediaQuery,
|
||||
InputAdornment,
|
||||
IconButton,
|
||||
Button,
|
||||
Popover,
|
||||
TextareaAutosize,
|
||||
TextField,
|
||||
Box,
|
||||
Link,
|
||||
Typography,
|
||||
useTheme,
|
||||
useMediaQuery,
|
||||
InputAdornment,
|
||||
IconButton,
|
||||
Button,
|
||||
Popover,
|
||||
TextareaAutosize,
|
||||
TextField,
|
||||
} from "@mui/material";
|
||||
import { useParams } from "react-router-dom";
|
||||
|
||||
@ -35,423 +35,247 @@ import type { QuizQuestionVarImg } from "../../../model/questionTypes/varimg";
|
||||
import { produce } from "immer";
|
||||
|
||||
interface Props {
|
||||
totalIndex: number;
|
||||
totalIndex: number;
|
||||
}
|
||||
|
||||
export default function OptionsAndPicture({ totalIndex }: Props) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [opened, setOpened] = useState<boolean>(false);
|
||||
const [switchState, setSwitchState] = useState("setting");
|
||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||
const quizId = Number(useParams().quizId);
|
||||
const { listQuestions } = questionStore();
|
||||
const theme = useTheme();
|
||||
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||
const question = listQuestions[quizId][totalIndex] as QuizQuestionVarImg;
|
||||
const [open, setOpen] = useState(false);
|
||||
const [opened, setOpened] = useState<boolean>(false);
|
||||
const [switchState, setSwitchState] = useState("setting");
|
||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||
const quizId = Number(useParams().quizId);
|
||||
const { listQuestions } = questionStore();
|
||||
const theme = useTheme();
|
||||
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||
const question = listQuestions[quizId][totalIndex] as QuizQuestionVarImg;
|
||||
|
||||
const SSHC = (data: string) => {
|
||||
setSwitchState(data);
|
||||
};
|
||||
const SSHC = (data: string) => {
|
||||
setSwitchState(data);
|
||||
};
|
||||
|
||||
const uploadImage = (files: FileList | null) => {
|
||||
if (files?.length) {
|
||||
const [file] = Array.from(files);
|
||||
const uploadImage = (files: FileList | null) => {
|
||||
if (files?.length) {
|
||||
const [file] = Array.from(files);
|
||||
|
||||
const clonedContent = { ...question.content };
|
||||
clonedContent.variants[currentIndex].extendedText =
|
||||
URL.createObjectURL(file);
|
||||
updateQuestionsList<QuizQuestionVarImg>(quizId, totalIndex, {
|
||||
content: clonedContent,
|
||||
});
|
||||
const clonedContent = { ...question.content };
|
||||
clonedContent.variants[currentIndex].extendedText =
|
||||
URL.createObjectURL(file);
|
||||
updateQuestionsList<QuizQuestionVarImg>(quizId, totalIndex, {
|
||||
content: clonedContent,
|
||||
});
|
||||
|
||||
setOpen(false);
|
||||
setOpened(true);
|
||||
}
|
||||
};
|
||||
setOpen(false);
|
||||
setOpened(true);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box sx={{ pl: "20px", pr: "20px" }}>
|
||||
<AnswerDraggableList
|
||||
variants={question.content.variants}
|
||||
totalIndex={totalIndex}
|
||||
additionalContent={(variant, index) => (
|
||||
<>
|
||||
{!isMobile && (
|
||||
<Box
|
||||
sx={{ cursor: "pointer" }}
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "60px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
background: "#EEE4FC",
|
||||
borderRadius: "3px",
|
||||
margin: "0 10px",
|
||||
height: "40px",
|
||||
}}
|
||||
>
|
||||
<Box sx={{ display: "flex", width: "40px" }}>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
<PlusImage />
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<AddImage
|
||||
sx={{
|
||||
height: "40px",
|
||||
width: "60px",
|
||||
margin: "0 10px",
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
additionalMobile={(variant, index) => (
|
||||
<>
|
||||
{isMobile && (
|
||||
<Box
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
m: "8px",
|
||||
position: "relative",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
background: "#EEE4FC",
|
||||
height: "30px",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<Image
|
||||
sx={{
|
||||
height: "40px",
|
||||
width: "60px",
|
||||
margin: "0 10px",
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: "20px",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
color: "white",
|
||||
backgroundColor: "#7E2AEA",
|
||||
}}
|
||||
>
|
||||
+
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<UploadImageModal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
imgHC={uploadImage}
|
||||
/>
|
||||
<CropModal
|
||||
opened={opened}
|
||||
onClose={() => setOpened(false)}
|
||||
picture={question.content.variants[currentIndex]?.extendedText}
|
||||
onCropPress={url => {
|
||||
const content = produce(question.content, draft => {
|
||||
draft.variants[currentIndex].extendedText = url;
|
||||
});
|
||||
updateQuestionsList<QuizQuestionVarImg>(quizId, totalIndex, {
|
||||
content,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
return (
|
||||
<>
|
||||
<Box sx={{ pl: "20px", pr: "20px" }}>
|
||||
<AnswerDraggableList
|
||||
variants={question.content.variants}
|
||||
totalIndex={totalIndex}
|
||||
additionalContent={(variant, index) => (
|
||||
<>
|
||||
{!isMobile && (
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
border: "1px solid #9A9AAF",
|
||||
borderRadius: "8px",
|
||||
display: isTablet ? "block" : "none",
|
||||
}}
|
||||
sx={{ cursor: "pointer" }}
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
<TextField
|
||||
fullWidth
|
||||
focused={false}
|
||||
placeholder={"Добавьте ответ"}
|
||||
multiline={question.content.largeCheck}
|
||||
InputProps={{
|
||||
startAdornment: (
|
||||
<>
|
||||
<InputAdornment position="start">
|
||||
<PointsIcon
|
||||
style={{ color: "#9A9AAF", fontSize: "30px" }}
|
||||
/>
|
||||
</InputAdornment>
|
||||
{!isMobile && (
|
||||
<Box
|
||||
sx={{
|
||||
width: "60px",
|
||||
height: "40px",
|
||||
background: "#EEE4FC",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
marginRight: "20px",
|
||||
marginLeft: "12px",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<ImageAddIcons fontSize="22px" color="#7E2AEA" />
|
||||
</Box>
|
||||
<span
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
background: "#7E2AEA",
|
||||
height: "100%",
|
||||
width: "25px",
|
||||
color: "white",
|
||||
fontSize: "15px",
|
||||
}}
|
||||
>
|
||||
+
|
||||
</span>
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
<IconButton
|
||||
sx={{ padding: "0" }}
|
||||
aria-describedby="my-popover-id"
|
||||
>
|
||||
<MessageIcon
|
||||
style={{
|
||||
color: "#9A9AAF",
|
||||
fontSize: "30px",
|
||||
marginRight: "6.5px",
|
||||
}}
|
||||
/>
|
||||
</IconButton>
|
||||
<Popover
|
||||
id="my-popover-id"
|
||||
anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
|
||||
open={false}
|
||||
>
|
||||
<TextareaAutosize
|
||||
style={{ margin: "10px" }}
|
||||
placeholder="Подсказка для этого ответа"
|
||||
/>
|
||||
</Popover>
|
||||
<IconButton sx={{ padding: "0" }}>
|
||||
<DeleteIcon
|
||||
style={{
|
||||
color: theme.palette.grey2.main,
|
||||
marginRight: "-1px",
|
||||
}}
|
||||
/>
|
||||
</IconButton>
|
||||
</InputAdornment>
|
||||
),
|
||||
}}
|
||||
sx={{
|
||||
"& .MuiInputBase-root": {
|
||||
padding: "13.5px",
|
||||
borderRadius: "10px",
|
||||
background: "#ffffff",
|
||||
height: "48px",
|
||||
},
|
||||
"& .MuiOutlinedInput-notchedOutline": {
|
||||
border: "none",
|
||||
},
|
||||
}}
|
||||
inputProps={{
|
||||
sx: { fontSize: "18px", lineHeight: "21px", py: 0 },
|
||||
}}
|
||||
/>
|
||||
|
||||
{isMobile && (
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
m: "8px",
|
||||
position: "relative",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{ width: "100%", background: "#EEE4FC", height: "40px" }}
|
||||
/>
|
||||
<ImageAddIcons
|
||||
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
|
||||
sx={{ width: "100%", background: "#EEE4FC", height: "40px" }}
|
||||
/>
|
||||
<ImageAddIcons
|
||||
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>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "60px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
marginBottom: "17px",
|
||||
}}
|
||||
>
|
||||
<Link
|
||||
component="button"
|
||||
variant="body2"
|
||||
sx={{
|
||||
color: theme.palette.brightPurple.main,
|
||||
fontWeight: "400",
|
||||
fontSize: "16px",
|
||||
mr: "4px",
|
||||
height: "19px",
|
||||
}}
|
||||
onClick={() => {
|
||||
const clonedContent = { ...question.content };
|
||||
clonedContent.variants.push({
|
||||
answer: "",
|
||||
hints: "",
|
||||
extendedText: "",
|
||||
});
|
||||
updateQuestionsList<QuizQuestionVarImg>(quizId, totalIndex, {
|
||||
content: clonedContent,
|
||||
});
|
||||
}}
|
||||
background: "#EEE4FC",
|
||||
borderRadius: "3px",
|
||||
margin: "0 10px",
|
||||
height: "40px",
|
||||
}}
|
||||
>
|
||||
Добавьте ответ
|
||||
</Link>
|
||||
{isMobile ? null : (
|
||||
<>
|
||||
<Typography
|
||||
sx={{
|
||||
fontWeight: 400,
|
||||
lineHeight: "21.33px",
|
||||
color: theme.palette.grey2.main,
|
||||
fontSize: "16px",
|
||||
}}
|
||||
>
|
||||
или нажмите Enter
|
||||
</Typography>
|
||||
<EnterIcon
|
||||
style={{
|
||||
color: "#7E2AEA",
|
||||
fontSize: "24px",
|
||||
marginLeft: "6px",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Box sx={{ display: "flex", width: "40px" }}>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
<PlusImage />
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<AddImage
|
||||
sx={{
|
||||
height: "40px",
|
||||
width: "60px",
|
||||
margin: "0 10px",
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
<ButtonsOptionsAndPict
|
||||
switchState={switchState}
|
||||
SSHC={SSHC}
|
||||
totalIndex={totalIndex}
|
||||
/>
|
||||
<SwitchOptionsAndPict switchState={switchState} totalIndex={totalIndex} />
|
||||
</>
|
||||
);
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
additionalMobile={(variant, index) => (
|
||||
<>
|
||||
{isMobile && (
|
||||
<Box
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
m: "8px",
|
||||
position: "relative",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
background: "#EEE4FC",
|
||||
height: "30px",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<Image
|
||||
sx={{
|
||||
height: "40px",
|
||||
width: "60px",
|
||||
margin: "0 10px",
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: "20px",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
color: "white",
|
||||
backgroundColor: "#7E2AEA",
|
||||
}}
|
||||
>
|
||||
+
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<UploadImageModal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
imgHC={uploadImage}
|
||||
/>
|
||||
<CropModal
|
||||
opened={opened}
|
||||
onClose={() => setOpened(false)}
|
||||
picture={question.content.variants[currentIndex]?.extendedText}
|
||||
onCropPress={(url) => {
|
||||
const content = produce(question.content, (draft) => {
|
||||
draft.variants[currentIndex].extendedText = url;
|
||||
});
|
||||
updateQuestionsList<QuizQuestionVarImg>(quizId, totalIndex, {
|
||||
content,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
marginBottom: "17px",
|
||||
}}
|
||||
>
|
||||
<Link
|
||||
component="button"
|
||||
variant="body2"
|
||||
sx={{
|
||||
color: theme.palette.brightPurple.main,
|
||||
fontWeight: "400",
|
||||
fontSize: "16px",
|
||||
mr: "4px",
|
||||
height: "19px",
|
||||
}}
|
||||
onClick={() => {
|
||||
const clonedContent = { ...question.content };
|
||||
clonedContent.variants.push({
|
||||
answer: "",
|
||||
extendedText: "",
|
||||
});
|
||||
updateQuestionsList<QuizQuestionVarImg>(quizId, totalIndex, {
|
||||
content: clonedContent,
|
||||
});
|
||||
}}
|
||||
>
|
||||
Добавьте ответ
|
||||
</Link>
|
||||
{isMobile ? null : (
|
||||
<>
|
||||
<Typography
|
||||
sx={{
|
||||
fontWeight: 400,
|
||||
lineHeight: "21.33px",
|
||||
color: theme.palette.grey2.main,
|
||||
fontSize: "16px",
|
||||
}}
|
||||
>
|
||||
или нажмите Enter
|
||||
</Typography>
|
||||
<EnterIcon
|
||||
style={{
|
||||
color: "#7E2AEA",
|
||||
fontSize: "24px",
|
||||
marginLeft: "6px",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
<ButtonsOptionsAndPict
|
||||
switchState={switchState}
|
||||
SSHC={SSHC}
|
||||
totalIndex={totalIndex}
|
||||
/>
|
||||
<SwitchOptionsAndPict switchState={switchState} totalIndex={totalIndex} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import {
|
||||
Box,
|
||||
Link,
|
||||
Typography,
|
||||
Button,
|
||||
useTheme,
|
||||
useMediaQuery
|
||||
Box,
|
||||
Link,
|
||||
Typography,
|
||||
Button,
|
||||
useTheme,
|
||||
useMediaQuery,
|
||||
} from "@mui/material";
|
||||
|
||||
import ButtonsOptions from "../ButtonsOptions";
|
||||
@ -25,227 +25,234 @@ import type { QuizQuestionImages } from "../../../model/questionTypes/images";
|
||||
import { produce } from "immer";
|
||||
|
||||
interface Props {
|
||||
totalIndex: number;
|
||||
totalIndex: number;
|
||||
}
|
||||
|
||||
export default function OptionsPicture({ totalIndex }: Props) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [opened, setOpened] = useState<boolean>(false);
|
||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||
const isTablet = useMediaQuery(theme.breakpoints.down(790));
|
||||
const quizId = Number(useParams().quizId);
|
||||
const [switchState, setSwitchState] = useState("setting");
|
||||
const { listQuestions } = questionStore();
|
||||
const question = listQuestions[quizId][totalIndex] as QuizQuestionImages;
|
||||
const [open, setOpen] = useState(false);
|
||||
const [opened, setOpened] = useState<boolean>(false);
|
||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||
const isTablet = useMediaQuery(theme.breakpoints.down(790));
|
||||
const quizId = Number(useParams().quizId);
|
||||
const [switchState, setSwitchState] = useState("setting");
|
||||
const { listQuestions } = questionStore();
|
||||
const question = listQuestions[quizId][totalIndex] as QuizQuestionImages;
|
||||
|
||||
const SSHC = (data: string) => {
|
||||
setSwitchState(data);
|
||||
};
|
||||
const SSHC = (data: string) => {
|
||||
setSwitchState(data);
|
||||
};
|
||||
|
||||
const uploadImage = (files: FileList | null) => {
|
||||
if (files?.length) {
|
||||
const [file] = Array.from(files);
|
||||
const uploadImage = (files: FileList | null) => {
|
||||
if (files?.length) {
|
||||
const [file] = Array.from(files);
|
||||
|
||||
const clonedContent = { ...question.content };
|
||||
clonedContent.variants[currentIndex].extendedText =
|
||||
URL.createObjectURL(file);
|
||||
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
||||
content: clonedContent,
|
||||
});
|
||||
const clonedContent = { ...question.content };
|
||||
clonedContent.variants[currentIndex].extendedText =
|
||||
URL.createObjectURL(file);
|
||||
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
||||
content: clonedContent,
|
||||
});
|
||||
|
||||
setOpen(false);
|
||||
setOpened(true);
|
||||
}
|
||||
};
|
||||
setOpen(false);
|
||||
setOpened(true);
|
||||
}
|
||||
};
|
||||
|
||||
const addNewAnswer = () => {
|
||||
const answerNew = question.content.variants.slice();
|
||||
answerNew.push({ answer: "", hints: "", extendedText: "" });
|
||||
const addNewAnswer = () => {
|
||||
const answerNew = question.content.variants.slice();
|
||||
answerNew.push({ answer: "", extendedText: "" });
|
||||
|
||||
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
||||
content: { ...question.content, variants: answerNew },
|
||||
});
|
||||
};
|
||||
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
||||
content: { ...question.content, variants: answerNew },
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box sx={{ padding: "20px" }}>
|
||||
<AnswerDraggableList
|
||||
variants={question.content.variants}
|
||||
totalIndex={totalIndex}
|
||||
additionalContent={(variant, index) => (
|
||||
<>
|
||||
{!isMobile && (
|
||||
<Box
|
||||
sx={{ cursor: "pointer" }}
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "60px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
background: "#EEE4FC",
|
||||
borderRadius: "3px",
|
||||
margin: "0 10px",
|
||||
height: "40px",
|
||||
}}
|
||||
>
|
||||
<Box sx={{ display: "flex", width: "40px" }}>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
<PlusImage />
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<AddImage
|
||||
sx={{ height: "40px", width: "60px", margin: "0 10px" }}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
additionalMobile={(variant, index) => (
|
||||
<>
|
||||
{isMobile && (
|
||||
<Box
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
m: "8px",
|
||||
position: "relative",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
background: "#EEE4FC",
|
||||
height: "30px",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<Image
|
||||
sx={{
|
||||
height: "40px",
|
||||
width: "60px",
|
||||
margin: "0 10px",
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: "20px",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
color: "white",
|
||||
backgroundColor: "#7E2AEA",
|
||||
}}
|
||||
>
|
||||
+
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<UploadImageModal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
imgHC={uploadImage}
|
||||
/>
|
||||
<CropModal
|
||||
opened={opened}
|
||||
onClose={() => setOpened(false)}
|
||||
picture={question.content.variants[currentIndex]?.extendedText}
|
||||
onCropPress={url => {
|
||||
const content = produce(question.content, draft => {
|
||||
draft.variants[currentIndex].extendedText = url;
|
||||
});
|
||||
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
||||
content,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
||||
<Link
|
||||
component="button"
|
||||
variant="body2"
|
||||
sx={{ color: theme.palette.brightPurple.main }}
|
||||
onClick={addNewAnswer}
|
||||
return (
|
||||
<>
|
||||
<Box sx={{ padding: "20px" }}>
|
||||
<AnswerDraggableList
|
||||
variants={question.content.variants}
|
||||
totalIndex={totalIndex}
|
||||
additionalContent={(variant, index) => (
|
||||
<>
|
||||
{!isMobile && (
|
||||
<Box
|
||||
sx={{ cursor: "pointer" }}
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "60px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
background: "#EEE4FC",
|
||||
borderRadius: "3px",
|
||||
margin: "0 10px",
|
||||
height: "40px",
|
||||
}}
|
||||
>
|
||||
Добавьте ответ
|
||||
</Link>
|
||||
{isMobile ? null : (
|
||||
<>
|
||||
<Typography
|
||||
sx={{
|
||||
fontWeight: 400,
|
||||
lineHeight: "21.33px",
|
||||
color: theme.palette.grey2.main,
|
||||
fontSize: "16px",
|
||||
}}
|
||||
>
|
||||
или нажмите Enter
|
||||
</Typography>
|
||||
<EnterIcon
|
||||
style={{
|
||||
color: "#7E2AEA",
|
||||
fontSize: "24px",
|
||||
marginLeft: "6px",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Box sx={{ display: "flex", width: "40px" }}>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
<PlusImage />
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<AddImage
|
||||
sx={{ height: "40px", width: "60px", margin: "0 10px" }}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
<ButtonsOptions switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
||||
<SwitchAnswerOptionsPict switchState={switchState} totalIndex={totalIndex} />
|
||||
</>
|
||||
);
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
additionalMobile={(variant, index) => (
|
||||
<>
|
||||
{isMobile && (
|
||||
<Box
|
||||
onClick={() => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
}}
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
m: "8px",
|
||||
position: "relative",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
width: "100%",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<Box
|
||||
sx={{
|
||||
overflow: "hidden",
|
||||
width: "40px",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
background: "#EEE4FC",
|
||||
height: "30px",
|
||||
borderRadius: "3px",
|
||||
}}
|
||||
>
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt=""
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
<Button component="label" sx={{ padding: "0px" }}>
|
||||
<Image
|
||||
sx={{
|
||||
height: "40px",
|
||||
width: "60px",
|
||||
margin: "0 10px",
|
||||
}}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
width: "20px",
|
||||
background: "#EEE4FC",
|
||||
height: "40px",
|
||||
color: "white",
|
||||
backgroundColor: "#7E2AEA",
|
||||
}}
|
||||
>
|
||||
+
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
<UploadImageModal
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
imgHC={uploadImage}
|
||||
/>
|
||||
<CropModal
|
||||
opened={opened}
|
||||
onClose={() => setOpened(false)}
|
||||
picture={question.content.variants[currentIndex]?.extendedText}
|
||||
onCropPress={(url) => {
|
||||
const content = produce(question.content, (draft) => {
|
||||
draft.variants[currentIndex].extendedText = url;
|
||||
});
|
||||
updateQuestionsList<QuizQuestionImages>(quizId, totalIndex, {
|
||||
content,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
|
||||
<Link
|
||||
component="button"
|
||||
variant="body2"
|
||||
sx={{ color: theme.palette.brightPurple.main }}
|
||||
onClick={addNewAnswer}
|
||||
>
|
||||
Добавьте ответ
|
||||
</Link>
|
||||
{isMobile ? null : (
|
||||
<>
|
||||
<Typography
|
||||
sx={{
|
||||
fontWeight: 400,
|
||||
lineHeight: "21.33px",
|
||||
color: theme.palette.grey2.main,
|
||||
fontSize: "16px",
|
||||
}}
|
||||
>
|
||||
или нажмите Enter
|
||||
</Typography>
|
||||
<EnterIcon
|
||||
style={{
|
||||
color: "#7E2AEA",
|
||||
fontSize: "24px",
|
||||
marginLeft: "6px",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
<ButtonsOptions
|
||||
switchState={switchState}
|
||||
SSHC={SSHC}
|
||||
totalIndex={totalIndex}
|
||||
/>
|
||||
<SwitchAnswerOptionsPict
|
||||
switchState={switchState}
|
||||
totalIndex={totalIndex}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
IconButton,
|
||||
Typography,
|
||||
useMediaQuery,
|
||||
useTheme,
|
||||
Box,
|
||||
Button,
|
||||
IconButton,
|
||||
Typography,
|
||||
useMediaQuery,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import AddPlus from "../../assets/icons/questionsPage/addPlus";
|
||||
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
|
||||
import { quizStore } from "@root/quizes";
|
||||
import { useParams } from "react-router-dom";
|
||||
import {
|
||||
questionStore,
|
||||
createQuestion,
|
||||
updateQuestionsList,
|
||||
questionStore,
|
||||
createQuestion,
|
||||
updateQuestionsList,
|
||||
} from "@root/questions";
|
||||
import { DraggableList } from "./DraggableList";
|
||||
|
||||
@ -22,17 +22,17 @@ import QuizPreview from "@ui_kit/QuizPreview/QuizPreview";
|
||||
import { createPortal } from "react-dom";
|
||||
|
||||
export default function QuestionsPage() {
|
||||
const { listQuizes, updateQuizesList } = quizStore();
|
||||
const quizId = Number(useParams().quizId);
|
||||
const { listQuestions } = questionStore();
|
||||
const handleNext = () => {
|
||||
updateQuizesList(quizId, { step: listQuizes[quizId].step + 1 });
|
||||
};
|
||||
const { listQuizes, updateQuizesList } = quizStore();
|
||||
const quizId = Number(useParams().quizId);
|
||||
const { listQuestions } = questionStore();
|
||||
const handleNext = () => {
|
||||
updateQuizesList(quizId, { step: listQuizes[quizId].step + 1 });
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
let result = listQuizes[quizId].step - 1;
|
||||
updateQuizesList(quizId, { step: result ? result : 1 });
|
||||
};
|
||||
const handleBack = () => {
|
||||
let result = listQuizes[quizId].step - 1;
|
||||
updateQuizesList(quizId, { step: result ? result : 1 });
|
||||
};
|
||||
|
||||
const collapseEverything = () => {
|
||||
listQuestions[quizId].forEach((item, index) => {
|
||||
@ -43,12 +43,11 @@ export default function QuestionsPage() {
|
||||
});
|
||||
};
|
||||
|
||||
const theme = useTheme();
|
||||
const isTablet = useMediaQuery(theme.breakpoints.up(1000));
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* <Stepper activeStep={activeStep} desc={"Задайте вопросы"} /> */}
|
||||
<Box
|
||||
sx={{
|
||||
maxWidth: "796px",
|
||||
@ -85,10 +84,15 @@ export default function QuestionsPage() {
|
||||
onClick={() => {
|
||||
createQuestion(quizId);
|
||||
}}
|
||||
sx={{
|
||||
position: "fixed",
|
||||
left: isMobile ? "20px" : "250px",
|
||||
bottom: "20px",
|
||||
}}
|
||||
>
|
||||
<AddPlus />
|
||||
</IconButton>
|
||||
<Box sx={{ display: "flex", gap: "8px" }}>
|
||||
<Box sx={{ display: "flex", gap: "8px", marginLeft: "auto" }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
sx={{ padding: "10px 20px", borderRadius: "8px", height: "44px" }}
|
||||
|
||||
@ -27,7 +27,7 @@ export default function AnswerOptions({ totalIndex }: Props) {
|
||||
|
||||
const addNewAnswer = () => {
|
||||
const answerNew = question.content.variants.slice();
|
||||
answerNew.push({ answer: "", hints: "", extendedText: "" });
|
||||
answerNew.push({ answer: "", extendedText: "" });
|
||||
|
||||
updateQuestionsList<QuizQuestionVariant>(quizId, totalIndex, {
|
||||
content: { ...question.content, variants: answerNew },
|
||||
@ -89,12 +89,22 @@ export default function AnswerOptions({ totalIndex }: Props) {
|
||||
>
|
||||
или нажмите Enter
|
||||
</Typography>
|
||||
<EnterIcon style={{ color: "#7E2AEA", fontSize: "24px", marginLeft: "6px" }} />
|
||||
<EnterIcon
|
||||
style={{
|
||||
color: "#7E2AEA",
|
||||
fontSize: "24px",
|
||||
marginLeft: "6px",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
<ButtonsOptionsAndPict switchState={switchState} SSHC={SSHC} totalIndex={totalIndex} />
|
||||
<ButtonsOptionsAndPict
|
||||
switchState={switchState}
|
||||
SSHC={SSHC}
|
||||
totalIndex={totalIndex}
|
||||
/>
|
||||
<SwitchAnswerOptions switchState={switchState} totalIndex={totalIndex} />
|
||||
</>
|
||||
);
|
||||
|
||||
@ -126,7 +126,7 @@ export const quizStore = create<QuizStore>()(
|
||||
"logo": "hub.pena.digital/img/logo",
|
||||
"startpage": {
|
||||
"description": "",// приветственный текст опроса
|
||||
"button": "Начать", // текст на кнопке начала опроса
|
||||
"button": "", // текст на кнопке начала опроса
|
||||
"position": "ltr", // ltr или rtl. отображение элементов поверх фона
|
||||
"background": {
|
||||
"type": "image", //image или video
|
||||
@ -137,11 +137,11 @@ export const quizStore = create<QuizStore>()(
|
||||
},
|
||||
},
|
||||
"info": {
|
||||
"phonenumber": "+79885895677",
|
||||
"phonenumber": "",
|
||||
"clickable": true,
|
||||
"orgname": "ООО \"Пена\"",
|
||||
"site": "hub.pena.digital",
|
||||
"law": "юридическая информация"
|
||||
"orgname": "",
|
||||
"site": "",
|
||||
"law": ""
|
||||
},
|
||||
"meta": "что-то"
|
||||
}
|
||||
|
||||
@ -1,130 +1,132 @@
|
||||
import { PointsIcon } from "@icons/questionsPage/PointsIcon";
|
||||
import { Box, IconButton } from "@mui/material";
|
||||
import { toggleQuizPreview, useQuizPreviewStore } from "@root/quizPreview";
|
||||
import { useLayoutEffect, useRef } from "react";
|
||||
import { Rnd } from "react-rnd";
|
||||
import QuizPreviewLayout from "./QuizPreviewLayout";
|
||||
import ResizeIcon from "./ResizeIcon";
|
||||
import VisibilityIcon from '@mui/icons-material/Visibility';
|
||||
import VisibilityIcon from "@mui/icons-material/Visibility";
|
||||
|
||||
|
||||
const DRAG_PARENT_MARGIN = 25;
|
||||
const NAVBAR_HEIGHT = 81;
|
||||
const DRAG_PARENT_BOTTOM_MARGIN = 65;
|
||||
const DRAG_PARENT_MARGIN = 0;
|
||||
const NAVBAR_HEIGHT = 0;
|
||||
const DRAG_PARENT_BOTTOM_MARGIN = 0;
|
||||
|
||||
interface RndPositionAndSize {
|
||||
x: number;
|
||||
y: number;
|
||||
width: string;
|
||||
height: string;
|
||||
x: number;
|
||||
y: number;
|
||||
width: string;
|
||||
height: string;
|
||||
}
|
||||
|
||||
export default function QuizPreview() {
|
||||
const isPreviewShown = useQuizPreviewStore(state => state.isPreviewShown);
|
||||
const rndParentRef = useRef<HTMLDivElement>(null);
|
||||
const rndRef = useRef<Rnd | null>(null);
|
||||
const rndPositionAndSizeRef = useRef<RndPositionAndSize>({ x: 0, y: 0, width: "340", height: "480" });
|
||||
const isFirstShowRef = useRef<boolean>(true);
|
||||
const isPreviewShown = useQuizPreviewStore((state) => state.isPreviewShown);
|
||||
const rndParentRef = useRef<HTMLDivElement>(null);
|
||||
const rndRef = useRef<Rnd | null>(null);
|
||||
const rndPositionAndSizeRef = useRef<RndPositionAndSize>({
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: "340",
|
||||
height: "480",
|
||||
});
|
||||
const isFirstShowRef = useRef<boolean>(true);
|
||||
|
||||
useLayoutEffect(function stickPreviewToBottomRight() {
|
||||
const rnd = rndRef.current;
|
||||
const rndSelfElement = rnd?.getSelfElement();
|
||||
if (!rnd || !rndSelfElement || !rndParentRef.current || !isFirstShowRef.current) return;
|
||||
useLayoutEffect(
|
||||
function stickPreviewToBottomRight() {
|
||||
const rnd = rndRef.current;
|
||||
const rndSelfElement = rnd?.getSelfElement();
|
||||
if (
|
||||
!rnd ||
|
||||
!rndSelfElement ||
|
||||
!rndParentRef.current ||
|
||||
!isFirstShowRef.current
|
||||
)
|
||||
return;
|
||||
|
||||
const rndParentRect = rndParentRef.current.getBoundingClientRect();
|
||||
const rndRect = rndSelfElement.getBoundingClientRect();
|
||||
const rndParentRect = rndParentRef.current.getBoundingClientRect();
|
||||
const rndRect = rndSelfElement.getBoundingClientRect();
|
||||
|
||||
const x = rndParentRect.width - rndRect.width;
|
||||
const y = rndParentRect.height - rndRect.height;
|
||||
const x = rndParentRect.width - rndRect.width;
|
||||
const y = rndParentRect.height - rndRect.height;
|
||||
|
||||
rnd.updatePosition({ x, y });
|
||||
rndPositionAndSizeRef.current.x = x;
|
||||
rndPositionAndSizeRef.current.y = y;
|
||||
rnd.updatePosition({ x, y });
|
||||
rndPositionAndSizeRef.current.x = x;
|
||||
rndPositionAndSizeRef.current.y = y;
|
||||
|
||||
isFirstShowRef.current = false;
|
||||
}, [isPreviewShown]);
|
||||
isFirstShowRef.current = false;
|
||||
},
|
||||
[isPreviewShown]
|
||||
);
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={rndParentRef}
|
||||
sx={{
|
||||
position: "fixed",
|
||||
top: NAVBAR_HEIGHT + DRAG_PARENT_MARGIN,
|
||||
left: DRAG_PARENT_MARGIN,
|
||||
bottom: DRAG_PARENT_BOTTOM_MARGIN,
|
||||
right: DRAG_PARENT_MARGIN,
|
||||
// backgroundColor: "rgba(0, 100, 0, 0.2)",
|
||||
pointerEvents: "none",
|
||||
zIndex: 100,
|
||||
}}
|
||||
return (
|
||||
<Box
|
||||
ref={rndParentRef}
|
||||
sx={{
|
||||
position: "fixed",
|
||||
top: NAVBAR_HEIGHT + DRAG_PARENT_MARGIN,
|
||||
left: DRAG_PARENT_MARGIN,
|
||||
bottom: DRAG_PARENT_BOTTOM_MARGIN,
|
||||
right: DRAG_PARENT_MARGIN,
|
||||
// backgroundColor: "rgba(0, 100, 0, 0.2)",
|
||||
pointerEvents: "none",
|
||||
zIndex: 100,
|
||||
}}
|
||||
>
|
||||
{isPreviewShown && (
|
||||
<Rnd
|
||||
minHeight={20}
|
||||
minWidth={20}
|
||||
bounds="parent"
|
||||
ref={rndRef}
|
||||
dragHandleClassName="quiz-preview-draghandle"
|
||||
default={{
|
||||
x: rndPositionAndSizeRef.current.x,
|
||||
y: rndPositionAndSizeRef.current.y,
|
||||
width: rndPositionAndSizeRef.current.width,
|
||||
height: rndPositionAndSizeRef.current.height,
|
||||
}}
|
||||
onResizeStop={(e, direction, ref, delta, position) => {
|
||||
rndPositionAndSizeRef.current.x = position.x;
|
||||
rndPositionAndSizeRef.current.y = position.y;
|
||||
rndPositionAndSizeRef.current.width = ref.style.width;
|
||||
rndPositionAndSizeRef.current.height = ref.style.height;
|
||||
}}
|
||||
onDragStop={(e, d) => {
|
||||
rndPositionAndSizeRef.current.x = d.x;
|
||||
rndPositionAndSizeRef.current.y = d.y;
|
||||
}}
|
||||
onDragStart={(e, d) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
enableResizing={{
|
||||
topLeft: isPreviewShown,
|
||||
}}
|
||||
resizeHandleComponent={{
|
||||
topLeft: <ResizeIcon />,
|
||||
}}
|
||||
resizeHandleStyles={{
|
||||
topLeft: {
|
||||
top: "-1px",
|
||||
left: "-1px",
|
||||
},
|
||||
}}
|
||||
style={{
|
||||
overflow: "hidden",
|
||||
pointerEvents: "auto",
|
||||
}}
|
||||
>
|
||||
{isPreviewShown &&
|
||||
<Rnd
|
||||
minHeight={300}
|
||||
minWidth={340}
|
||||
bounds="parent"
|
||||
ref={rndRef}
|
||||
dragHandleClassName="quiz-preview-draghandle"
|
||||
default={{
|
||||
x: rndPositionAndSizeRef.current.x,
|
||||
y: rndPositionAndSizeRef.current.y,
|
||||
width: rndPositionAndSizeRef.current.width,
|
||||
height: rndPositionAndSizeRef.current.height
|
||||
}}
|
||||
onResizeStop={(e, direction, ref, delta, position) => {
|
||||
rndPositionAndSizeRef.current.x = position.x;
|
||||
rndPositionAndSizeRef.current.y = position.y;
|
||||
rndPositionAndSizeRef.current.width = ref.style.width;
|
||||
rndPositionAndSizeRef.current.height = ref.style.height;
|
||||
}}
|
||||
onDragStop={(e, d) => {
|
||||
rndPositionAndSizeRef.current.x = d.x;
|
||||
rndPositionAndSizeRef.current.y = d.y;
|
||||
}}
|
||||
onDragStart={(e, d) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
enableResizing={{
|
||||
topLeft: isPreviewShown,
|
||||
}}
|
||||
resizeHandleComponent={{
|
||||
topLeft: <ResizeIcon />
|
||||
}}
|
||||
resizeHandleStyles={{
|
||||
topLeft: {
|
||||
top: "-1px",
|
||||
left: "-1px",
|
||||
}
|
||||
}}
|
||||
style={{
|
||||
pointerEvents: "auto",
|
||||
}}
|
||||
>
|
||||
<QuizPreviewLayout />
|
||||
<IconButton
|
||||
className="quiz-preview-draghandle"
|
||||
sx={{
|
||||
position: "absolute",
|
||||
bottom: -54,
|
||||
right: 46,
|
||||
cursor: "move",
|
||||
}}
|
||||
>
|
||||
<PointsIcon style={{ color: "#4D4D4D", fontSize: "30px" }} />
|
||||
</IconButton>
|
||||
</Rnd>
|
||||
}
|
||||
<IconButton
|
||||
onClick={toggleQuizPreview}
|
||||
sx={{
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
bottom: -54,
|
||||
pointerEvents: "auto",
|
||||
}}
|
||||
>
|
||||
<VisibilityIcon sx={{ height: "30px", width: "30px" }} />
|
||||
</IconButton>
|
||||
</Box>
|
||||
);
|
||||
<QuizPreviewLayout />
|
||||
</Rnd>
|
||||
)}
|
||||
<IconButton
|
||||
onClick={toggleQuizPreview}
|
||||
sx={{
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
bottom: -54,
|
||||
pointerEvents: "auto",
|
||||
}}
|
||||
>
|
||||
<VisibilityIcon sx={{ height: "30px", width: "30px" }} />
|
||||
</IconButton>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import { Box, Button, LinearProgress, Paper, Typography } from "@mui/material";
|
||||
import { questionStore } from "@root/questions";
|
||||
import { decrementCurrentQuestionIndex, incrementCurrentQuestionIndex, useQuizPreviewStore } from "@root/quizPreview";
|
||||
import {
|
||||
decrementCurrentQuestionIndex,
|
||||
incrementCurrentQuestionIndex,
|
||||
useQuizPreviewStore,
|
||||
} from "@root/quizPreview";
|
||||
import { DefiniteQuestionType } from "model/questionTypes/shared";
|
||||
import { FC, useEffect } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
@ -17,117 +21,143 @@ import Text from "./QuizPreviewQuestionTypes/Text";
|
||||
import Variant from "./QuizPreviewQuestionTypes/Variant";
|
||||
import Varimg from "./QuizPreviewQuestionTypes/Varimg";
|
||||
|
||||
|
||||
const QuestionPreviewComponentByType: Record<DefiniteQuestionType, FC<any>> = {
|
||||
variant: Variant,
|
||||
images: Images,
|
||||
varimg: Varimg,
|
||||
emoji: Emoji,
|
||||
text: Text,
|
||||
select: Select,
|
||||
date: Date,
|
||||
number: Number,
|
||||
file: File,
|
||||
page: Page,
|
||||
rating: Rating,
|
||||
variant: Variant,
|
||||
images: Images,
|
||||
varimg: Varimg,
|
||||
emoji: Emoji,
|
||||
text: Text,
|
||||
select: Select,
|
||||
date: Date,
|
||||
number: Number,
|
||||
file: File,
|
||||
page: Page,
|
||||
rating: Rating,
|
||||
};
|
||||
|
||||
export default function QuizPreviewLayout() {
|
||||
const quizId = useParams().quizId ?? 0;
|
||||
const listQuestions = questionStore(state => state.listQuestions);
|
||||
const currentQuizStep = useQuizPreviewStore(state => state.currentQuestionIndex);
|
||||
const quizId = useParams().quizId ?? 0;
|
||||
const listQuestions = questionStore((state) => state.listQuestions);
|
||||
const currentQuizStep = useQuizPreviewStore(
|
||||
(state) => state.currentQuestionIndex
|
||||
);
|
||||
|
||||
const quizQuestions = listQuestions[quizId] ?? [];
|
||||
const nonDeletedQuizQuestions = quizQuestions.filter(question => !question.deleted);
|
||||
const maxCurrentQuizStep = nonDeletedQuizQuestions.length > 0 ? nonDeletedQuizQuestions.length - 1 : 0;
|
||||
const currentProgress = Math.floor((currentQuizStep / maxCurrentQuizStep) * 100);
|
||||
const quizQuestions = listQuestions[quizId] ?? [];
|
||||
const nonDeletedQuizQuestions = quizQuestions.filter(
|
||||
(question) => !question.deleted
|
||||
);
|
||||
const maxCurrentQuizStep =
|
||||
nonDeletedQuizQuestions.length > 0 ? nonDeletedQuizQuestions.length - 1 : 0;
|
||||
const currentProgress = Math.floor(
|
||||
(currentQuizStep / maxCurrentQuizStep) * 100
|
||||
);
|
||||
|
||||
const currentQuestion = nonDeletedQuizQuestions[currentQuizStep];
|
||||
const QuestionComponent = currentQuestion
|
||||
? QuestionPreviewComponentByType[currentQuestion.type as DefiniteQuestionType]
|
||||
: null;
|
||||
const currentQuestion = nonDeletedQuizQuestions[currentQuizStep];
|
||||
const QuestionComponent = currentQuestion
|
||||
? QuestionPreviewComponentByType[
|
||||
currentQuestion.type as DefiniteQuestionType
|
||||
]
|
||||
: null;
|
||||
|
||||
const questionElement = QuestionComponent
|
||||
? <QuestionComponent key={currentQuestion.id} question={currentQuestion} />
|
||||
: null;
|
||||
const questionElement = QuestionComponent ? (
|
||||
<QuestionComponent key={currentQuestion.id} question={currentQuestion} />
|
||||
) : null;
|
||||
|
||||
useEffect(function resetCurrentQuizStep() {
|
||||
if (currentQuizStep > maxCurrentQuizStep) {
|
||||
decrementCurrentQuestionIndex();
|
||||
}
|
||||
}, [currentQuizStep, maxCurrentQuizStep]);
|
||||
useEffect(
|
||||
function resetCurrentQuizStep() {
|
||||
if (currentQuizStep > maxCurrentQuizStep) {
|
||||
decrementCurrentQuestionIndex();
|
||||
}
|
||||
},
|
||||
[currentQuizStep, maxCurrentQuizStep]
|
||||
);
|
||||
|
||||
return (
|
||||
<Paper sx={{
|
||||
height: "100%",
|
||||
return (
|
||||
<Paper
|
||||
className="quiz-preview-draghandle"
|
||||
sx={{
|
||||
height: "100%",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
flexGrow: 1,
|
||||
borderRadius: "12px",
|
||||
pointerEvents: "auto",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
p: "16px",
|
||||
whiteSpace: "break-spaces",
|
||||
overflowY: "auto",
|
||||
flexGrow: 1,
|
||||
"&::-webkit-scrollbar": { width: 0 },
|
||||
}}
|
||||
>
|
||||
{questionElement}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
mt: "auto",
|
||||
p: "16px",
|
||||
display: "flex",
|
||||
borderTop: "1px solid #E3E3E3",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
flexGrow: 1,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
flexGrow: 1,
|
||||
borderRadius: "12px",
|
||||
pointerEvents: "auto",
|
||||
}}>
|
||||
<Box sx={{
|
||||
p: "16px",
|
||||
whiteSpace: "break-spaces",
|
||||
overflowY: "auto",
|
||||
flexGrow: 1,
|
||||
}}>
|
||||
{questionElement}
|
||||
</Box>
|
||||
<Box sx={{
|
||||
mt: "auto",
|
||||
p: "16px",
|
||||
display: "flex",
|
||||
borderTop: "1px solid #E3E3E3",
|
||||
alignItems: "center",
|
||||
}}>
|
||||
<Box sx={{
|
||||
flexGrow: 1,
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 1,
|
||||
}}>
|
||||
<Typography>
|
||||
{nonDeletedQuizQuestions.length > 0
|
||||
? `Вопрос ${currentQuizStep + 1} из ${nonDeletedQuizQuestions.length}`
|
||||
: "Нет вопросов"
|
||||
}
|
||||
</Typography>
|
||||
{nonDeletedQuizQuestions.length > 0 &&
|
||||
<LinearProgress
|
||||
variant="determinate"
|
||||
value={currentProgress}
|
||||
sx={{
|
||||
"&.MuiLinearProgress-colorPrimary": {
|
||||
backgroundColor: "fadePurple.main",
|
||||
},
|
||||
"& .MuiLinearProgress-barColorPrimary": {
|
||||
backgroundColor: "brightPurple.main",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
}
|
||||
</Box>
|
||||
<Box sx={{
|
||||
ml: 2,
|
||||
display: "flex",
|
||||
gap: 1,
|
||||
}}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={decrementCurrentQuestionIndex}
|
||||
disabled={currentQuizStep === 0}
|
||||
sx={{ px: 1, minWidth: 0 }}
|
||||
>
|
||||
<ArrowLeft />
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => incrementCurrentQuestionIndex(maxCurrentQuizStep)}
|
||||
disabled={currentQuizStep >= maxCurrentQuizStep}
|
||||
>Далее</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Paper>
|
||||
);
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
<Typography>
|
||||
{nonDeletedQuizQuestions.length > 0
|
||||
? `Вопрос ${currentQuizStep + 1} из ${
|
||||
nonDeletedQuizQuestions.length
|
||||
}`
|
||||
: "Нет вопросов"}
|
||||
</Typography>
|
||||
{nonDeletedQuizQuestions.length > 0 && (
|
||||
<LinearProgress
|
||||
variant="determinate"
|
||||
value={currentProgress}
|
||||
sx={{
|
||||
"&.MuiLinearProgress-colorPrimary": {
|
||||
backgroundColor: "fadePurple.main",
|
||||
},
|
||||
"& .MuiLinearProgress-barColorPrimary": {
|
||||
backgroundColor: "brightPurple.main",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
<Box
|
||||
sx={{
|
||||
ml: 2,
|
||||
display: "flex",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={decrementCurrentQuestionIndex}
|
||||
disabled={currentQuizStep === 0}
|
||||
sx={{ px: 1, minWidth: 0 }}
|
||||
>
|
||||
<ArrowLeft />
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={() => incrementCurrentQuestionIndex(maxCurrentQuizStep)}
|
||||
disabled={currentQuizStep >= maxCurrentQuizStep}
|
||||
>
|
||||
Далее
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Paper>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,39 +1,54 @@
|
||||
import InfoIcon from "@icons/InfoIcon";
|
||||
import { Box, FormControl, FormControlLabel, FormLabel, Radio, RadioGroup, Tooltip, Typography } from "@mui/material";
|
||||
import {
|
||||
Box,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
FormLabel,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { QuizQuestionEmoji } from "model/questionTypes/emoji";
|
||||
import { useState, ChangeEvent } from "react";
|
||||
|
||||
|
||||
interface Props {
|
||||
question: QuizQuestionEmoji;
|
||||
question: QuizQuestionEmoji;
|
||||
}
|
||||
|
||||
export default function Emoji({ question }: Props) {
|
||||
const [value, setValue] = useState<string | null>(null);
|
||||
const [value, setValue] = useState<string | null>(null);
|
||||
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setValue((event.target as HTMLInputElement).value);
|
||||
};
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setValue((event.target as HTMLInputElement).value);
|
||||
};
|
||||
|
||||
return (
|
||||
<FormControl fullWidth>
|
||||
<FormLabel id="quiz-question-radio-group">{question.title}</FormLabel>
|
||||
<RadioGroup
|
||||
aria-labelledby="quiz-question-radio-group"
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<FormControlLabel key={index} value={variant.answer} control={<Radio />} label={
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||
<Typography>{`${variant.extendedText} ${variant.answer}`}</Typography>
|
||||
<Tooltip title={variant.hints} placement="right">
|
||||
<Box><InfoIcon /></Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
} />
|
||||
))}
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
);
|
||||
return (
|
||||
<FormControl fullWidth>
|
||||
<FormLabel id="quiz-question-radio-group">{question.title}</FormLabel>
|
||||
<RadioGroup
|
||||
aria-labelledby="quiz-question-radio-group"
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<FormControlLabel
|
||||
key={index}
|
||||
value={variant.answer}
|
||||
control={<Radio />}
|
||||
label={
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||
<Typography>{`${variant.extendedText} ${variant.answer}`}</Typography>
|
||||
<Tooltip title="Подсказка" placement="right">
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,90 +1,107 @@
|
||||
import InfoIcon from "@icons/InfoIcon";
|
||||
import { Box, ButtonBase, Divider, Tooltip, Typography, useTheme } from "@mui/material";
|
||||
import {
|
||||
Box,
|
||||
ButtonBase,
|
||||
Divider,
|
||||
Tooltip,
|
||||
Typography,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import { QuizQuestionImages } from "model/questionTypes/images";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
|
||||
interface Props {
|
||||
question: QuizQuestionImages;
|
||||
question: QuizQuestionImages;
|
||||
}
|
||||
|
||||
export default function Images({ question }: Props) {
|
||||
const theme = useTheme();
|
||||
const [selectedVariants, setSelectedVariants] = useState<number[]>([]);
|
||||
const theme = useTheme();
|
||||
const [selectedVariants, setSelectedVariants] = useState<number[]>([]);
|
||||
|
||||
function handleVariantClick(index: number) {
|
||||
if (!question.content.multi) return setSelectedVariants([index]);
|
||||
function handleVariantClick(index: number) {
|
||||
if (!question.content.multi) return setSelectedVariants([index]);
|
||||
|
||||
const newSelectedVariants = [...selectedVariants];
|
||||
if (newSelectedVariants.includes(index)) {
|
||||
newSelectedVariants.splice(newSelectedVariants.indexOf(index), 1);
|
||||
} else {
|
||||
newSelectedVariants.push(index);
|
||||
}
|
||||
setSelectedVariants(newSelectedVariants);
|
||||
const newSelectedVariants = [...selectedVariants];
|
||||
if (newSelectedVariants.includes(index)) {
|
||||
newSelectedVariants.splice(newSelectedVariants.indexOf(index), 1);
|
||||
} else {
|
||||
newSelectedVariants.push(index);
|
||||
}
|
||||
setSelectedVariants(newSelectedVariants);
|
||||
}
|
||||
|
||||
useEffect(function resetSelectedVariants() {
|
||||
setSelectedVariants([]);
|
||||
}, [question.content.multi]);
|
||||
useEffect(
|
||||
function resetSelectedVariants() {
|
||||
setSelectedVariants([]);
|
||||
},
|
||||
[question.content.multi]
|
||||
);
|
||||
|
||||
return (
|
||||
<Box sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 1,
|
||||
}}>
|
||||
<Typography variant="h6">{question.title}</Typography>
|
||||
<Box sx={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(160px, 1fr))",
|
||||
gap: 1,
|
||||
}}>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<ButtonBase
|
||||
key={index}
|
||||
onClick={() => handleVariantClick(index)}
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
borderRadius: "8px",
|
||||
overflow: "hidden",
|
||||
border: "1px solid",
|
||||
borderColor: selectedVariants.includes(index) ? theme.palette.brightPurple.main : "#E3E3E3",
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ?
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt="question variant"
|
||||
style={{
|
||||
width: "100%",
|
||||
display: "block",
|
||||
objectFit: "scale-down",
|
||||
flexGrow: 1,
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<Typography p={2}>Картинка отсутствует</Typography>
|
||||
}
|
||||
<Divider sx={{ width: "100%" }} />
|
||||
<Box sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
gap: 2,
|
||||
p: 1,
|
||||
}}>
|
||||
<Typography>{variant.answer}</Typography>
|
||||
<Tooltip title={variant.hints} placement="right">
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
</ButtonBase>
|
||||
))}
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
<Typography variant="h6">{question.title}</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(160px, 1fr))",
|
||||
gap: 1,
|
||||
}}
|
||||
>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<ButtonBase
|
||||
key={index}
|
||||
onClick={() => handleVariantClick(index)}
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
borderRadius: "8px",
|
||||
overflow: "hidden",
|
||||
border: "1px solid",
|
||||
borderColor: selectedVariants.includes(index)
|
||||
? theme.palette.brightPurple.main
|
||||
: "#E3E3E3",
|
||||
}}
|
||||
>
|
||||
{variant.extendedText ? (
|
||||
<img
|
||||
src={variant.extendedText}
|
||||
alt="question variant"
|
||||
style={{
|
||||
width: "100%",
|
||||
display: "block",
|
||||
objectFit: "scale-down",
|
||||
flexGrow: 1,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<Typography p={2}>Картинка отсутствует</Typography>
|
||||
)}
|
||||
<Divider sx={{ width: "100%" }} />
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
gap: 2,
|
||||
p: 1,
|
||||
}}
|
||||
>
|
||||
<Typography>{variant.answer}</Typography>
|
||||
<Tooltip title="Подсказка" placement="right">
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
</ButtonBase>
|
||||
))}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,41 +1,54 @@
|
||||
import InfoIcon from "@icons/InfoIcon";
|
||||
import { Box, FormControl, FormControlLabel, FormLabel, Radio, RadioGroup, Tooltip, Typography } from "@mui/material";
|
||||
import {
|
||||
Box,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
FormLabel,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { QuizQuestionVariant } from "model/questionTypes/variant";
|
||||
import { ChangeEvent, useState } from "react";
|
||||
|
||||
|
||||
interface Props {
|
||||
question: QuizQuestionVariant;
|
||||
question: QuizQuestionVariant;
|
||||
}
|
||||
|
||||
export default function Variant({ question }: Props) {
|
||||
const [value, setValue] = useState<string | null>(null);
|
||||
const [value, setValue] = useState<string | null>(null);
|
||||
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setValue((event.target as HTMLInputElement).value);
|
||||
};
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setValue((event.target as HTMLInputElement).value);
|
||||
};
|
||||
|
||||
return (
|
||||
<FormControl fullWidth>
|
||||
<FormLabel id="quiz-question-radio-group">{question.title}</FormLabel>
|
||||
<RadioGroup
|
||||
aria-labelledby="quiz-question-radio-group"
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<FormControlLabel key={index} value={variant.answer} control={<Radio />} label={
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||
<Typography>{variant.answer}</Typography>
|
||||
<Tooltip title={variant.hints} placement="right">
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
} />
|
||||
))}
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
);
|
||||
return (
|
||||
<FormControl fullWidth>
|
||||
<FormLabel id="quiz-question-radio-group">{question.title}</FormLabel>
|
||||
<RadioGroup
|
||||
aria-labelledby="quiz-question-radio-group"
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<FormControlLabel
|
||||
key={index}
|
||||
value={variant.answer}
|
||||
control={<Radio />}
|
||||
label={
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||
<Typography>{variant.answer}</Typography>
|
||||
<Tooltip title="Подсказка" placement="right">
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,80 +1,99 @@
|
||||
import InfoIcon from "@icons/InfoIcon";
|
||||
import { Box, FormControl, FormControlLabel, FormLabel, Radio, RadioGroup, Tooltip, Typography } from "@mui/material";
|
||||
import {
|
||||
Box,
|
||||
FormControl,
|
||||
FormControlLabel,
|
||||
FormLabel,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { QuestionVariant } from "model/questionTypes/shared";
|
||||
import { QuizQuestionVarImg } from "model/questionTypes/varimg";
|
||||
import { useState, ChangeEvent } from "react";
|
||||
|
||||
|
||||
interface Props {
|
||||
question: QuizQuestionVarImg;
|
||||
question: QuizQuestionVarImg;
|
||||
}
|
||||
|
||||
export default function Varimg({ question }: Props) {
|
||||
const [selectedVariantIndex, setSelectedVariantIndex] = useState<number>(-1);
|
||||
const [selectedVariantIndex, setSelectedVariantIndex] = useState<number>(-1);
|
||||
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setSelectedVariantIndex(question.content.variants.findIndex(
|
||||
variant => variant.answer === event.target.value
|
||||
));
|
||||
};
|
||||
|
||||
const currentVariant: QuestionVariant | undefined = question.content.variants[selectedVariantIndex];
|
||||
|
||||
return (
|
||||
<Box sx={{
|
||||
display: "flex",
|
||||
flexWrap: "wrap",
|
||||
gap: 2,
|
||||
}}>
|
||||
<FormControl>
|
||||
<FormLabel id="quiz-question-radio-group">{question.title}</FormLabel>
|
||||
<RadioGroup
|
||||
aria-labelledby="quiz-question-radio-group"
|
||||
value={currentVariant?.answer ?? ""}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<FormControlLabel
|
||||
key={index}
|
||||
value={variant.answer}
|
||||
control={<Radio />}
|
||||
label={
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||
<Typography>{variant.answer}</Typography>
|
||||
<Tooltip title={variant.hints} placement="right">
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
<Box sx={{
|
||||
border: "1px solid #E3E3E3",
|
||||
maxWidth: "400px",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
borderRadius: "8px",
|
||||
}}>
|
||||
{currentVariant?.extendedText ?
|
||||
<img
|
||||
src={currentVariant.extendedText}
|
||||
alt="question variant"
|
||||
style={{
|
||||
width: "100%",
|
||||
display: "block",
|
||||
objectFit: "scale-down",
|
||||
flexGrow: 1,
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<Typography p={2}>{selectedVariantIndex === -1 ? "Выберите вариант" : "Картинка отсутствует"}</Typography>
|
||||
}
|
||||
</Box>
|
||||
</Box>
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setSelectedVariantIndex(
|
||||
question.content.variants.findIndex(
|
||||
(variant) => variant.answer === event.target.value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const currentVariant: QuestionVariant | undefined =
|
||||
question.content.variants[selectedVariantIndex];
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
flexWrap: "wrap",
|
||||
gap: 2,
|
||||
}}
|
||||
>
|
||||
<FormControl>
|
||||
<FormLabel id="quiz-question-radio-group">{question.title}</FormLabel>
|
||||
<RadioGroup
|
||||
aria-labelledby="quiz-question-radio-group"
|
||||
value={currentVariant?.answer ?? ""}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{question.content.variants.map((variant, index) => (
|
||||
<FormControlLabel
|
||||
key={index}
|
||||
value={variant.answer}
|
||||
control={<Radio />}
|
||||
label={
|
||||
<Box sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||
<Typography>{variant.answer}</Typography>
|
||||
<Tooltip title="Подсказка" placement="right">
|
||||
<Box>
|
||||
<InfoIcon />
|
||||
</Box>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</FormControl>
|
||||
<Box
|
||||
sx={{
|
||||
border: "1px solid #E3E3E3",
|
||||
maxWidth: "400px",
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
borderRadius: "8px",
|
||||
}}
|
||||
>
|
||||
{currentVariant?.extendedText ? (
|
||||
<img
|
||||
src={currentVariant.extendedText}
|
||||
alt="question variant"
|
||||
style={{
|
||||
width: "100%",
|
||||
display: "block",
|
||||
objectFit: "scale-down",
|
||||
flexGrow: 1,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<Typography p={2}>
|
||||
{selectedVariantIndex === -1
|
||||
? "Выберите вариант"
|
||||
: "Картинка отсутствует"}
|
||||
</Typography>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user