diff --git a/src/assets/icons/questionsPage/image.tsx b/src/assets/icons/questionsPage/image.tsx new file mode 100644 index 00000000..cccdcfd7 --- /dev/null +++ b/src/assets/icons/questionsPage/image.tsx @@ -0,0 +1,53 @@ +import { Box, SxProps } from "@mui/material"; +import { FC } from "react"; + +interface Iprops { + onClick?: () => void; + sx?: SxProps; +} + +const Image: FC = ({ onClick, sx }) => { + return ( + + + + + + + + ); +}; + +export default Image; diff --git a/src/assets/icons/questionsPage/plus.tsx b/src/assets/icons/questionsPage/plus.tsx index eddbe273..98b7fa83 100644 --- a/src/assets/icons/questionsPage/plus.tsx +++ b/src/assets/icons/questionsPage/plus.tsx @@ -13,8 +13,8 @@ export default function Plus() { > diff --git a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx index a9e3c86c..17ffb74c 100644 --- a/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx +++ b/src/pages/Questions/AnswerDraggableList/AnswerItem.tsx @@ -70,7 +70,7 @@ export const AnswerItem = ({ const addNewAnswer = () => { const answerNew = variants.slice(); - answerNew.push({ answer: "", hints: "", emoji: "" }); + answerNew.push({ answer: "", hints: "", emoji: "", image: "" }); updateQuestionsList(quizId, totalIndex, { content: { @@ -177,7 +177,6 @@ export const AnswerItem = ({ ), }} sx={{ - padding: isTablet ? "10px 0px" : 0, "& .MuiInputBase-root": { minHeight: "48px", borderRadius: "10px", diff --git a/src/pages/Questions/DropDown/DropDown.tsx b/src/pages/Questions/DropDown/DropDown.tsx index 95dc201c..80e4b41b 100644 --- a/src/pages/Questions/DropDown/DropDown.tsx +++ b/src/pages/Questions/DropDown/DropDown.tsx @@ -27,7 +27,7 @@ export default function DropDown({ totalIndex }: Props) { const addNewAnswer = () => { const answerNew = variants.slice(); - answerNew.push({ answer: "", hints: "", emoji: "" }); + answerNew.push({ answer: "", hints: "", emoji: "", image: "" }); updateQuestionsList(quizId, totalIndex, { content: { diff --git a/src/pages/Questions/Emoji/Emoji.tsx b/src/pages/Questions/Emoji/Emoji.tsx index cdfa43c8..2bf7aee1 100644 --- a/src/pages/Questions/Emoji/Emoji.tsx +++ b/src/pages/Questions/Emoji/Emoji.tsx @@ -18,8 +18,8 @@ import { EmojiIcons } from "@icons/EmojiIocns"; import { questionStore, updateQuestionsList } from "@root/questions"; -import AddEmoji from "../../../assets/icons/questionsPage/addEmoji"; -import PlusImage from "../../../assets/icons/questionsPage/plus"; +import AddEmoji from "@icons/questionsPage/addEmoji"; +import PlusImage from "@icons/questionsPage/plus"; interface Props { totalIndex: number; @@ -199,7 +199,7 @@ export default function Emoji({ totalIndex }: Props) { onClick={() => { const answerNew = listQuestions[quizId][totalIndex].content.variants.slice(); - answerNew.push({ answer: "", hints: "", emoji: "" }); + answerNew.push({ answer: "", hints: "", emoji: "", image: "" }); updateQuestionsList(quizId, totalIndex, { content: { diff --git a/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx b/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx index 3a519398..dd72ca94 100644 --- a/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx +++ b/src/pages/Questions/OptionsAndPicture/OptionsAndPicture.tsx @@ -197,7 +197,12 @@ export default function OptionsAndPicture({ totalIndex }: Props) { sx={{ color: theme.palette.brightPurple.main }} onClick={() => { const clonContent = listQuestions[quizId][totalIndex].content; - clonContent.variants.push({ answer: "", hints: "", emoji: "" }); + clonContent.variants.push({ + answer: "", + hints: "", + emoji: "", + image: "", + }); updateQuestionsList(quizId, totalIndex, { content: clonContent }); }} diff --git a/src/pages/Questions/OptionsPicture/OptionsPicture.tsx b/src/pages/Questions/OptionsPicture/OptionsPicture.tsx index 27d75747..9e8686eb 100644 --- a/src/pages/Questions/OptionsPicture/OptionsPicture.tsx +++ b/src/pages/Questions/OptionsPicture/OptionsPicture.tsx @@ -7,33 +7,29 @@ import { Button, useTheme, useMediaQuery, - InputAdornment, - IconButton, - TextareaAutosize, - Popover, - TextField, } from "@mui/material"; import ButtonsOptions from "../ButtonsOptions"; +import { AnswerDraggableList } from "../AnswerDraggableList"; +import { CropModal } from "@ui_kit/Modal/CropModal"; +import { UploadImageModal } from "../UploadImage/UploadImageModal"; import { questionStore, updateQuestionsList } from "@root/questions"; import EnterIcon from "../../../assets/icons/questionsPage/enterIcon"; import AddImage from "../../../assets/icons/questionsPage/addImage"; +import Image from "../../../assets/icons/questionsPage/image"; import SwitchAnswerOptionsPict from "./switchOptionsPict"; - -import type { ChangeEvent } from "react"; -import PointsIcon from "@icons/questionsPage/PointsIcon"; -import MessageIcon from "@icons/messagIcon"; -import DeleteIcon from "@icons/questionsPage/deleteIcon"; -import { ImageAddIcons } from "@icons/ImageAddIcons"; +import PlusImage from "@icons/questionsPage/plus"; interface Props { totalIndex: number; } export default function OptionsPicture({ totalIndex }: Props) { + const [open, setOpen] = useState(false); + const [opened, setOpened] = useState(false); + const [currentIndex, setCurrentIndex] = useState(0); const theme = useTheme(); - const isTablet = useMediaQuery(theme.breakpoints.down(1000)); const isMobile = useMediaQuery(theme.breakpoints.down(790)); const quizId = Number(useParams().quizId); const [switchState, setSwitchState] = useState("setting"); @@ -43,148 +39,176 @@ export default function OptionsPicture({ totalIndex }: Props) { setSwitchState(data); }; - const addImage = ({ target }: ChangeEvent) => { - if (target.files?.length) { - const clonContent = listQuestions[quizId][totalIndex].content; - - clonContent.images.push(URL.createObjectURL(target.files[0])); + const uploadImage = (files: FileList | null) => { + if (files?.length) { + const [file] = Array.from(files); + const clonContent = { ...listQuestions[quizId][totalIndex].content }; + clonContent.variants[currentIndex].image = URL.createObjectURL(file); updateQuestionsList(quizId, totalIndex, { content: clonContent }); + + setOpen(false); + setOpened(true); } }; + const addNewAnswer = () => { + const answerNew = + listQuestions[quizId][totalIndex].content.variants.slice(); + answerNew.push({ answer: "", hints: "", emoji: "", image: "" }); + + updateQuestionsList(quizId, totalIndex, { + content: { + ...listQuestions[quizId][totalIndex].content, + variants: answerNew, + }, + }); + }; return ( <> - - - - - - Добавьте ответ - - - - - - - - - {!isMobile && ( - - )} - - ), - endAdornment: ( - - - - - - - - - - - - ), - }} - sx={{ - "& .MuiInputBase-root": { - padding: "13.5px", - borderRadius: "10px", - background: "#ffffff", - }, - "& .MuiOutlinedInput-notchedOutline": { - border: "none", - }, - }} - inputProps={{ - sx: { fontSize: "18px", lineHeight: "21px", py: 0 }, - }} - /> - - {isMobile && ( - + ( + <> + {!isMobile && ( - - { + setCurrentIndex(index); + setOpen(true); }} > - + + {variant.image ? ( + + + + + + + ) : ( + + )} - - )} - - + )} + + )} + additionalMobile={(variant, index) => ( + <> + {isMobile && ( + { + setCurrentIndex(index); + setOpen(true); + }} + sx={{ + overflow: "hidden", + display: "flex", + alignItems: "center", + m: "8px", + position: "relative", + borderRadius: "3px", + }} + > + + {variant.image ? ( + + + + ) : ( + + )} + + + + + + + )} + + )} + /> + setOpen(false)} + imgHC={uploadImage} + /> + setOpened(false)} + picture={ + listQuestions[quizId][totalIndex].content.variants[currentIndex] + .image + } + /> { - // console.info("I'm a button."); - // }} + onClick={addNewAnswer} > Добавьте ответ diff --git a/src/pages/Questions/answerOptions/AnswerOptions.tsx b/src/pages/Questions/answerOptions/AnswerOptions.tsx index 5687e255..dd35e830 100755 --- a/src/pages/Questions/answerOptions/AnswerOptions.tsx +++ b/src/pages/Questions/answerOptions/AnswerOptions.tsx @@ -25,7 +25,7 @@ export default function AnswerOptions({ totalIndex }: Props) { const addNewAnswer = () => { const answerNew = variants.slice(); - answerNew.push({ answer: "", hints: "", emoji: "" }); + answerNew.push({ answer: "", hints: "", emoji: "", image: "" }); updateQuestionsList(quizId, totalIndex, { content: { diff --git a/src/stores/questions.ts b/src/stores/questions.ts index 36788b87..c232d5b4 100644 --- a/src/stores/questions.ts +++ b/src/stores/questions.ts @@ -5,6 +5,7 @@ export type Variants = { answer: string; hints: string; emoji: string; + image: string; }; type Hint = { @@ -36,7 +37,6 @@ export interface Question { variants: Variants[]; hint: Hint; rule: Rule; - images: string[]; largeCheck: boolean; large: string; multi: boolean; @@ -100,7 +100,6 @@ export const DEFAULT_QUESTION: Omit = { type: "all", autofill: true, default: "", - images: [], number: false, single: false, xy: "", @@ -125,6 +124,7 @@ export const DEFAULT_QUESTION: Omit = { answer: "", hints: "", emoji: "", + image: "", }, ], hint: {