From 89c32e4f6ecfd5ba3ef0da9a5758fbe9c9ed6ef5 Mon Sep 17 00:00:00 2001 From: "Daniel S. Hansen" Date: Tue, 29 Jul 2025 11:04:29 -0700 Subject: [PATCH] Add keyViews.js file inside src/constants to track current view in Sidebar and Canvas --- client/src/components/layout/Canvas/Canvas.jsx | 7 +++++-- .../layout/Canvas/views/DashboardCanvas.jsx | 14 ++++++++------ client/src/components/layout/Sidebar/Sidebar.jsx | 8 ++++---- client/src/constants/viewKeys.js | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 client/src/constants/viewKeys.js diff --git a/client/src/components/layout/Canvas/Canvas.jsx b/client/src/components/layout/Canvas/Canvas.jsx index e097f28..9280c4b 100644 --- a/client/src/components/layout/Canvas/Canvas.jsx +++ b/client/src/components/layout/Canvas/Canvas.jsx @@ -8,6 +8,7 @@ import RegionalMapCanvas from "./views/RegionalMapCanvas"; import VolcanoCanvas from "./views/VolcanoCanvas"; import AdminCanvas from "./views/AdminCanvas"; import { DashboardCanvas } from "./views/DashboardCanvas"; +import { DASHBOARD_VIEWS } from "@/constants/viewKeys"; export default function Canvas({ view, setView, layout, setLayout, onLayoutChange }) { const recipe = useRecipe({ key: "canvas" }); @@ -15,14 +16,16 @@ export default function Canvas({ view, setView, layout, setLayout, onLayoutChang return ( - {view === "widget" && + {/* {view === "widget" && */} + { DASHBOARD_VIEWS.includes(view) && ( } + /> + )} {view === "global" && } {view === "regional" && } {view === "volcano" && } diff --git a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx index 239d2bd..1b5a3a0 100644 --- a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx +++ b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx @@ -83,9 +83,11 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan /* HEADER */ setView(e.value)} + // onValueChange={(value) => setView(value)} > Seismic - + Remote Sensing - + Daily Activity @@ -151,10 +153,10 @@ export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChan - + - + diff --git a/client/src/components/layout/Sidebar/Sidebar.jsx b/client/src/components/layout/Sidebar/Sidebar.jsx index 6c8ca8d..3ff8794 100644 --- a/client/src/components/layout/Sidebar/Sidebar.jsx +++ b/client/src/components/layout/Sidebar/Sidebar.jsx @@ -9,6 +9,7 @@ import { HiUsers } from "react-icons/hi2"; import { VscThreeBars } from "react-icons/vsc"; import { useState, useEffect } from "react"; import { Seismic } from "../Canvas/views/DashboardCanvasNav/Seismic"; +import { DASHBOARD_VIEWS } from "@/constants/viewKeys"; export default function Sidebar({ view, onChangeView }) { const [isOpen, setIsOpen] = useState(true); @@ -33,12 +34,13 @@ export default function Sidebar({ view, onChangeView }) { // Track currrent view from both Sidebar and Canvas when 'view' changes useEffect(() => { + console.log("typeof view =", typeof view); console.log("Current view = ", view); - const dashboardViews = ["widget", "gas", "seismic", "remote", "activity"]; + // const dashboardViews = ["widget", "gas", "seismic", "remote", "daily"]; const newIndex = buttons.findIndex((btn) => { if (btn.view === "widget") { - return dashboardViews.includes(view); // Group match + return DASHBOARD_VIEWS.includes(view); // Group match } return btn.view === view; // Exact match }); @@ -47,8 +49,6 @@ export default function Sidebar({ view, onChangeView }) { setActiveButton(newIndex); } }, [view]); - - return (