lots of file surgery, it works

This commit is contained in:
2025-07-24 12:08:10 -07:00
parent 2db5514f2c
commit 85160caae0
4 changed files with 62 additions and 47 deletions
@@ -6,9 +6,43 @@ import { DailyActivity } from "./DashboardCanvasNav/DailyActivity";
import { Gas } from "./DashboardCanvasNav/Gas";
import { Seismic } from "./DashboardCanvasNav/Seismic";
import { RemoteSensing } from "./DashboardCanvasNav/RemoteSensing";
import { useState } from "react";
export function DashboardCanvas() {
const [layout, setLayout] = useState([
{ i: '0', x: 0, y: 0, w: 3, h: 3, minH: 3, minW: 1, static: false },
{ i: '1', x: 3, y: 0, w: 3, h: 3, minH: 3, minW: 1, static: false },
{ i: '2', x: 6, y: 0, w: 3, h: 3, minH: 3, minW: 1, static: false }
]);
const [newCounter, setNewCounter] = useState(3);
const onAddWidget = () => {
const newId = newCounter.toString();
setLayout(prev => [
...prev,
{
i: newId,
x: (prev.length * 3) % 12,
y: Infinity,
w: 3,
h: 3
}
]);
setNewCounter(prev => prev + 1);
};
const onRemoveWidget = (id) => {
setLayout(prev => prev.filter(w => w.i !== id));
}
const onLayoutChange = (newLayout) => {
setLayout(newLayout);
console.log('Updated layout:', newLayout)
};
export function MyDashboardCanvas() {
return (
/* HEADER */
<Tabs.Root defaultValue="my dashboard">
<Flex
as="header"
@@ -40,12 +74,20 @@ export function MyDashboardCanvas() {
<HStack>
<SearchBar />
<SettingsButton />
<SettingsButton
onAddWidget={ onAddWidget }
// onEditWidgets={ onEditWidgets }
onDeleteWidgets={ onRemoveWidget }
/>
</HStack>
</Flex>
{/* CANVAS */}
<Tabs.Content value="my dashboard">
<WidgetCanvas />
<WidgetCanvas
layout={layout}
onLayoutChange={onLayoutChange}
/>
</Tabs.Content>
<Tabs.Content value="gas">
<Gas />
@@ -7,24 +7,13 @@ import GridLayout, { WidthProvider } from 'react-grid-layout';
import Widget from '../../components/Widget.jsx';
import { useSlotRecipe, chakra, Flex } from '@chakra-ui/react';
export default function WidgetCanvas() {
export default function WidgetCanvas({layout, onLayoutChange}) {
// Define widgets initial position and size
// TODO Add dynamic adding/deleting of widgets via options button
const recipe = useSlotRecipe({ key: "widget" });
const styles = recipe(); // using root recipe for widget below
const ResponsiveGridLayout = WidthProvider(GridLayout); // canvas width now adjusts to window size
const [layout, setLayout] = useState([
{ i: '0', x: 0, y: 0, w: 3, h: 3, minH: 3, minW: 1, static: false },
{ i: '1', x: 3, y: 0, w: 3, h: 3, minH: 3, minW: 1, static: false },
{ i: '2', x: 6, y: 0, w: 3, h: 3, minH: 3, minW: 1, static: false }
]);
const onLayoutChange = (newLayout) => {
setLayout(newLayout);
console.log('Updated layout:', newLayout)
};
// don't allow text highlighting when dragging
const handleDragStart = () => {
document.body.style.userSelect = "none";