Save point, page is rendering with view tracking
This commit is contained in:
@@ -9,7 +9,7 @@ import VolcanoCanvas from "./views/VolcanoCanvas";
|
|||||||
import AdminCanvas from "./views/AdminCanvas";
|
import AdminCanvas from "./views/AdminCanvas";
|
||||||
import { DashboardCanvas } from "./views/DashboardCanvas";
|
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 recipe = useRecipe({ key: "canvas" });
|
||||||
const styles = recipe();
|
const styles = recipe();
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@ export default function Canvas({ view, layout, setLayout, onLayoutChange }) {
|
|||||||
<Box height="100%" width="100%">
|
<Box height="100%" width="100%">
|
||||||
{view === "widget" &&
|
{view === "widget" &&
|
||||||
<DashboardCanvas
|
<DashboardCanvas
|
||||||
|
view={ view }
|
||||||
|
setView={ setView }
|
||||||
layout={ layout }
|
layout={ layout }
|
||||||
setLayout={ setLayout }
|
setLayout={ setLayout }
|
||||||
onLayoutChange={ onLayoutChange }
|
onLayoutChange={ onLayoutChange }
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { useState, useEffect, useDebugValue } from "react";
|
|||||||
import { CancelButton } from "../components/CancelButton";
|
import { CancelButton } from "../components/CancelButton";
|
||||||
import { SaveButton } from "../components/SaveButton";
|
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 [isEditable, setIsEditable] = useState(false); // editable=true means static=false (vice versa)
|
||||||
const [isDelete, setIsDelete] = useState(false);
|
const [isDelete, setIsDelete] = useState(false);
|
||||||
const [newCounter, setNewCounter] = useState(3);
|
const [newCounter, setNewCounter] = useState(3);
|
||||||
@@ -81,7 +81,12 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
/* HEADER */
|
/* HEADER */
|
||||||
<Tabs.Root lazyMount defaultValue="my dashboard">
|
<Tabs.Root
|
||||||
|
lazyMount
|
||||||
|
defaultValue="my dashboard"
|
||||||
|
value={ view }
|
||||||
|
onValueChange={ setView }
|
||||||
|
>
|
||||||
<Flex
|
<Flex
|
||||||
as="header"
|
as="header"
|
||||||
position="sticky"
|
position="sticky"
|
||||||
@@ -94,7 +99,7 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
|
|||||||
justify="space-between"
|
justify="space-between"
|
||||||
>
|
>
|
||||||
<Tabs.List>
|
<Tabs.List>
|
||||||
<Tabs.Trigger value="my dashboard">
|
<Tabs.Trigger value="widget">
|
||||||
My Dashboard
|
My Dashboard
|
||||||
</Tabs.Trigger>
|
</Tabs.Trigger>
|
||||||
<Tabs.Trigger value="gas">
|
<Tabs.Trigger value="gas">
|
||||||
@@ -131,7 +136,7 @@ export function DashboardCanvas({ layout, setLayout, onLayoutChange }) {
|
|||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
{/* CANVAS */}
|
{/* CANVAS */}
|
||||||
<Tabs.Content value="my dashboard">
|
<Tabs.Content value="widget">
|
||||||
<WidgetCanvas
|
<WidgetCanvas
|
||||||
layout={layout}
|
layout={layout}
|
||||||
onLayoutChange={onLayoutChange}
|
onLayoutChange={onLayoutChange}
|
||||||
|
|||||||
@@ -64,11 +64,14 @@ export default function Dashboard() {
|
|||||||
<Header />
|
<Header />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem colSpan={1}>
|
<GridItem colSpan={1}>
|
||||||
<Sidebar onChangeView={ setView }/>
|
<Sidebar
|
||||||
|
view={ view }
|
||||||
|
onChangeView={ setView }/>
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem colSpan={1} width="100%" overflow="auto">
|
<GridItem colSpan={1} width="100%" overflow="auto">
|
||||||
<Canvas
|
<Canvas
|
||||||
view={ view }
|
view={ view }
|
||||||
|
setView={ setView }
|
||||||
layout={ layout }
|
layout={ layout }
|
||||||
setLayout={ setLayout }
|
setLayout={ setLayout }
|
||||||
onLayoutChange={( newLayout ) => setLayout( newLayout )}
|
onLayoutChange={( newLayout ) => setLayout( newLayout )}
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import { FaGlobeAmericas } from "react-icons/fa";
|
|||||||
import { FaMapMarkerAlt } from "react-icons/fa";
|
import { FaMapMarkerAlt } from "react-icons/fa";
|
||||||
import { HiUsers } from "react-icons/hi2";
|
import { HiUsers } from "react-icons/hi2";
|
||||||
import { VscThreeBars } from "react-icons/vsc";
|
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 [isOpen, setIsOpen] = useState(true);
|
||||||
const [activeButton, setActiveButton] = useState(0)
|
const [activeButton, setActiveButton] = useState(0)
|
||||||
|
|
||||||
@@ -30,6 +31,25 @@ export default function Sidebar({ onChangeView }) {
|
|||||||
else setIsOpen(true);
|
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 (
|
return (
|
||||||
<Box
|
<Box
|
||||||
css={styles.root}
|
css={styles.root}
|
||||||
@@ -53,7 +73,7 @@ export default function Sidebar({ onChangeView }) {
|
|||||||
// key={idx}
|
// key={idx}
|
||||||
css={styles.buttons}
|
css={styles.buttons}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setActiveButton(idx);
|
// setActiveButton(idx);
|
||||||
onChangeView(button.view); // Trigger state change in Dashboard
|
onChangeView(button.view); // Trigger state change in Dashboard
|
||||||
}}
|
}}
|
||||||
bg={activeButton === idx ? "primary":undefined}
|
bg={activeButton === idx ? "primary":undefined}
|
||||||
|
|||||||
Reference in New Issue
Block a user