From 958a2e366f6cd779350a8f0c06596430a48ea079 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Wed, 8 Dec 2021 11:34:28 +0100 Subject: [PATCH] tweak: Moved state variable to comparisonView body --- lib/comparisonView.js | 10 +++++++--- lib/findPaths.js | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/comparisonView.js b/lib/comparisonView.js index 794b65f..13d474c 100644 --- a/lib/comparisonView.js +++ b/lib/comparisonView.js @@ -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} > diff --git a/lib/findPaths.js b/lib/findPaths.js index 144f2dd..caea418 100644 --- a/lib/findPaths.js +++ b/lib/findPaths.js @@ -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 })