2025-07-31 09:50:40 -07:00
|
|
|
import { HStack, Flex, Tabs } from "@chakra-ui/react";
|
2025-08-05 15:08:18 -07:00
|
|
|
import MyDashboard from "./HomeTabs/MyDashboard";
|
2025-08-05 12:57:18 -07:00
|
|
|
import { SearchBar } from "../CanvasComponents/SearchBar";
|
|
|
|
|
import { SettingsButton } from "../CanvasComponents/SettingsButton";
|
|
|
|
|
import { DailyActivity } from "./HomeTabs/DailyActivity";
|
|
|
|
|
import { Gas } from "./HomeTabs/Gas";
|
|
|
|
|
import { Seismic } from "./HomeTabs/Seismic";
|
|
|
|
|
import { RemoteSensing } from "./HomeTabs/RemoteSensing";
|
2025-09-26 12:01:48 -07:00
|
|
|
import { Deformation } from "./HomeTabs/Deformation"
|
2025-08-05 12:57:18 -07:00
|
|
|
import { CancelButton } from "../CanvasComponents/CancelButton";
|
|
|
|
|
import { SaveButton } from "../CanvasComponents/SaveButton";
|
|
|
|
|
import DeleteAllButton from "../CanvasComponents/DeleteAllButton";
|
2025-08-06 16:27:08 -07:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2025-09-05 20:15:00 +00:00
|
|
|
import { CanvasHeaderTabs } from '../CanvasComponents/CanvasHeaderTabs';
|
|
|
|
|
import { DASHBOARD_TABS } from "@/constants/viewKeys";
|
2025-08-06 16:27:08 -07:00
|
|
|
|
2025-08-12 15:27:33 -07:00
|
|
|
export default function Home(props) {
|
2025-08-04 15:38:19 -07:00
|
|
|
// deconstructing props
|
2025-08-11 14:40:05 -07:00
|
|
|
const { view, layout, setLayout, setOriginalLayout, onLayoutChange, onChangeView, onCancel, setOriginalWidgets,
|
2025-08-11 14:17:21 -07:00
|
|
|
isDelete, setIsDelete, beginEditIfNeeded, isEditable, setIsEditable, widgetArray, setWidgetArray } = props;
|
2025-07-24 12:08:10 -07:00
|
|
|
|
2025-08-11 14:17:21 -07:00
|
|
|
function appendWidget(name, w, h, minw, minh, maxw, maxh) {
|
|
|
|
|
beginEditIfNeeded(); // Save state before anything else
|
|
|
|
|
|
|
|
|
|
const newID = uuid(); // could be replaced with something else like guid
|
2025-08-11 14:53:17 -07:00
|
|
|
const COLS = 16;
|
|
|
|
|
const W = w ?? 3;
|
|
|
|
|
const H = h ?? 3;
|
|
|
|
|
|
2025-08-11 14:17:21 -07:00
|
|
|
setWidgetArray([ // updating widget array containing info on the types of widgets
|
|
|
|
|
...widgetArray,
|
|
|
|
|
{i: newID, widget: name }
|
|
|
|
|
]);
|
|
|
|
|
// onAddWidget(newID, w, h, minw, minh, maxw, maxh); // updating array containing info on layout of widgets
|
|
|
|
|
|
2025-07-24 12:08:10 -07:00
|
|
|
setLayout(prev => [
|
2025-08-04 12:04:33 -07:00
|
|
|
...prev,
|
|
|
|
|
{
|
2025-08-11 14:17:21 -07:00
|
|
|
i: newID,
|
2025-08-11 14:53:17 -07:00
|
|
|
x: (prev.length * W) % COLS,
|
|
|
|
|
y: 0,
|
2025-08-06 16:27:08 -07:00
|
|
|
w: w,
|
|
|
|
|
h: h,
|
|
|
|
|
minW: minw,
|
|
|
|
|
minH: minh,
|
|
|
|
|
maxW: maxw,
|
|
|
|
|
maxH: maxh,
|
2025-08-06 12:03:48 -07:00
|
|
|
static: false,
|
|
|
|
|
resizeHandles: ['se']
|
2025-08-11 14:17:21 -07:00
|
|
|
},
|
2025-07-24 12:08:10 -07:00
|
|
|
]);
|
2025-08-06 16:27:08 -07:00
|
|
|
}
|
|
|
|
|
|
2025-07-25 11:40:57 -07:00
|
|
|
const onSave = () => {
|
2025-07-28 12:44:17 -07:00
|
|
|
console.log("saving widgets...");
|
2025-07-31 14:01:08 -07:00
|
|
|
// Set all widgets back to static: true
|
|
|
|
|
setLayout(prevLayout =>
|
|
|
|
|
prevLayout.map(item => ({
|
|
|
|
|
...item,
|
2025-07-25 11:40:57 -07:00
|
|
|
static: true
|
2025-07-31 14:01:08 -07:00
|
|
|
}))
|
|
|
|
|
);
|
2025-07-25 11:40:57 -07:00
|
|
|
setIsEditable(false);
|
2025-07-28 12:44:17 -07:00
|
|
|
setIsDelete(false);
|
2025-07-31 14:01:08 -07:00
|
|
|
setOriginalLayout([]); // Clear backup layout
|
2025-08-11 14:17:21 -07:00
|
|
|
setOriginalWidgets([]);
|
2025-07-24 16:05:42 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-12 15:27:33 -07:00
|
|
|
const onEditWidgets = () => {
|
2025-07-28 12:44:17 -07:00
|
|
|
console.log("Start deleting widgets...");
|
2025-08-12 13:57:58 -07:00
|
|
|
beginEditIfNeeded(); // Save state before anything else
|
2025-08-12 15:27:33 -07:00
|
|
|
setLayout(prevLayout =>
|
|
|
|
|
prevLayout.map(item => ({
|
|
|
|
|
...item,
|
|
|
|
|
static: false
|
|
|
|
|
}))
|
|
|
|
|
);
|
2025-07-28 12:44:17 -07:00
|
|
|
setIsEditable(true);
|
|
|
|
|
setIsDelete(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 15:38:19 -07:00
|
|
|
const DeleteWidget = (ID) => {
|
|
|
|
|
console.log("Deleting widget with id: ", ID);
|
|
|
|
|
setLayout(layout => layout.filter(w => w.i !== ID));
|
2025-08-05 15:19:46 -07:00
|
|
|
setWidgetArray(widgetArray => widgetArray.filter(w => w.i !== ID));
|
2025-07-24 12:08:10 -07:00
|
|
|
}
|
|
|
|
|
|
2025-07-31 09:50:40 -07:00
|
|
|
const DeleteAll = () => {
|
|
|
|
|
const confirm = window.confirm(
|
|
|
|
|
"Are you sure you want to delete all widgets?"
|
|
|
|
|
);
|
|
|
|
|
if (confirm) {
|
|
|
|
|
setLayout([]);
|
2025-08-04 12:04:33 -07:00
|
|
|
setWidgetArray([]);
|
2025-07-31 09:50:40 -07:00
|
|
|
onSave();
|
|
|
|
|
}
|
|
|
|
|
else return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 15:38:19 -07:00
|
|
|
// Prop Forwarding
|
2025-08-11 14:17:21 -07:00
|
|
|
const MyDashboardProps = { layout, onLayoutChange, isEditable, beginEditIfNeeded, isDelete, DeleteWidget, widgetArray, appendWidget };
|
2025-08-12 15:27:33 -07:00
|
|
|
const settingsButtonProps = { onEditWidgets, appendWidget };
|
2025-08-04 15:38:19 -07:00
|
|
|
|
2025-07-24 08:52:20 -07:00
|
|
|
return (
|
2025-07-24 12:08:10 -07:00
|
|
|
/* HEADER */
|
2025-07-29 09:59:17 -07:00
|
|
|
<Tabs.Root
|
2025-08-05 17:12:59 -07:00
|
|
|
width="100%"
|
|
|
|
|
height="100%"
|
2025-07-29 09:59:17 -07:00
|
|
|
lazyMount
|
|
|
|
|
value={ view }
|
2025-08-04 15:38:19 -07:00
|
|
|
variant="line"
|
2025-07-29 12:08:36 -07:00
|
|
|
// Prevent navigation away from 'My Dashboard' while in Edit mode
|
2025-07-29 11:51:33 -07:00
|
|
|
onValueChange={(e) => {
|
|
|
|
|
const nextView = e.value;
|
2025-07-31 12:23:45 -07:00
|
|
|
onChangeView(nextView);
|
2025-07-29 11:51:33 -07:00
|
|
|
}}
|
2025-07-29 09:59:17 -07:00
|
|
|
>
|
2025-07-24 08:52:20 -07:00
|
|
|
<Flex
|
|
|
|
|
as="header"
|
|
|
|
|
position="sticky"
|
|
|
|
|
top="0"
|
2025-07-28 11:44:25 -07:00
|
|
|
zIndex="dropdown" // zIndex: 1100
|
2025-07-24 08:52:20 -07:00
|
|
|
bg="base200"
|
2025-09-05 20:15:00 +00:00
|
|
|
pl={5}
|
|
|
|
|
pr={2}
|
2025-07-29 11:08:36 -07:00
|
|
|
pt={3}
|
2025-08-06 16:25:54 -07:00
|
|
|
pb={2}
|
2025-07-24 08:52:20 -07:00
|
|
|
align="center"
|
|
|
|
|
justify="space-between"
|
2025-08-05 17:12:59 -07:00
|
|
|
width="100%"
|
2025-07-24 08:52:20 -07:00
|
|
|
>
|
2025-09-05 20:15:00 +00:00
|
|
|
<CanvasHeaderTabs tabs={DASHBOARD_TABS} />
|
2025-08-05 17:12:59 -07:00
|
|
|
<HStack width="258px" justifyContent="flex-end">
|
2025-07-31 09:50:40 -07:00
|
|
|
{isEditable ? (
|
2025-07-25 11:40:57 -07:00
|
|
|
<>
|
2025-07-31 09:50:40 -07:00
|
|
|
<SaveButton onSave={ onSave } />
|
|
|
|
|
<CancelButton onCancel={ onCancel } />
|
|
|
|
|
{isDelete ? (
|
|
|
|
|
<DeleteAllButton onDeleteAll={ DeleteAll } />
|
|
|
|
|
):(null)
|
|
|
|
|
}
|
2025-07-25 11:40:57 -07:00
|
|
|
</>
|
|
|
|
|
):(
|
|
|
|
|
<>
|
|
|
|
|
<SearchBar />
|
2025-08-04 15:38:19 -07:00
|
|
|
<SettingsButton {...settingsButtonProps}/>
|
2025-07-25 11:40:57 -07:00
|
|
|
</>
|
|
|
|
|
)}
|
2025-07-24 08:52:20 -07:00
|
|
|
</HStack>
|
|
|
|
|
</Flex>
|
|
|
|
|
|
2025-07-24 12:08:10 -07:00
|
|
|
{/* CANVAS */}
|
2025-08-05 15:08:18 -07:00
|
|
|
<Tabs.Content value="mydashboard">
|
|
|
|
|
<MyDashboard {...MyDashboardProps}/>
|
2025-07-24 08:52:20 -07:00
|
|
|
</Tabs.Content>
|
|
|
|
|
<Tabs.Content value="gas">
|
|
|
|
|
<Gas />
|
|
|
|
|
</Tabs.Content>
|
|
|
|
|
<Tabs.Content value="seismic">
|
|
|
|
|
<Seismic />
|
|
|
|
|
</Tabs.Content>
|
2025-07-29 11:04:29 -07:00
|
|
|
<Tabs.Content value="remote">
|
2025-07-24 08:52:20 -07:00
|
|
|
<RemoteSensing />
|
|
|
|
|
</Tabs.Content>
|
2025-09-26 12:01:48 -07:00
|
|
|
<Tabs.Content value="deformation">
|
|
|
|
|
<Deformation />
|
|
|
|
|
</Tabs.Content>
|
2025-07-29 11:04:29 -07:00
|
|
|
<Tabs.Content value="daily">
|
2025-07-24 08:52:20 -07:00
|
|
|
<DailyActivity />
|
|
|
|
|
</Tabs.Content>
|
|
|
|
|
</Tabs.Root>
|
|
|
|
|
);
|
|
|
|
|
}
|