import { HStack, Flex, Tabs } from "@chakra-ui/react"; import MyDashboard from "./HomeTabs/MyDashboard"; 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"; import { Deformation } from "./HomeTabs/Deformation" import { CancelButton } from "../CanvasComponents/CancelButton"; import { SaveButton } from "../CanvasComponents/SaveButton"; import DeleteAllButton from "../CanvasComponents/DeleteAllButton"; import { v4 as uuid } from 'uuid'; import { CanvasHeaderTabs } from '../CanvasComponents/CanvasHeaderTabs'; import { DASHBOARD_TABS } from "@/constants/viewKeys"; export default function Home(props) { // deconstructing props const { view, layout, setLayout, setOriginalLayout, onLayoutChange, onChangeView, onCancel, setOriginalWidgets, isDelete, setIsDelete, beginEditIfNeeded, isEditable, setIsEditable, widgetArray, setWidgetArray } = props; 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 const COLS = 16; const W = w ?? 3; const H = h ?? 3; 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 setLayout(prev => [ ...prev, { i: newID, x: (prev.length * W) % COLS, y: 0, w: w, h: h, minW: minw, minH: minh, maxW: maxw, maxH: maxh, static: false, resizeHandles: ['se'] }, ]); } const onSave = () => { console.log("saving widgets..."); // Set all widgets back to static: true setLayout(prevLayout => prevLayout.map(item => ({ ...item, static: true })) ); setIsEditable(false); setIsDelete(false); setOriginalLayout([]); // Clear backup layout setOriginalWidgets([]); } const onEditWidgets = () => { console.log("Start deleting widgets..."); beginEditIfNeeded(); // Save state before anything else setLayout(prevLayout => prevLayout.map(item => ({ ...item, static: false })) ); setIsEditable(true); setIsDelete(true); } const DeleteWidget = (ID) => { console.log("Deleting widget with id: ", ID); setLayout(layout => layout.filter(w => w.i !== ID)); setWidgetArray(widgetArray => widgetArray.filter(w => w.i !== ID)); } const DeleteAll = () => { const confirm = window.confirm( "Are you sure you want to delete all widgets?" ); if (confirm) { setLayout([]); setWidgetArray([]); onSave(); } else return; } // Prop Forwarding const MyDashboardProps = { layout, onLayoutChange, isEditable, beginEditIfNeeded, isDelete, DeleteWidget, widgetArray, appendWidget }; const settingsButtonProps = { onEditWidgets, appendWidget }; return ( /* HEADER */ { const nextView = e.value; onChangeView(nextView); }} > {isEditable ? ( <> {isDelete ? ( ):(null) } ):( <> )} {/* CANVAS */} ); }