2024-04-17 12:08:18 +00:00
|
|
|
|
import React, { ChangeEvent, FC, useEffect, useRef, useState } from "react";
|
2024-01-04 15:18:29 +00:00
|
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
FormControl,
|
|
|
|
|
IconButton,
|
|
|
|
|
TextField,
|
|
|
|
|
Typography,
|
2024-03-07 23:07:54 +00:00
|
|
|
|
useMediaQuery,
|
|
|
|
|
useTheme,
|
2024-01-04 15:18:29 +00:00
|
|
|
|
} from "@mui/material";
|
2023-12-29 13:32:57 +00:00
|
|
|
|
|
|
|
|
|
import { SidebarModal } from "./SidebarModal";
|
|
|
|
|
|
|
|
|
|
import BackArrowIcon from "@icons/BackArrowIcon";
|
2023-09-20 17:39:17 +00:00
|
|
|
|
import { Settings } from "./icons/Settings";
|
|
|
|
|
import { Pencil } from "./icons/Pencil";
|
|
|
|
|
import { ArrowDown } from "./icons/ArrowDown";
|
2024-03-07 23:07:54 +00:00
|
|
|
|
import { Link, useLocation, useNavigate } from "react-router-dom";
|
|
|
|
|
import { setCurrentStep, updateQuiz } from "@root/quizes/actions";
|
2024-01-04 15:18:29 +00:00
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2024-01-04 18:36:26 +00:00
|
|
|
|
import { LogoutButton } from "@ui_kit/LogoutButton";
|
2024-03-07 23:07:54 +00:00
|
|
|
|
import PencilCircleIcon from "@icons/PencilCircleIcon";
|
|
|
|
|
import { quizSetupSteps } from "@model/quizSettings";
|
|
|
|
|
import { updateNextStep } from "@root/uiTools/actions";
|
2024-04-08 23:11:19 +00:00
|
|
|
|
import { handleLogoutClick } from "@utils/HandleLogoutClick";
|
2024-03-07 23:07:54 +00:00
|
|
|
|
|
|
|
|
|
interface SidebarIconProps {
|
|
|
|
|
height: string;
|
|
|
|
|
width: string;
|
|
|
|
|
color: string;
|
|
|
|
|
}
|
2023-09-20 17:39:17 +00:00
|
|
|
|
|
|
|
|
|
interface Iprops {
|
|
|
|
|
open: boolean;
|
2023-12-29 10:17:43 +00:00
|
|
|
|
changePage: (step: number) => void;
|
2024-02-15 01:19:03 +00:00
|
|
|
|
setHeightSitebar: any;
|
2024-03-14 09:40:44 +00:00
|
|
|
|
scrollDown: boolean;
|
2023-09-20 17:39:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-15 01:19:03 +00:00
|
|
|
|
export const SidebarMobile: FC<Iprops> = ({
|
|
|
|
|
open,
|
|
|
|
|
changePage,
|
|
|
|
|
setHeightSitebar,
|
2024-03-14 09:40:44 +00:00
|
|
|
|
scrollDown,
|
2024-02-15 01:19:03 +00:00
|
|
|
|
}) => {
|
2024-03-07 23:07:54 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const isWrappSidebar = useMediaQuery(theme.breakpoints.down(400));
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
2024-01-04 15:18:29 +00:00
|
|
|
|
const [inputOpen, setInputOpen] = useState<boolean>(false);
|
|
|
|
|
const quiz = useCurrentQuiz();
|
2024-02-15 21:49:21 +00:00
|
|
|
|
const [inputValue, setInputValue] = useState(quiz.name);
|
2024-04-17 12:08:18 +00:00
|
|
|
|
const ref = useRef<HTMLInputElement | null>(null);
|
2024-02-15 01:19:03 +00:00
|
|
|
|
const heightSidebar = useRef(null);
|
2024-01-04 18:36:26 +00:00
|
|
|
|
const navigate = useNavigate();
|
2024-03-07 23:07:54 +00:00
|
|
|
|
const { pathname } = useLocation();
|
2024-02-15 01:19:03 +00:00
|
|
|
|
|
|
|
|
|
const observer = useRef(
|
|
|
|
|
new ResizeObserver((entries) => {
|
|
|
|
|
const { height } = entries[0].contentRect;
|
|
|
|
|
setHeightSitebar(height);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-04-17 12:08:18 +00:00
|
|
|
|
if (heightSidebar.current) {
|
|
|
|
|
observer.current.observe(heightSidebar.current);
|
|
|
|
|
}
|
2024-02-15 01:19:03 +00:00
|
|
|
|
}, [heightSidebar, observer]);
|
|
|
|
|
|
2024-04-17 12:08:18 +00:00
|
|
|
|
const handleClick = (event: ChangeEvent<HTMLDivElement>) => {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
setAnchorEl(anchorEl ? null : event.currentTarget);
|
|
|
|
|
};
|
2024-03-07 23:07:54 +00:00
|
|
|
|
|
2024-04-17 12:08:18 +00:00
|
|
|
|
const clickInput = (event: MouseEvent) => {
|
|
|
|
|
debugger;
|
|
|
|
|
if (ref.current && !ref.current?.contains(event.target as Node))
|
|
|
|
|
setInputOpen(false);
|
2024-01-04 15:18:29 +00:00
|
|
|
|
};
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
document.addEventListener("mousedown", clickInput);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener("mousedown", clickInput);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
2024-03-07 23:07:54 +00:00
|
|
|
|
|
|
|
|
|
const changeMenuItem = (index: number) => {
|
|
|
|
|
if (!pathname.startsWith("/edit")) {
|
|
|
|
|
navigate("/edit");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateNextStep(index);
|
|
|
|
|
changePage(index);
|
|
|
|
|
};
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const openPopper = Boolean(anchorEl);
|
2024-04-17 12:08:18 +00:00
|
|
|
|
const id = openPopper ? "simple-popper" : "";
|
2023-12-29 13:32:57 +00:00
|
|
|
|
return (
|
2023-09-20 17:39:17 +00:00
|
|
|
|
<Box
|
2024-02-15 01:19:03 +00:00
|
|
|
|
ref={heightSidebar}
|
2023-12-29 10:17:43 +00:00
|
|
|
|
sx={{
|
2024-03-14 09:40:44 +00:00
|
|
|
|
display: open ? "flex" : "none",
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
width: "100%",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
minHeight: "134px",
|
|
|
|
|
padding: "20px 16px 16px 16px",
|
|
|
|
|
background: "#333647",
|
|
|
|
|
borderTop: "1px solid #9A9AAF",
|
|
|
|
|
borderBottomLeftRadius: "8px",
|
|
|
|
|
borderBottomRightRadius: "8px",
|
|
|
|
|
transitionDuration: "200ms",
|
2024-03-14 09:40:44 +00:00
|
|
|
|
position: "fixed",
|
|
|
|
|
top: "51px",
|
|
|
|
|
zIndex: theme.zIndex.drawer + 1,
|
|
|
|
|
transition: "transform 0.3s",
|
|
|
|
|
transform: scrollDown ? "translateY(-200px)" : undefined,
|
2023-12-29 10:17:43 +00:00
|
|
|
|
}}
|
2023-09-20 17:39:17 +00:00
|
|
|
|
>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", position: "relative" }}>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
<Link to="/list">
|
|
|
|
|
<IconButton sx={{ p: "6px" }}>
|
|
|
|
|
<BackArrowIcon color={"white"} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Link>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
|
2024-01-04 15:18:29 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
ml: "15px",
|
|
|
|
|
display: "flex",
|
2024-03-19 15:58:20 +00:00
|
|
|
|
alignItems: "center",
|
2024-01-04 15:18:29 +00:00
|
|
|
|
width: "100%",
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
<Box>
|
|
|
|
|
<Typography sx={{ fontSize: "12px", color: "#9A9AAF" }}>
|
|
|
|
|
Название
|
|
|
|
|
</Typography>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
{inputOpen ? (
|
|
|
|
|
<FormControl fullWidth variant="standard">
|
|
|
|
|
<TextField
|
|
|
|
|
ref={ref}
|
2024-02-15 21:49:21 +00:00
|
|
|
|
value={inputValue}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
if (e.target.value.length <= 200) {
|
|
|
|
|
setInputValue(e.target.value);
|
|
|
|
|
}
|
2024-01-04 15:18:29 +00:00
|
|
|
|
updateQuiz(quiz.id, (quiz) => {
|
|
|
|
|
quiz.name = e.target.value;
|
2024-02-15 21:49:21 +00:00
|
|
|
|
});
|
|
|
|
|
}}
|
2024-01-04 15:18:29 +00:00
|
|
|
|
fullWidth
|
|
|
|
|
id="project-name"
|
|
|
|
|
placeholder="Название проекта"
|
|
|
|
|
sx={{
|
2024-03-19 15:58:20 +00:00
|
|
|
|
width: "85%",
|
2024-01-04 15:18:29 +00:00
|
|
|
|
"& .MuiInputBase-root": {
|
|
|
|
|
height: "34px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
p: 0,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
inputProps={{
|
|
|
|
|
sx: {
|
|
|
|
|
height: "20px",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
fontSize: "16px",
|
|
|
|
|
lineHeight: "20px",
|
|
|
|
|
p: "7px",
|
|
|
|
|
color: "white",
|
|
|
|
|
"&::placeholder": {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</FormControl>
|
|
|
|
|
) : (
|
2024-02-15 01:19:03 +00:00
|
|
|
|
<Typography color={"white"} sx={{ wordBreak: "break-word" }}>
|
|
|
|
|
{quiz.name}
|
|
|
|
|
</Typography>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
)}
|
2023-12-29 13:32:57 +00:00
|
|
|
|
</Box>
|
2024-03-19 15:58:20 +00:00
|
|
|
|
<IconButton onClick={() => setInputOpen(true)} sx={{ mt: "10px" }}>
|
2024-01-04 15:18:29 +00:00
|
|
|
|
<Pencil
|
|
|
|
|
style={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
right: "0",
|
|
|
|
|
color: "white",
|
|
|
|
|
fontSize: "24px",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</IconButton>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: "100%",
|
2024-01-04 18:36:26 +00:00
|
|
|
|
justifyContent: "space-between",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
display: "flex",
|
2024-03-07 23:07:54 +00:00
|
|
|
|
alignItems: "center",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
marginTop: "20px",
|
|
|
|
|
flexWrap: "wrap",
|
|
|
|
|
gap: "5px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-03-07 23:07:54 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<LogoutButton
|
2024-04-08 23:11:19 +00:00
|
|
|
|
onClick={() => {
|
|
|
|
|
navigate("/");
|
|
|
|
|
handleLogoutClick();
|
|
|
|
|
}}
|
2024-03-07 23:07:54 +00:00
|
|
|
|
sx={{
|
|
|
|
|
backgroundColor: "transparent",
|
|
|
|
|
border: "1px solid #9A9AAF",
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box sx={{ display: "flex", alignItems: "center", flexWrap: "wrap" }}>
|
2024-01-04 18:36:26 +00:00
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
display: "flex",
|
2024-03-07 23:07:54 +00:00
|
|
|
|
gap: "4px",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
flexWrap: "wrap",
|
2024-01-04 18:36:26 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2024-03-07 23:07:54 +00:00
|
|
|
|
{quizSetupSteps.map(({ sidebarIcon }, index) => (
|
|
|
|
|
<Box
|
|
|
|
|
key={index}
|
|
|
|
|
onClick={() => changeMenuItem(index)}
|
|
|
|
|
sx={{
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
width: isWrappSidebar ? "30px" : "36px",
|
|
|
|
|
height: isWrappSidebar ? "30px" : "36px",
|
|
|
|
|
background: "#262835",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{React.createElement(
|
|
|
|
|
sidebarIcon as React.FC<SidebarIconProps>,
|
|
|
|
|
{
|
|
|
|
|
height: isWrappSidebar ? "25px" : "32px",
|
|
|
|
|
width: isWrappSidebar ? "25px" : "32px",
|
|
|
|
|
color: `${theme.palette.brightPurple.main}`,
|
|
|
|
|
},
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
))}
|
|
|
|
|
<Box
|
|
|
|
|
onClick={() => {
|
|
|
|
|
navigate("/design");
|
|
|
|
|
setCurrentStep(15);
|
|
|
|
|
}}
|
2024-01-04 18:36:26 +00:00
|
|
|
|
sx={{
|
2024-03-07 23:07:54 +00:00
|
|
|
|
// ml: "4px",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
width: isWrappSidebar ? "30px" : "36px",
|
|
|
|
|
height: isWrappSidebar ? "30px" : "36px",
|
|
|
|
|
background: "#262835",
|
|
|
|
|
display: "flex",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
borderRadius: "8px",
|
2024-01-04 18:36:26 +00:00
|
|
|
|
}}
|
2024-03-07 23:07:54 +00:00
|
|
|
|
>
|
|
|
|
|
<PencilCircleIcon
|
|
|
|
|
color={theme.palette.brightPurple.main}
|
|
|
|
|
height={isWrappSidebar ? "25px" : "32px"}
|
|
|
|
|
width={isWrappSidebar ? "25px" : "32px"}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
2024-01-04 18:36:26 +00:00
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2023-12-29 10:17:43 +00:00
|
|
|
|
<Box
|
2023-12-31 02:53:25 +00:00
|
|
|
|
aria-describedby={id}
|
2023-12-30 00:29:13 +00:00
|
|
|
|
onClick={handleClick}
|
2023-12-29 10:17:43 +00:00
|
|
|
|
sx={{
|
2024-03-07 23:07:54 +00:00
|
|
|
|
pr: "10px",
|
|
|
|
|
pl: "5px",
|
|
|
|
|
width: "60px",
|
2023-12-29 10:17:43 +00:00
|
|
|
|
height: "44px",
|
|
|
|
|
background: "#262835",
|
|
|
|
|
display: "flex",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
justifyContent: "space-between",
|
2023-12-29 10:17:43 +00:00
|
|
|
|
alignItems: "center",
|
|
|
|
|
borderRadius: "8px",
|
2023-12-29 13:32:57 +00:00
|
|
|
|
border: "1px solid #FFFFFF66",
|
2024-03-07 23:07:54 +00:00
|
|
|
|
marginLeft: "0",
|
2023-12-29 10:17:43 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
<Settings
|
2024-03-07 23:07:54 +00:00
|
|
|
|
style={{ color: "#974BFA", fontSize: "24px", marginLeft: "5px" }}
|
2023-12-29 13:32:57 +00:00
|
|
|
|
/>
|
|
|
|
|
<ArrowDown style={{ color: "#F2F3F7" }} />
|
2023-12-29 10:17:43 +00:00
|
|
|
|
</Box>
|
2023-09-20 17:39:17 +00:00
|
|
|
|
</Box>
|
2023-12-31 02:53:25 +00:00
|
|
|
|
<SidebarModal
|
|
|
|
|
open={openPopper}
|
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
|
handleClick={handleClick}
|
|
|
|
|
id={id}
|
|
|
|
|
changePage={changePage}
|
|
|
|
|
/>
|
2023-09-20 17:39:17 +00:00
|
|
|
|
</Box>
|
2023-12-29 13:32:57 +00:00
|
|
|
|
);
|
|
|
|
|
};
|