2025-07-23 11:01:25 -07:00
|
|
|
import Header from './Header/Header.jsx';
|
|
|
|
|
import Sidebar from './Sidebar/Sidebar.jsx';
|
|
|
|
|
import Canvas from './Canvas/Canvas.jsx';
|
2025-08-11 15:10:58 -07:00
|
|
|
import { Grid, GridItem, useRecipe, useDialog } from '@chakra-ui/react';
|
2025-07-23 11:35:28 -07:00
|
|
|
import { useState } from 'react';
|
2025-08-11 15:10:58 -07:00
|
|
|
import DialogPopup from './Canvas/CanvasComponents/DialogPopup.jsx';
|
2025-07-23 11:01:25 -07:00
|
|
|
|
|
|
|
|
export default function Dashboard() {
|
2025-07-28 13:32:03 -07:00
|
|
|
const recipe = useRecipe({ key: "dashboard" });
|
2025-07-23 11:01:25 -07:00
|
|
|
const styles = recipe();
|
|
|
|
|
|
2025-07-31 08:56:32 -07:00
|
|
|
const [darkMode, setDarkMode] = useState(false);
|
2025-07-31 12:23:45 -07:00
|
|
|
const [isEditable, setIsEditable] = useState(false); // editable=true means static=false (vice versa)
|
|
|
|
|
const [isDelete, setIsDelete] = useState(false);
|
|
|
|
|
const [originalLayout, setOriginalLayout] = useState([]);
|
2025-08-05 15:08:18 -07:00
|
|
|
const [view, setView] = useState("mydashboard");
|
2025-08-04 12:04:33 -07:00
|
|
|
const [layout, setLayout] = useState([]);
|
2025-08-04 15:38:19 -07:00
|
|
|
const [widgetArray, setWidgetArray] = useState([]);
|
2025-08-11 15:10:58 -07:00
|
|
|
const dialog = useDialog();
|
2025-07-25 13:19:09 -07:00
|
|
|
|
2025-07-31 12:40:46 -07:00
|
|
|
const onCancel = () => {
|
2025-08-06 12:38:04 -07:00
|
|
|
// This is a test comment
|
2025-07-31 12:40:46 -07:00
|
|
|
console.log("canceling changes...");
|
|
|
|
|
if (originalLayout.length) {
|
|
|
|
|
setLayout(originalLayout.map(item => ({
|
|
|
|
|
...item,
|
|
|
|
|
static: true
|
|
|
|
|
})));
|
|
|
|
|
};
|
|
|
|
|
setIsEditable(false);
|
|
|
|
|
setIsDelete(false);
|
|
|
|
|
setOriginalLayout([]);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 12:23:45 -07:00
|
|
|
// Prevent navigation while in Edit mode without saving or cancelling
|
|
|
|
|
const handleViewChange = (nextView) => {
|
2025-08-06 12:27:27 -07:00
|
|
|
if (view === "mydashboard" && isEditable) {
|
2025-08-11 15:10:58 -07:00
|
|
|
dialog.open();
|
|
|
|
|
<DialogPopup dialog={dialog}/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const confirmed = window.confirm(
|
|
|
|
|
// "You have unsaved changes. Discard them and continue?"
|
|
|
|
|
// );
|
|
|
|
|
// if (!confirmed) return;
|
|
|
|
|
// onCancel();
|
2025-07-31 12:23:45 -07:00
|
|
|
}
|
|
|
|
|
setView(nextView);
|
|
|
|
|
};
|
2025-08-04 15:38:19 -07:00
|
|
|
|
|
|
|
|
const onLayoutChange = (newLayout) => setLayout(newLayout);
|
2025-07-31 12:23:45 -07:00
|
|
|
|
2025-08-04 15:38:19 -07:00
|
|
|
// Prop Forwarding
|
|
|
|
|
const canvasProps = { view, layout, setLayout, setOriginalLayout, onLayoutChange, onChangeView: handleViewChange,
|
|
|
|
|
onCancel, isEditable, setIsEditable, isDelete, setIsDelete, widgetArray, setWidgetArray
|
|
|
|
|
};
|
|
|
|
|
const sidebarProps = { view, onChangeView: handleViewChange, darkMode, setDarkMode };
|
|
|
|
|
const headerProps = { onChangeView: handleViewChange };
|
|
|
|
|
|
2025-07-23 11:01:25 -07:00
|
|
|
return (
|
2025-07-23 21:31:18 +00:00
|
|
|
<Grid css={styles}
|
|
|
|
|
templateRows="1fr 11fr"
|
2025-07-31 14:51:25 -07:00
|
|
|
// templateColumns="1fr 20fr"
|
|
|
|
|
templateColumns="auto 1fr"
|
2025-07-23 21:31:18 +00:00
|
|
|
height="100vh"
|
|
|
|
|
width="100vw"
|
|
|
|
|
>
|
|
|
|
|
<GridItem rowSpan={1} colSpan={2}>
|
2025-08-04 15:38:19 -07:00
|
|
|
<Header {...headerProps}/>
|
2025-07-23 21:31:18 +00:00
|
|
|
</GridItem>
|
|
|
|
|
<GridItem colSpan={1}>
|
2025-08-04 15:38:19 -07:00
|
|
|
<Sidebar {...sidebarProps}/>
|
2025-07-23 21:31:18 +00:00
|
|
|
</GridItem>
|
2025-07-24 13:48:41 -07:00
|
|
|
<GridItem colSpan={1} width="100%" overflow="auto">
|
2025-08-04 15:38:19 -07:00
|
|
|
<Canvas {...canvasProps}/>
|
2025-08-04 12:04:33 -07:00
|
|
|
</GridItem>
|
2025-07-23 21:31:18 +00:00
|
|
|
</Grid>
|
2025-07-23 11:01:25 -07:00
|
|
|
);
|
2025-07-23 21:31:18 +00:00
|
|
|
}
|