2025-07-28 15:10:57 -07:00
|
|
|
import { useSlotRecipe, Box, Button, IconButton } from "@chakra-ui/react";
|
2025-07-31 08:56:32 -07:00
|
|
|
import { ColorModeButton, useColorMode } from "@/components/ui/color-mode";
|
2025-07-29 11:08:36 -07:00
|
|
|
// import { Tooltip } from "@/components/ui/tooltip";
|
|
|
|
|
import Tooltip from "../Canvas/components/Tooltip.jsx";
|
2025-07-16 15:02:57 -07:00
|
|
|
import { FaVolcano } from "react-icons/fa6";
|
2025-07-28 13:42:12 -07:00
|
|
|
import { FaHome } from "react-icons/fa";
|
2025-07-28 15:10:57 -07:00
|
|
|
import { FaGlobeAmericas } from "react-icons/fa";
|
|
|
|
|
import { FaMapMarkerAlt } from "react-icons/fa";
|
|
|
|
|
import { HiUsers } from "react-icons/hi2";
|
|
|
|
|
import { VscThreeBars } from "react-icons/vsc";
|
2025-07-29 09:59:17 -07:00
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
import { Seismic } from "../Canvas/views/DashboardCanvasNav/Seismic";
|
2025-07-29 11:04:29 -07:00
|
|
|
import { DASHBOARD_VIEWS } from "@/constants/viewKeys";
|
2025-07-16 15:02:57 -07:00
|
|
|
|
2025-07-31 08:56:32 -07:00
|
|
|
export default function Sidebar({ view, onChangeView, darkMode, setDarkMode }) {
|
2025-07-16 15:02:57 -07:00
|
|
|
const [isOpen, setIsOpen] = useState(true);
|
2025-07-23 11:35:28 -07:00
|
|
|
const [activeButton, setActiveButton] = useState(0)
|
2025-07-29 11:08:36 -07:00
|
|
|
const recipe = useSlotRecipe({ key: "sidebar" });
|
|
|
|
|
const styles = recipe();
|
2025-07-31 08:56:32 -07:00
|
|
|
const { toggleColorMode } = useColorMode();
|
2025-07-17 09:45:36 -07:00
|
|
|
|
2025-07-23 13:44:24 -07:00
|
|
|
// this list of btns will come from the db (not every usr will have access to admin)
|
2025-07-17 09:45:36 -07:00
|
|
|
const buttons = [
|
2025-07-28 13:42:12 -07:00
|
|
|
{icon: FaHome, name: "Home", view: "widget"},
|
2025-07-28 15:10:57 -07:00
|
|
|
{icon: FaGlobeAmericas, name: "Global Map", view: "global"},
|
|
|
|
|
{icon: FaMapMarkerAlt, name: "Regional Map", view: "regional"},
|
2025-07-23 11:35:28 -07:00
|
|
|
{icon: FaVolcano, name: "Volcano", view: "volcano"},
|
2025-07-28 15:10:57 -07:00
|
|
|
{icon: HiUsers, name: "Admin", view: "admin"}
|
2025-07-17 09:45:36 -07:00
|
|
|
];
|
2025-07-16 15:02:57 -07:00
|
|
|
|
|
|
|
|
const toggleSidebar = () => {
|
2025-07-17 09:45:36 -07:00
|
|
|
if (isOpen) setIsOpen(false);
|
|
|
|
|
else setIsOpen(true);
|
2025-07-16 15:02:57 -07:00
|
|
|
};
|
|
|
|
|
|
2025-07-29 09:59:17 -07:00
|
|
|
// Track currrent view from both Sidebar and Canvas when 'view' changes
|
|
|
|
|
useEffect(() => {
|
2025-07-29 12:53:20 -07:00
|
|
|
// console.log("typeof view =", typeof view);
|
2025-07-29 09:59:17 -07:00
|
|
|
console.log("Current view = ", view);
|
|
|
|
|
|
|
|
|
|
const newIndex = buttons.findIndex((btn) => {
|
|
|
|
|
if (btn.view === "widget") {
|
2025-07-29 11:04:29 -07:00
|
|
|
return DASHBOARD_VIEWS.includes(view); // Group match
|
2025-07-29 09:59:17 -07:00
|
|
|
}
|
|
|
|
|
return btn.view === view; // Exact match
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (newIndex !== -1 ) {
|
|
|
|
|
setActiveButton(newIndex);
|
|
|
|
|
}
|
|
|
|
|
}, [view]);
|
|
|
|
|
|
2025-07-16 15:02:57 -07:00
|
|
|
return (
|
|
|
|
|
<Box
|
2025-07-29 12:53:20 -07:00
|
|
|
// key={button.name}
|
2025-07-16 15:02:57 -07:00
|
|
|
css={styles.root}
|
2025-07-17 10:32:35 -07:00
|
|
|
width={isOpen ? "210px" : "71px"}
|
2025-07-16 15:02:57 -07:00
|
|
|
transition="width 0.4s ease"
|
2025-07-29 11:08:36 -07:00
|
|
|
position="relative"
|
2025-07-16 15:02:57 -07:00
|
|
|
>
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Toggle Sidebar"
|
2025-07-22 09:26:40 -07:00
|
|
|
variant="plain"
|
2025-07-16 15:02:57 -07:00
|
|
|
size="md"
|
|
|
|
|
onClick={toggleSidebar}
|
2025-07-22 09:26:40 -07:00
|
|
|
width="54px"
|
2025-07-16 15:02:57 -07:00
|
|
|
>
|
2025-07-28 15:10:57 -07:00
|
|
|
<VscThreeBars />
|
2025-07-16 15:02:57 -07:00
|
|
|
</IconButton>
|
2025-07-17 09:45:36 -07:00
|
|
|
|
|
|
|
|
{buttons.map((button, idx) => {
|
|
|
|
|
const Icon = button.icon;
|
2025-07-29 11:08:36 -07:00
|
|
|
return (
|
2025-07-29 12:53:20 -07:00
|
|
|
<Tooltip key={button.name} tooltipkeykey={idx} content={button.name} sidebarIsOpen={isOpen}>
|
2025-07-29 11:08:36 -07:00
|
|
|
<Button
|
2025-07-29 12:53:20 -07:00
|
|
|
key={button.name}
|
2025-07-29 11:08:36 -07:00
|
|
|
css={styles.buttons}
|
|
|
|
|
onClick={() => {
|
2025-07-29 12:53:20 -07:00
|
|
|
// setActiveButton(idx);
|
2025-07-29 11:08:36 -07:00
|
|
|
onChangeView(button.view); // Trigger state change in Dashboard
|
|
|
|
|
}}
|
|
|
|
|
bg={activeButton === idx ? "primary":undefined}
|
|
|
|
|
color={activeButton === idx ? "#FFFFFF":undefined}
|
|
|
|
|
justifyContent="flex-start"
|
|
|
|
|
>
|
|
|
|
|
<Icon />
|
|
|
|
|
<span
|
|
|
|
|
style={{
|
2025-07-17 09:45:36 -07:00
|
|
|
opacity: isOpen ? 1 : 0,
|
|
|
|
|
transition: "opacity 0.4s ease",
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
|
display: "inline-block",
|
|
|
|
|
lineHeight: 1.2
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{button.name}
|
|
|
|
|
</span>
|
2025-07-29 11:08:36 -07:00
|
|
|
</Button>
|
2025-07-28 11:12:03 -07:00
|
|
|
</Tooltip>
|
2025-07-29 11:08:36 -07:00
|
|
|
)
|
2025-07-17 09:45:36 -07:00
|
|
|
})}
|
2025-07-31 08:56:32 -07:00
|
|
|
<ColorModeButton
|
|
|
|
|
onClick={
|
|
|
|
|
() => {
|
|
|
|
|
setDarkMode(!darkMode);
|
|
|
|
|
toggleColorMode();
|
|
|
|
|
}}
|
|
|
|
|
position="absolute"
|
|
|
|
|
bottom="2"/>
|
2025-07-16 15:02:57 -07:00
|
|
|
</Box>
|
|
|
|
|
);
|
2025-07-17 09:45:36 -07:00
|
|
|
}
|