diff --git a/client/src/components/layout/Canvas/Canvas.jsx b/client/src/components/layout/Canvas/Canvas.jsx index 3067854..e097f28 100644 --- a/client/src/components/layout/Canvas/Canvas.jsx +++ b/client/src/components/layout/Canvas/Canvas.jsx @@ -9,14 +9,16 @@ import VolcanoCanvas from "./views/VolcanoCanvas"; import AdminCanvas from "./views/AdminCanvas"; import { DashboardCanvas } from "./views/DashboardCanvas"; -export default function Canvas({ view, layout, setLayout, onLayoutChange }) { +export default function Canvas({ view, setView, layout, setLayout, onLayoutChange }) { const recipe = useRecipe({ key: "canvas" }); const styles = recipe(); return ( {view === "widget" && - + - + My Dashboard @@ -131,7 +136,7 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) { {/* CANVAS */} - + - + setLayout( newLayout )} diff --git a/client/src/components/layout/Sidebar/Sidebar.jsx b/client/src/components/layout/Sidebar/Sidebar.jsx index 1db12b9..6c8ca8d 100644 --- a/client/src/components/layout/Sidebar/Sidebar.jsx +++ b/client/src/components/layout/Sidebar/Sidebar.jsx @@ -7,9 +7,10 @@ import { FaGlobeAmericas } from "react-icons/fa"; import { FaMapMarkerAlt } from "react-icons/fa"; import { HiUsers } from "react-icons/hi2"; import { VscThreeBars } from "react-icons/vsc"; -import { useState } from "react"; +import { useState, useEffect } from "react"; +import { Seismic } from "../Canvas/views/DashboardCanvasNav/Seismic"; -export default function Sidebar({ onChangeView }) { +export default function Sidebar({ view, onChangeView }) { const [isOpen, setIsOpen] = useState(true); const [activeButton, setActiveButton] = useState(0) @@ -30,6 +31,25 @@ export default function Sidebar({ onChangeView }) { else setIsOpen(true); }; + // Track currrent view from both Sidebar and Canvas when 'view' changes + useEffect(() => { + console.log("Current view = ", view); + const dashboardViews = ["widget", "gas", "seismic", "remote", "activity"]; + + const newIndex = buttons.findIndex((btn) => { + if (btn.view === "widget") { + return dashboardViews.includes(view); // Group match + } + return btn.view === view; // Exact match + }); + + if (newIndex !== -1 ) { + setActiveButton(newIndex); + } + }, [view]); + + + return ( { - setActiveButton(idx); + // setActiveButton(idx); onChangeView(button.view); // Trigger state change in Dashboard }} bg={activeButton === idx ? "primary":undefined}