From b432c8a8ec98f6aa78a4e49a235c072cb9db7b08 Mon Sep 17 00:00:00 2001 From: "Daniel S. Hansen" Date: Wed, 23 Jul 2025 11:01:25 -0700 Subject: [PATCH 1/3] Add Dashboard parent component to Header, Siderbar, Canvas in order to faciliate lifting state --- client/src/App.jsx | 45 +------------------ client/src/components/layout/Dashboard.jsx | 50 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 43 deletions(-) create mode 100644 client/src/components/layout/Dashboard.jsx diff --git a/client/src/App.jsx b/client/src/App.jsx index c60c2f9..ad2140b 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -1,49 +1,8 @@ -import { Global, css } from "@emotion/react"; -import Header from './components/layout/Header/Header.jsx'; -import Sidebar from './components/layout/Sidebar/Sidebar.jsx'; -import Canvas from './components/layout/Canvas/Canvas.jsx'; -import { Grid, GridItem, useRecipe, Box } from '@chakra-ui/react'; +import Dashboard from './components/layout/Dashboard.jsx' function App() { - const recipe = useRecipe({ key: "canvas" }); - const styles = recipe(); - return ( - <> - - - -
- - - - - - - - - + ); } diff --git a/client/src/components/layout/Dashboard.jsx b/client/src/components/layout/Dashboard.jsx new file mode 100644 index 0000000..eeb1042 --- /dev/null +++ b/client/src/components/layout/Dashboard.jsx @@ -0,0 +1,50 @@ +import { Global, css } from "@emotion/react"; +import Header from './Header/Header.jsx'; +import Sidebar from './Sidebar/Sidebar.jsx'; +import Canvas from './Canvas/Canvas.jsx'; +import { Grid, GridItem, useRecipe, Box } from '@chakra-ui/react'; + +export default function Dashboard() { + const recipe = useRecipe({ key: "canvas" }); + const styles = recipe(); + + return ( + <> + + + +
+ + + + + + + + + + ); +} + + From 0ec105d9ec93978abd2c86805d0aedf8d13a4638 Mon Sep 17 00:00:00 2001 From: "Daniel S. Hansen" Date: Wed, 23 Jul 2025 11:35:28 -0700 Subject: [PATCH 2/3] Add view and setView props in order to successfully pass state from Sidebar to the Canvas inside Dashboard --- .../src/components/layout/Canvas/Canvas.jsx | 6 +++--- client/src/components/layout/Dashboard.jsx | 10 +++++++--- .../src/components/layout/Sidebar/Sidebar.jsx | 19 +++++++++++-------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/client/src/components/layout/Canvas/Canvas.jsx b/client/src/components/layout/Canvas/Canvas.jsx index ef6e2a8..bfdf7dd 100644 --- a/client/src/components/layout/Canvas/Canvas.jsx +++ b/client/src/components/layout/Canvas/Canvas.jsx @@ -8,12 +8,12 @@ import WidgetCanvas from "./views/WidgetCanvas"; // import MapCanvas from "./views/MapCanvas"; // import AdminCanvas from "./views/AdminCanvas"; -export default function Canvas() { - const [view, setView] = useState("widget"); +export default function Canvas({ view }) { + // const [view, setView] = useState("widget"); return ( - + {view === "widget" && } {/* {view === "map" && } */} {/* {view === "admin" && } */} diff --git a/client/src/components/layout/Dashboard.jsx b/client/src/components/layout/Dashboard.jsx index eeb1042..11be033 100644 --- a/client/src/components/layout/Dashboard.jsx +++ b/client/src/components/layout/Dashboard.jsx @@ -2,12 +2,16 @@ import { Global, css } from "@emotion/react"; import Header from './Header/Header.jsx'; import Sidebar from './Sidebar/Sidebar.jsx'; import Canvas from './Canvas/Canvas.jsx'; -import { Grid, GridItem, useRecipe, Box } from '@chakra-ui/react'; +import { Grid, GridItem, useRecipe } from '@chakra-ui/react'; +import { useState } from 'react'; export default function Dashboard() { const recipe = useRecipe({ key: "canvas" }); const styles = recipe(); + // Lifted State - defaults to widget dashboard + const [view, setView] = useState("widget"); + return ( <> - + - + diff --git a/client/src/components/layout/Sidebar/Sidebar.jsx b/client/src/components/layout/Sidebar/Sidebar.jsx index 55de0b0..cbcf06b 100644 --- a/client/src/components/layout/Sidebar/Sidebar.jsx +++ b/client/src/components/layout/Sidebar/Sidebar.jsx @@ -57,18 +57,18 @@ export const Users = createIcon({ ), }); -export default function Sidebar() { +export default function Sidebar({ onChangeView }) { const [isOpen, setIsOpen] = useState(true); + const [activeButton, setActiveButton] = useState(0) const buttons = [ - {icon: PushPin, name: "Dashboard"}, - {icon: Globe, name: "Global Map"}, - {icon: MapMarker, name: "Regional Map"}, - {icon: FaVolcano, name: "Volcano"}, - {icon: Users, name: "Admin"} + {icon: PushPin, name: "Dashboard", view: "widget"}, + {icon: Globe, name: "Global Map", view: "global"}, + {icon: MapMarker, name: "Regional Map", view: "regional"}, + {icon: FaVolcano, name: "Volcano", view: "volcano"}, + {icon: Users, name: "Admin", view: "admin"} ]; - const [activeButton, setActiveButton] = useState(0) const recipe = useSlotRecipe({ key: "sidebar" }); const styles = recipe(); @@ -98,7 +98,10 @@ export default function Sidebar() { return (