import React, { ChangeEvent, FC, useEffect, useRef, useState } from "react"; import { Box, FormControl, IconButton, TextField, Typography, useMediaQuery, useTheme, } from "@mui/material"; import { SidebarModal } from "./SidebarModal"; import BackArrowIcon from "@icons/BackArrowIcon"; import { Settings } from "./icons/Settings"; import { Pencil } from "./icons/Pencil"; import { ArrowDown } from "./icons/ArrowDown"; import { Link, useLocation, useNavigate } from "react-router-dom"; import { setCurrentStep, updateQuiz } from "@root/quizes/actions"; import { useCurrentQuiz } from "@root/quizes/hooks"; import { LogoutButton } from "@ui_kit/LogoutButton"; import PencilCircleIcon from "@icons/PencilCircleIcon"; import { quizSetupSteps } from "@model/quizSettings"; import { updateNextStep } from "@root/uiTools/actions"; import { handleLogoutClick } from "@utils/HandleLogoutClick"; interface SidebarIconProps { height: string; width: string; color: string; } interface Iprops { open: boolean; changePage: (step: number) => void; setHeightSitebar: any; scrollDown: boolean; } export const SidebarMobile: FC = ({ open, changePage, setHeightSitebar, scrollDown, }) => { const theme = useTheme(); const isWrappSidebar = useMediaQuery(theme.breakpoints.down(400)); const [anchorEl, setAnchorEl] = useState(null); const [inputOpen, setInputOpen] = useState(false); const quiz = useCurrentQuiz(); const [inputValue, setInputValue] = useState(quiz.name); const ref = useRef(null); const heightSidebar = useRef(null); const navigate = useNavigate(); const { pathname } = useLocation(); const observer = useRef( new ResizeObserver((entries) => { const { height } = entries[0].contentRect; setHeightSitebar(height); }), ); useEffect(() => { if (heightSidebar.current) { observer.current.observe(heightSidebar.current); } }, [heightSidebar, observer]); const handleClick = (event: ChangeEvent) => { setAnchorEl(anchorEl ? null : event.currentTarget); }; const clickInput = (event: MouseEvent) => { debugger; if (ref.current && !ref.current?.contains(event.target as Node)) setInputOpen(false); }; useEffect(() => { document.addEventListener("mousedown", clickInput); return () => { document.removeEventListener("mousedown", clickInput); }; }, []); const changeMenuItem = (index: number) => { if (!pathname.startsWith("/edit")) { navigate("/edit"); } updateNextStep(index); changePage(index); }; const openPopper = Boolean(anchorEl); const id = openPopper ? "simple-popper" : ""; return ( Название {inputOpen ? ( { if (e.target.value.length <= 200) { setInputValue(e.target.value); } updateQuiz(quiz.id, (quiz) => { quiz.name = e.target.value; }); }} fullWidth id="project-name" placeholder="Название проекта" sx={{ width: "85%", "& .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, }, }, }} /> ) : ( {quiz.name} )} setInputOpen(true)} sx={{ mt: "10px" }}> { navigate("/"); handleLogoutClick(); }} sx={{ backgroundColor: "transparent", border: "1px solid #9A9AAF", }} /> {quizSetupSteps.map(({ sidebarIcon }, index) => ( 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, { height: isWrappSidebar ? "25px" : "32px", width: isWrappSidebar ? "25px" : "32px", color: `${theme.palette.brightPurple.main}`, }, )} ))} { navigate("/design"); setCurrentStep(15); }} sx={{ // ml: "4px", cursor: "pointer", width: isWrappSidebar ? "30px" : "36px", height: isWrappSidebar ? "30px" : "36px", background: "#262835", display: "flex", justifyContent: "center", alignItems: "center", borderRadius: "8px", }} > ); };