feat: OptionsPicture store logic

This commit is contained in:
IlyaDoronin 2023-08-28 12:31:34 +03:00
parent 7ac8aef451
commit a49b999a38
3 changed files with 111 additions and 34 deletions

@ -1,7 +1,10 @@
import { useEffect } from "react";
import { Box, Button, Typography, useTheme } from "@mui/material"; import { Box, Button, Typography, useTheme } from "@mui/material";
import CustomCheckbox from "@ui_kit/CustomCheckbox"; import CustomCheckbox from "@ui_kit/CustomCheckbox";
import { questionStore, updateQuestionsList } from "@root/questions";
import InfoIcon from "../../../assets/icons/InfoIcon"; import InfoIcon from "../../../assets/icons/InfoIcon";
import { useState } from "react";
import FormatIcon2 from "../../../assets/icons/questionsPage/FormatIcon2"; import FormatIcon2 from "../../../assets/icons/questionsPage/FormatIcon2";
import FormatIcon1 from "../../../assets/icons/questionsPage/FormatIcon1"; import FormatIcon1 from "../../../assets/icons/questionsPage/FormatIcon1";
import ProportionsIcon11 from "../../../assets/icons/questionsPage/ProportionsIcon11"; import ProportionsIcon11 from "../../../assets/icons/questionsPage/ProportionsIcon11";
@ -14,18 +17,38 @@ interface Props {
onClick: () => void; onClick: () => void;
} }
type SettingOpytionsPictProps = {
totalIndex: number;
};
const PROPORTIONS = [
{ value: "1:1", icon: ProportionsIcon11 },
{ value: "2:1", icon: ProportionsIcon21 },
{ value: "1:2", icon: ProportionsIcon12 },
];
export function SelectIconButton({ Icon, isActive = false, onClick }: Props) { export function SelectIconButton({ Icon, isActive = false, onClick }: Props) {
const theme = useTheme(); const theme = useTheme();
return ( return (
<Button <Button
onClick={onClick} onClick={onClick}
variant="outlined" variant="outlined"
startIcon={<Icon color={isActive ? theme.palette.navbarbg.main : theme.palette.brightPurple.main} />} startIcon={
<Icon
color={
isActive
? theme.palette.navbarbg.main
: theme.palette.brightPurple.main
}
/>
}
sx={{ sx={{
backgroundColor: isActive ? theme.palette.brightPurple.main : "#eee4fc", backgroundColor: isActive ? theme.palette.brightPurple.main : "#eee4fc",
borderRadius: 0, borderRadius: 0,
border: "none", border: "none",
color: isActive ? theme.palette.brightPurple.main : theme.palette.grey2.main, color: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
p: "7px", p: "7px",
width: "auto", width: "auto",
minWidth: 0, minWidth: 0,
@ -35,19 +58,31 @@ export function SelectIconButton({ Icon, isActive = false, onClick }: Props) {
}, },
"&:hover": { "&:hover": {
border: "none", border: "none",
borderColor: isActive ? theme.palette.brightPurple.main : theme.palette.grey2.main, borderColor: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
}, },
}} }}
/> />
); );
} }
type Proportions = "oneOne" | "twoOne" | "oneTwo"; export default function SettingOpytionsPict({
type AlignType = "left" | "right"; totalIndex,
}: SettingOpytionsPictProps) {
const { listQuestions } = questionStore();
export default function SettingOpytionsPict() { useEffect(() => {
const [proportions, setProportions] = useState<Proportions>("oneOne"); if (!listQuestions[totalIndex].content.xy) {
const [alignType, setAlignType] = useState<AlignType>("left"); updateProportions("1:1");
}
}, []);
const updateProportions = (proportions: string) => {
const clonContent = listQuestions[totalIndex].content;
clonContent.xy = proportions;
updateQuestionsList(totalIndex, { content: clonContent });
};
return ( return (
<> <>
@ -61,25 +96,43 @@ export default function SettingOpytionsPict() {
marginBottom: "20px", marginBottom: "20px",
}} }}
> >
{PROPORTIONS.map(({ value, icon }, index) => (
<SelectIconButton <SelectIconButton
onClick={() => setProportions("oneOne")} key={index}
isActive={proportions === "oneOne"} onClick={() => updateProportions(value)}
Icon={ProportionsIcon11} isActive={listQuestions[totalIndex].content.xy === value}
/> Icon={icon}
<SelectIconButton
onClick={() => setProportions("twoOne")}
isActive={proportions === "twoOne"}
Icon={ProportionsIcon21}
/>
<SelectIconButton
onClick={() => setProportions("oneTwo")}
isActive={proportions === "oneTwo"}
Icon={ProportionsIcon12}
/> />
))}
</Box> </Box>
<Typography sx={{ marginBottom: "15px" }}>Настройки ответов</Typography> <Typography sx={{ marginBottom: "15px" }}>
<CustomCheckbox label={"Можно несколько"} /> Настройки ответов
<CustomCheckbox label={"Большие картинки"} /> </Typography>
<CustomCheckbox
label={"Можно несколько"}
checked={listQuestions[totalIndex].content.multi}
handleChange={() =>
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
multi: !listQuestions[totalIndex].content.multi,
},
})
}
/>
<CustomCheckbox
label={"Большие картинки"}
checked={listQuestions[totalIndex].content.large}
handleChange={() =>
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
large: !listQuestions[totalIndex].content.large,
},
})
}
/>
<CustomCheckbox label={'Вариант "свой ответ"'} /> <CustomCheckbox label={'Вариант "свой ответ"'} />
</Box> </Box>
<Box sx={{ padding: "20px" }}> <Box sx={{ padding: "20px" }}>
@ -91,14 +144,34 @@ export default function SettingOpytionsPict() {
marginBottom: "20px", marginBottom: "20px",
}} }}
> >
<SelectIconButton onClick={() => setAlignType("left")} isActive={alignType === "left"} Icon={FormatIcon2} />
<SelectIconButton <SelectIconButton
onClick={() => setAlignType("right")} onClick={() =>
isActive={alignType === "right"} updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
format: "carousel",
},
})
}
isActive={listQuestions[totalIndex].content.format === "carousel"}
Icon={FormatIcon2}
/>
<SelectIconButton
onClick={() =>
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
format: "masonry",
},
})
}
isActive={listQuestions[totalIndex].content.format === "masonry"}
Icon={FormatIcon1} Icon={FormatIcon1}
/> />
</Box> </Box>
<Typography sx={{ marginBottom: "15px" }}>Настройки вопросов</Typography> <Typography sx={{ marginBottom: "15px" }}>
Настройки вопросов
</Typography>
<CustomCheckbox label={"Необязательный вопрос"} /> <CustomCheckbox label={"Необязательный вопрос"} />
<CustomCheckbox label={"Внутреннее название вопроса"} /> <InfoIcon /> <CustomCheckbox label={"Внутреннее название вопроса"} /> <InfoIcon />
</Box> </Box>

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

@ -47,6 +47,8 @@ export interface Question {
default: string; default: string;
single: boolean; single: boolean;
number: boolean; number: boolean;
xy: string;
format: "carousel" | "masonry";
}; };
version: number; version: number;
parent_ids: number[]; parent_ids: number[];
@ -116,6 +118,8 @@ export const createQuestion = (id: number) => {
images: [], images: [],
number: false, number: false,
single: false, single: false,
xy: "",
format: "carousel",
variants: [ variants: [
{ {
answer: "", answer: "",