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.
This commit is contained in:
parent
958a2e366f
commit
3d6a544a72
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 (
|
||||
<div>
|
||||
|
@ -259,6 +259,43 @@ export function CreateTableWithDistances({ isListOrdered, orderedList, listOfEle
|
|||
</div>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
export function CreateTableWithDistances({ tableRows }) {
|
||||
return (
|
||||
<div>
|
||||
<table className="">
|
||||
<thead>
|
||||
<tr >
|
||||
<th >Id</th>
|
||||
<th> </th>
|
||||
<th >Position</th>
|
||||
<th> </th>
|
||||
<th >Element</th>
|
||||
<th> </th>
|
||||
<th >Possible relative values</th>
|
||||
<th> </th>
|
||||
<th >Average relative value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{tableRows.map(row => <tr key={row.id}>
|
||||
<td className="" >{row.id}</td>
|
||||
<td> </td>
|
||||
<td className="" >{row.position}</td>
|
||||
<td> </td>
|
||||
<td className="">{row.name}</td>
|
||||
<td> </td>
|
||||
<td className="">{abridgeArrayAndDisplay(row.distances)}</td>
|
||||
<td> </td>
|
||||
<td className="">{formatLargeOrSmall(avg(row.distances))}</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
function CreateTableWithoutDistances({ isListOrdered, orderedList, listOfElements, links }) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user