From 3d6a544a723176cf73f67bfb7f79e537c383a013 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Wed, 8 Dec 2021 11:56:20 +0100 Subject: [PATCH] feat: Refactored to avoid useState in lib/findPaths.js Note: This is important because it allows for restarting the utility-function extractor. It also makes for code which is more understandable. --- lib/comparisonView.js | 15 +++++++++++++-- lib/findPaths.js | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/comparisonView.js b/lib/comparisonView.js index 13d474c..f3c4259 100644 --- a/lib/comparisonView.js +++ b/lib/comparisonView.js @@ -88,8 +88,9 @@ export default function ComparisonView({ listOfElementsForView }) { setQuantitativeComparisons(initialQuantitativeComparisons) setIsListOrdered(initialIsListOdered) setOrderedList(initialOrderedList) - changeNumSteps(0) + changeNumSteps(initialNumSteps) removeOldSvg() + setTableRows(initialTableRows) } let changeDataSet = (listOfElementsNew) => { @@ -209,16 +210,26 @@ export default function ComparisonView({ listOfElementsForView }) { setReasoning('') changeNumSteps(numSteps + 1) if (successStatus) { + let jsObject = nicelyFormatLinks(quantitativeComparisons, listOfElements) await pushToMongo(jsObject) console.log(jsObject) + alert("Comparisons completed. Background work might take a while, or straight-out fail") setTimeout(async () => { // Make sure to do this after the setIsListOrdered(true) setOrderedList(result) - }, 500); + await buildRows({ + isListOrdered: true, + orderedList: result, + listOfElements, + links: buildLinks(newQuantitativeComparisons), + rows: tableRows, + setTableRows }) + + }, 100); } } diff --git a/lib/findPaths.js b/lib/findPaths.js index caea418..f5878ee 100644 --- a/lib/findPaths.js +++ b/lib/findPaths.js @@ -189,9 +189,8 @@ export async function buildRows({ isListOrdered, orderedList, listOfElements, li } // return rows } - -export function CreateTableWithDistances({ isListOrdered, orderedList, listOfElements, links, tableRows, setTableRows }) { - +export function CreateTableWithDistancesWithUseEffect({ isListOrdered, orderedList, listOfElements, links, tableRows, setTableRows }) { + useEffect(async () => { await buildRows({ isListOrdered, orderedList, listOfElements, links, rows: tableRows, setTableRows }) /* @@ -224,6 +223,7 @@ export function CreateTableWithDistances({ isListOrdered, orderedList, listOfEle } */ }); // this useEffect should ideally only work when isListOrdered changes, but I haven't bothered to program that. + return (
@@ -259,6 +259,43 @@ export function CreateTableWithDistances({ isListOrdered, orderedList, listOfEle
) +} + +export function CreateTableWithDistances({ tableRows }) { + return ( +
+ + + + + + + + + + + + + + + + {tableRows.map(row => + + + + + + + + + + + )} + +
Id   Position   Element    Possible relative values    Average relative value
{row.id}   {row.position}   {row.name}   {abridgeArrayAndDisplay(row.distances)}   {formatLargeOrSmall(avg(row.distances))}
+
+ ) + } function CreateTableWithoutDistances({ isListOrdered, orderedList, listOfElements, links }) {