fix: emoji

This commit is contained in:
IlyaDoronin 2023-09-06 10:30:27 +03:00
parent afdc4ca493
commit cd2d4dde67
5 changed files with 83 additions and 44 deletions

@ -19,12 +19,14 @@ import TextareaAutosize from "@mui/base/TextareaAutosize";
import type { ChangeEvent, KeyboardEvent } from "react"; import type { ChangeEvent, KeyboardEvent } from "react";
import type { Variants } from "@root/questions"; import type { Variants } from "@root/questions";
import { ReactNode } from "react";
type AnswerItemProps = { type AnswerItemProps = {
index: number; index: number;
totalIndex: number; totalIndex: number;
variants: Variants[]; variants: Variants[];
variant: Variants; variant: Variants;
icon?: ReactNode;
}; };
export const AnswerItem = ({ export const AnswerItem = ({
@ -32,6 +34,7 @@ export const AnswerItem = ({
totalIndex, totalIndex,
variants, variants,
variant, variant,
icon,
}: AnswerItemProps) => { }: AnswerItemProps) => {
const { listQuestions } = questionStore(); const { listQuestions } = questionStore();
const theme = useTheme(); const theme = useTheme();
@ -105,12 +108,15 @@ export const AnswerItem = ({
} }
InputProps={{ InputProps={{
startAdornment: ( startAdornment: (
<InputAdornment <>
{...provided.dragHandleProps} <InputAdornment
position="start" {...provided.dragHandleProps}
> position="start"
<PointsIcon /> >
</InputAdornment> <PointsIcon />
</InputAdornment>
{icon && icon}
</>
), ),
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">

@ -7,17 +7,20 @@ import { updateVariants } from "@root/questions";
import { reorder } from "./helper"; import { reorder } from "./helper";
import { ReactNode } from "react";
import type { DropResult } from "react-beautiful-dnd"; import type { DropResult } from "react-beautiful-dnd";
import type { Variants } from "@root/questions"; import type { Variants } from "@root/questions";
type AnswerDraggableListProps = { type AnswerDraggableListProps = {
variants: Variants[]; variants: Variants[];
totalIndex: number; totalIndex: number;
icon?: ReactNode;
}; };
export const AnswerDraggableList = ({ export const AnswerDraggableList = ({
variants, variants,
totalIndex, totalIndex,
icon,
}: AnswerDraggableListProps) => { }: AnswerDraggableListProps) => {
const onDragEnd = ({ destination, source }: DropResult) => { const onDragEnd = ({ destination, source }: DropResult) => {
if (destination) { if (destination) {
@ -39,6 +42,7 @@ export const AnswerDraggableList = ({
totalIndex={totalIndex} totalIndex={totalIndex}
variants={variants} variants={variants}
variant={variant} variant={variant}
icon={icon}
/> />
))} ))}
{provided.placeholder} {provided.placeholder}

@ -4,43 +4,50 @@ import ButtonsOptions from "../ButtonsOptions";
import SwitchEmoji from "./switchEmoji"; import SwitchEmoji from "./switchEmoji";
import React from "react"; import React from "react";
import AddEmoji from "../../../assets/icons/questionsPage/addEmoji"; import AddEmoji from "../../../assets/icons/questionsPage/addEmoji";
import { AnswerDraggableList } from "../AnswerDraggableList";
import { questionStore, updateQuestionsList } from "@root/questions";
interface Props { interface Props {
totalIndex: number; totalIndex: number;
} }
export default function Emoji({ totalIndex }: Props) { export default function Emoji({ totalIndex }: Props) {
const theme = useTheme();
const [switchState, setSwitchState] = React.useState("setting"); const [switchState, setSwitchState] = React.useState("setting");
const { listQuestions } = questionStore();
const theme = useTheme();
const SSHC = (data: string) => { const SSHC = (data: string) => {
setSwitchState(data); setSwitchState(data);
}; };
return ( return (
<> <>
<Box sx={{ padding: "20px" }}> <Box sx={{ padding: "20px" }}>
<Box <AnswerDraggableList
sx={{ display: "flex", alignItems: "center", paddingBottom: "25px" }} variants={listQuestions[totalIndex].content.variants}
> totalIndex={totalIndex}
<AddEmoji /> icon={
<Typography <Box sx={{ margin: "0 15px 0 5px" }}>
sx={{ <AddEmoji />
padding: "0 0 0 20px", </Box>
fontWeight: 400, }
fontSize: "18px", />
lineHeight: "21.33px",
color: theme.palette.grey2.main,
}}
>
Добавьте ответ
</Typography>
</Box>
<Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}> <Box sx={{ display: "flex", alignItems: "center", gap: "10px" }}>
<Link <Link
component="button" component="button"
variant="body2" variant="body2"
sx={{ color: theme.palette.brightPurple.main }} sx={{ color: theme.palette.brightPurple.main }}
// onClick={() => { onClick={() => {
// console.info("I'm a button."); const answerNew =
// }} listQuestions[totalIndex].content.variants.slice();
answerNew.push({ answer: "", answerLong: "", hints: "" });
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
variants: answerNew,
},
});
}}
> >
Добавьте ответ Добавьте ответ
</Link> </Link>

@ -1,21 +1,43 @@
import {Box, Typography} from "@mui/material"; import { Box, Typography } from "@mui/material";
import CustomCheckbox from "@ui_kit/CustomCheckbox"; import CustomCheckbox from "@ui_kit/CustomCheckbox";
import InfoIcon from "../../../assets/icons/InfoIcon"; import InfoIcon from "../../../assets/icons/InfoIcon";
import { questionStore, updateQuestionsList } from "@root/questions";
type SettingEmojiProps = {
totalIndex: number;
};
export default function SettingEmoji() { export default function SettingEmoji({ totalIndex }: SettingEmojiProps) {
return ( const { listQuestions } = questionStore();
<Box sx={{display: 'flex'}}>
<Box sx={{padding: '20px'}}> return (
<Typography>Настройки ответов</Typography> <Box sx={{ display: "flex" }}>
<CustomCheckbox label={'Можно несколько'}/> <Box sx={{ padding: "20px" }}>
<CustomCheckbox label={'Вариант "свой ответ"'}/> <Typography>Настройки ответов</Typography>
</Box> <CustomCheckbox
<Box sx={{padding: '20px'}}> label={"Можно несколько"}
<Typography>Настройки вопросов</Typography> checked={listQuestions[totalIndex].content.multi}
<CustomCheckbox label={'Необязательный вопрос'}/> handleChange={(e) => {
<CustomCheckbox label={'Внутреннее название вопроса'}/> <InfoIcon /> let clonContent = listQuestions[totalIndex].content;
</Box> clonContent.multi = e.target.checked;
</Box> updateQuestionsList(totalIndex, { content: clonContent });
); }}
}; />
<CustomCheckbox
label={'Вариант "свой ответ"'}
checked={listQuestions[totalIndex].content.own}
handleChange={(e) => {
let clonContent = listQuestions[totalIndex].content;
clonContent.own = e.target.checked;
updateQuestionsList(totalIndex, { content: clonContent });
}}
/>
</Box>
<Box sx={{ padding: "20px" }}>
<Typography>Настройки вопросов</Typography>
<CustomCheckbox label={"Необязательный вопрос"} />
<CustomCheckbox label={"Внутреннее название вопроса"} /> <InfoIcon />
</Box>
</Box>
);
}

@ -14,7 +14,7 @@ export default function SwitchEmoji({
}: Props) { }: Props) {
switch (switchState) { switch (switchState) {
case "setting": case "setting":
return <SettingEmoji />; return <SettingEmoji totalIndex={totalIndex} />;
break; break;
case "help": case "help":
return <HelpQuestions totalIndex={totalIndex} />; return <HelpQuestions totalIndex={totalIndex} />;