Skip to content

Commit

Permalink
Allow clearing of commits
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Dec 14, 2023
1 parent e04b520 commit f18c260
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/pages/maps/@id/edit/edit-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
24 changes: 11 additions & 13 deletions src/pages/maps/@id/edit/edit-table.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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)

Expand All @@ -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(() => {
Expand Down Expand Up @@ -203,7 +204,6 @@ export default function TableInterface({ url }: EditTableProps) {
}

setTableUpdates([])
getData()
}, [tableUpdates])

const columnHeaderCellRenderer = useCallback((columnIndex: number) => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f18c260

Please sign in to comment.