tweak: Moved state variable to comparisonView body

This commit is contained in:
NunoSempere 2021-12-08 11:34:28 +01:00
parent f134df4b0a
commit 958a2e366f
2 changed files with 8 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import { DrawGraph, removeOldSvg } from './labeledgraph';
import { SubmitSliderButton } from "./slider";
import { DisplayElement } from './displayElement'
import { DisplayAsMarkdown } from './displayAsMarkdown'
import { CreateTable } from './findPaths'
import { CreateTable, buildRows } from './findPaths'
import { TextAreaForJson } from "./textAreaForJson"
import { pushToMongo } from "./pushToMongo.js"
import { maxMergeSortSteps, expectedNumMergeSortSteps } from "./utils.js"
@ -54,7 +54,7 @@ export default function ComparisonView({ listOfElementsForView }) {
let initialNumSteps = 0;
let initialMaxSteps = maxMergeSortSteps(listOfElementsForView.length)
let initialExpectedSteps = expectedNumMergeSortSteps(listOfElementsForView.length)
let initialTableRows = []
//let listOfElements = listOfElementsForView.map((element, i) => ({...element, id: i}))
//let list = increasingList(listOfElementsForView.length) // [0,1,2,3,4]
//let initialComparePair = [list[list.length-2], list[list.length-1]]
@ -79,6 +79,7 @@ export default function ComparisonView({ listOfElementsForView }) {
let [numSteps, changeNumSteps] = useState(initialNumSteps);
let [maxSteps, changeMaxSteps] = useState(initialMaxSteps)
let [expectedSteps, changeExpectedSteps] = useState(initialExpectedSteps)
let [tableRows, setTableRows] = useState(initialTableRows)
let restart = (posList) => {
setToComparePair([posList[posList.length - 2], posList[posList.length - 1]])
@ -212,10 +213,11 @@ export default function ComparisonView({ listOfElementsForView }) {
await pushToMongo(jsObject)
console.log(jsObject)
alert("Comparisons completed. Background work might take a while, or straight-out fail")
setTimeout(() => {
setTimeout(async () => {
// Make sure to do this after the
setIsListOrdered(true)
setOrderedList(result)
}, 500);
}
}
@ -333,6 +335,8 @@ export default function ComparisonView({ listOfElementsForView }) {
orderedList={orderedList}
listOfElements={listOfElements}
links={buildLinks(quantitativeComparisons)}
tableRows={tableRows}
setTableRows={setTableRows}
>
</CreateTable>
</div>

View File

@ -190,8 +190,7 @@ export async function buildRows({ isListOrdered, orderedList, listOfElements, li
// return rows
}
export function CreateTableWithDistances({ isListOrdered, orderedList, listOfElements, links }) {
const [tableRows, setTableRows] = useState([])
export function CreateTableWithDistances({ isListOrdered, orderedList, listOfElements, links, tableRows, setTableRows }) {
useEffect(async () => {
await buildRows({ isListOrdered, orderedList, listOfElements, links, rows: tableRows, setTableRows })