2025-04-29 13:02:25 +00:00
|
|
|
import React, { useState, useEffect, useRef } from "react";
|
2025-03-25 06:17:41 +00:00
|
|
|
import RenameInput from "./inputs/RenameInput";
|
2025-03-31 05:41:44 +00:00
|
|
|
import { ArrowIcon } from "../icons/ExportCommonIcons";
|
|
|
|
import MenuBar from "./menu/menu";
|
2025-04-29 12:49:03 +00:00
|
|
|
import { ProjectIcon } from "../icons/HeaderIcons";
|
2025-03-25 06:17:41 +00:00
|
|
|
|
|
|
|
const FileMenu: React.FC = () => {
|
2025-03-31 05:41:44 +00:00
|
|
|
const [openMenu, setOpenMenu] = useState(false);
|
2025-04-29 13:02:25 +00:00
|
|
|
const containerRef = useRef<HTMLButtonElement>(null);
|
|
|
|
let clickTimeout: NodeJS.Timeout | null = null;
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
if (clickTimeout) return;
|
|
|
|
setOpenMenu((prev) => !prev);
|
|
|
|
clickTimeout = setTimeout(() => {
|
|
|
|
clickTimeout = null;
|
|
|
|
}, 800);
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
|
|
if (
|
|
|
|
containerRef.current &&
|
|
|
|
!containerRef.current.contains(event.target as Node)
|
|
|
|
) {
|
|
|
|
setOpenMenu(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener("mousedown", handleClickOutside);
|
|
|
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
|
|
}, []);
|
|
|
|
|
2025-05-09 13:19:34 +00:00
|
|
|
// project
|
|
|
|
const [projectName, setProjectName] = useState("project 1");
|
|
|
|
|
|
|
|
// Load project name from localStorage on mount
|
|
|
|
useEffect(() => {
|
|
|
|
const savedName = localStorage.getItem("projectName");
|
|
|
|
if (savedName) {
|
|
|
|
setProjectName(savedName);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const handleProjectRename = (newName: string) => {
|
|
|
|
setProjectName(newName);
|
|
|
|
localStorage.setItem("projectName", newName);
|
|
|
|
};
|
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
return (
|
2025-04-29 13:02:25 +00:00
|
|
|
<button
|
|
|
|
className="project-dropdowm-container"
|
|
|
|
ref={containerRef}
|
|
|
|
onClick={handleClick}
|
|
|
|
>
|
2025-03-25 06:17:41 +00:00
|
|
|
<div className="project-name">
|
2025-04-29 12:49:03 +00:00
|
|
|
<div className="icon">
|
|
|
|
<ProjectIcon />
|
|
|
|
</div>
|
2025-05-09 13:19:34 +00:00
|
|
|
<RenameInput value={projectName} onRename={handleProjectRename} />
|
2025-03-25 06:17:41 +00:00
|
|
|
</div>
|
2025-04-29 13:02:25 +00:00
|
|
|
<div className="more-options-button">
|
2025-03-31 05:41:44 +00:00
|
|
|
<ArrowIcon />
|
|
|
|
{openMenu && <MenuBar setOpenMenu={setOpenMenu} />}
|
|
|
|
</div>
|
2025-04-29 13:02:25 +00:00
|
|
|
</button>
|
2025-03-25 06:17:41 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FileMenu;
|