diff --git a/lib/comparisonView.js b/lib/comparisonView.js index 3a21a03..025d302 100644 --- a/lib/comparisonView.js +++ b/lib/comparisonView.js @@ -8,7 +8,7 @@ import { DrawGraph, removeOldSvg } from './labeledgraph'; import { SubmitSliderButton } from "./slider"; import { DisplayElement } from './displayElement' import { DisplayAsMarkdown } from './displayAsMarkdown' -import { CreateTableWithDistances } from './findPaths' +import { CreateTable } from './findPaths' import { TextAreaForJson } from "./textAreaForJson" import { pushToMongo } from "./pushToMongo.js" import { maxMergeSortSteps, expectedNumMergeSortSteps } from "./utils.js" @@ -183,24 +183,21 @@ export default function ComparisonView({ listOfElementsForView }) { console.log(posList) console.log("result@nextStepSimple") console.log(result) - alert("Comparisons completed. Background work might take a while.") - setIsListOrdered(true) - setOrderedList(result) - return true + return [true, result] } else { - return false + return [false, result] } } - let nextStepSlider = ({ posList, binaryComparisons, sliderValue, Reasoning, element1, element2 }) => { + let nextStepSlider = async ({ posList, binaryComparisons, sliderValue, Reasoning, element1, element2 }) => { if (sliderValue < 1 && sliderValue > 0) { sliderValue = 1 / sliderValue; [element1, element2] = [element2, element1] } console.log(`posList@nextStepSlider:`) console.log(posList) - let successStatus = nextStepSimple(posList, binaryComparisons, element1, element2) + let [successStatus, result] = nextStepSimple(posList, binaryComparisons, element1, element2) let newQuantitativeComparison = [element1, element2, sliderValue, reasoning] let newQuantitativeComparisons = [...quantitativeComparisons, newQuantitativeComparison] @@ -211,8 +208,14 @@ export default function ComparisonView({ listOfElementsForView }) { increaseNumSteps(numSteps + 1) if (successStatus) { let jsObject = nicelyFormatLinks(quantitativeComparisons, listOfElements) - pushToMongo(jsObject) + await pushToMongo(jsObject) console.log(jsObject) + alert("Comparisons completed. Background work might take a while, or straight-out fail") + setTimeout(() => { + // Make sure to do this after the + setIsListOrdered(true) + setOrderedList(result) + }, 5000); } } @@ -324,13 +327,13 @@ export default function ComparisonView({ listOfElementsForView }) { links={buildLinks(quantitativeComparisons)}>
- - +
@@ -138,6 +154,44 @@ export function CreateTableWithDistances({isListOrdered, orderedList, listOfElem } + +function CreateTableWithoutDistances({isListOrdered, orderedList, listOfElements, links}){ + if(!isListOrdered || orderedList.length < listOfElements.length){ + return (
{""}
) + } else { + let nodes = orderedList.map(i => listOfElements[i]) + let rows = nodes.map((element, i) => ({id: numToAlphabeticalString(element.id), name: element.name})) + console.log("rows@CreateTableWithoutDistances") + console.log(rows) + return( +
+ + + + + + + + + + + {rows.map(row => + + + + + )} + {} + +
Id   Element    
{row.id}   {row.name}
+
+ ) + } + +} + +export const CreateTable = CreateTableWithoutDistances; + /* Testing */ //import fs from 'fs'; //import path from 'path';