From f18c2603ee3083000ac227b0d265cb8de02e8840 Mon Sep 17 00:00:00 2001 From: Cannon Lock Date: Thu, 14 Dec 2023 16:10:31 -0600 Subject: [PATCH] Allow clearing of commits --- src/pages/maps/@id/edit/edit-page.ts | 2 +- src/pages/maps/@id/edit/edit-table.ts | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pages/maps/@id/edit/edit-page.ts b/src/pages/maps/@id/edit/edit-page.ts index 197777fe..ee7dac6a 100644 --- a/src/pages/maps/@id/edit/edit-page.ts +++ b/src/pages/maps/@id/edit/edit-page.ts @@ -3,7 +3,7 @@ import styles from "./edit-page.module.sass"; import { useState } from "react"; import EditTable from "./edit-table"; import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; -import { LinkButton } from "~/map-interface/components/buttons"; +import { LinkButton } from "~/pages/map/map-interface/components/buttons"; import { WidthAdjustablePanel } from "./components"; import MapInterface from "./map-interface"; import { useStoredState } from "@macrostrat/ui-components"; diff --git a/src/pages/maps/@id/edit/edit-table.ts b/src/pages/maps/@id/edit/edit-table.ts index 38d56e5e..597ddd33 100644 --- a/src/pages/maps/@id/edit/edit-table.ts +++ b/src/pages/maps/@id/edit/edit-table.ts @@ -1,7 +1,5 @@ import hyper from "@macrostrat/hyper"; - - import { useState, useEffect, useCallback, useRef, useLayoutEffect, useMemo, FunctionComponent } from "react"; import { HotkeysProvider, InputGroup, Button, useHotkeys } from "@blueprintjs/core"; import { Spinner, ButtonGroup } from "@blueprintjs/core"; @@ -85,23 +83,25 @@ export default function TableInterface({ url }: EditTableProps) { return data.length ? Object.keys(data[0]).filter(x => x != "_pkid") : [] }, [data]) - const setTableUpdates = useCallback((newTableUpdates: TableUpdate[]) => { + const setTableUpdates = useCallback(async (newTableUpdates: TableUpdate[]) => { // If the table updates are empty, reset the data if (newTableUpdates.length == 0) { - getData() + let newData = await getData(newTableUpdates, dataParameters) + setData(newData) } // If a new update is available apply it to the data if(newTableUpdates.length > tableUpdates.length){ - setData(applyTableUpdate(data, newTableUpdates.slice(-1)[0])) + let newData = applyTableUpdate(data, newTableUpdates.slice(-1)[0]) + setData(newData) } _setTableUpdates(newTableUpdates) - }, [tableUpdates, data]) + }, [data, tableUpdates, dataParameters]) - const getData = useCallback( async () => { + const getData = useCallback( async (tableUpdates: TableUpdate[], dataParameters: DataParameters) => { const dataURL = buildURL(url, dataParameters) @@ -116,18 +116,19 @@ export default function TableInterface({ url }: EditTableProps) { } else { setError(undefined) - setData(data) } // Remove the progress bar on data reload setUpdateProgress(undefined) return data - }, [dataParameters, tableUpdates]) + }, []) // On mount get data useEffect(() => { - getData() + (async () => { + setData(await getData(tableUpdates, dataParameters)) + })() }, [dataParameters]) const handlePaste = useCallback(() => { @@ -203,7 +204,6 @@ export default function TableInterface({ url }: EditTableProps) { } setTableUpdates([]) - getData() }, [tableUpdates]) const columnHeaderCellRenderer = useCallback((columnIndex: number) => { @@ -301,8 +301,6 @@ export default function TableInterface({ url }: EditTableProps) { }) } - console.log("TableUpdates", tableUpdates, tableUpdates.length, tableUpdates.length == 0) - return h("div", { onKeyDown: handleKeyDown, onKeyUp: handleKeyUp,