diff --git a/client/src/components/layout/Canvas/Canvas.jsx b/client/src/components/layout/Canvas/Canvas.jsx index 3067854..d94300e 100644 --- a/client/src/components/layout/Canvas/Canvas.jsx +++ b/client/src/components/layout/Canvas/Canvas.jsx @@ -8,19 +8,24 @@ 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, layout, setLayout, onLayoutChange }) { +export default function Canvas({ view, setView, layout, setLayout, onLayoutChange }) { const recipe = useRecipe({ key: "canvas" }); const styles = recipe(); return ( - {view === "widget" && - } + /> + )} {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 1773555..4b7bf4c 100644 --- a/client/src/components/layout/Canvas/views/DashboardCanvas.jsx +++ b/client/src/components/layout/Canvas/views/DashboardCanvas.jsx @@ -10,7 +10,7 @@ import { useState, useEffect, useDebugValue } from "react"; import { CancelButton } from "../components/CancelButton"; import { SaveButton } from "../components/SaveButton"; -export function DashboardCanvas({ layout, setLayout, onLayoutChange }) { +export function DashboardCanvas({ view, setView, layout, setLayout, onLayoutChange }) { const [isEditable, setIsEditable] = useState(false); // editable=true means static=false (vice versa) const [isDelete, setIsDelete] = useState(false); const [newCounter, setNewCounter] = useState(3); @@ -81,7 +81,24 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) { return ( /* HEADER */ - + { + const nextView = e.value; + + if (view === "widget" && isEditable && nextView !== "widget") { + const confirmed = window.confirm( + "You have unsaved changes. Do you wish to discard them and continue?" + ); + if (!confirmed) return; + onCancel(); + } + setView(nextView); + }} + > - + My Dashboard @@ -103,10 +120,10 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) { Seismic - + Remote Sensing - + Daily Activity @@ -131,7 +148,7 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) { {/* CANVAS */} - + - + - + diff --git a/client/src/components/layout/Dashboard.jsx b/client/src/components/layout/Dashboard.jsx index 76275d5..cf76695 100644 --- a/client/src/components/layout/Dashboard.jsx +++ b/client/src/components/layout/Dashboard.jsx @@ -64,11 +64,14 @@ export default function Dashboard() {
- + setLayout( newLayout )} diff --git a/client/src/components/layout/Sidebar/Sidebar.jsx b/client/src/components/layout/Sidebar/Sidebar.jsx index d78d689..7cff5a5 100644 --- a/client/src/components/layout/Sidebar/Sidebar.jsx +++ b/client/src/components/layout/Sidebar/Sidebar.jsx @@ -8,9 +8,11 @@ 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"; +import { DASHBOARD_VIEWS } from "@/constants/viewKeys"; -export default function Sidebar({ onChangeView }) { +export default function Sidebar({ view, onChangeView }) { const [isOpen, setIsOpen] = useState(true); const [activeButton, setActiveButton] = useState(0) const recipe = useSlotRecipe({ key: "sidebar" }); @@ -30,6 +32,24 @@ export default function Sidebar({ onChangeView }) { else setIsOpen(true); }; + // 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", "daily"]; + + const newIndex = buttons.findIndex((btn) => { + if (btn.view === "widget") { + return DASHBOARD_VIEWS.includes(view); // Group match + } + return btn.view === view; // Exact match + }); + + if (newIndex !== -1 ) { + setActiveButton(newIndex); + } + }, [view]); + return (