Utility Function Extractor
{/* Approximate progress indicator */} +{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}
{/* Comparison section */}diff --git a/lib/comparisonView.js b/lib/comparisonView.js index 0bd4bb1..60eeda2 100644 --- a/lib/comparisonView.js +++ b/lib/comparisonView.js @@ -56,6 +56,7 @@ export default function ComparisonView({ listOfElementsForView }) { let initialMaxSteps = maxMergeSortSteps(listOfElementsForView.length) let initialExpectedSteps = expectedNumMergeSortSteps(listOfElementsForView.length) let initialTableRows = [] + let initialDontPushSubmitButtonAnyMore = false // state variables and functions const [listOfElements, setListOfElements] = useState(initialListOfElements) @@ -68,6 +69,7 @@ export default function ComparisonView({ listOfElementsForView }) { const [isListOrdered, setIsListOrdered] = useState(initialIsListOdered) const [orderedList, setOrderedList] = useState(initialOrderedList) + const [dontPushSubmitButtonAnyMore, setDontPushSubmitButtonAnyMore] = useState(initialDontPushSubmitButtonAnyMore) let [showAdvancedOptions, changeShowAdvanceOptions] = useState(initialShowAdvancedOptions); let [showComparisons, changeShowComparisons] = useState(initialShowComparisons); @@ -88,6 +90,7 @@ export default function ComparisonView({ listOfElementsForView }) { changeNumSteps(initialNumSteps) removeOldSvg() setTableRows(initialTableRows) + setDontPushSubmitButtonAnyMore(initialDontPushSubmitButtonAnyMore) } let changeDataSet = (listOfElementsNew) => { @@ -190,31 +193,31 @@ export default function ComparisonView({ listOfElementsForView }) { } } - 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, result] = nextStepSimple(posList, binaryComparisons, element1, element2) + let nextStepSlider = async ({ posList, binaryComparisons, sliderValue, reasoning, element1, element2 }) => { + if (!dontPushSubmitButtonAnyMore) { + if (sliderValue < 1 && sliderValue > 0) { + sliderValue = 1 / sliderValue; + [element1, element2] = [element2, element1] + } + console.log(`posList@nextStepSlider:`) + console.log(posList) + let [successStatus, result] = nextStepSimple(posList, binaryComparisons, element1, element2) - let newQuantitativeComparison = [element1, element2, sliderValue, reasoning] - let newQuantitativeComparisons = [...quantitativeComparisons, newQuantitativeComparison] - setQuantitativeComparisons(newQuantitativeComparisons) + let newQuantitativeComparison = [element1, element2, sliderValue, reasoning] + let newQuantitativeComparisons = [...quantitativeComparisons, newQuantitativeComparison] + setQuantitativeComparisons(newQuantitativeComparisons) - setSliderValue(DEFAULT_COMPARE()) - setReasoning('') - changeNumSteps(numSteps + 1) - if (successStatus) { + setSliderValue(DEFAULT_COMPARE()) + setReasoning('') + changeNumSteps(numSteps + 1) + if (successStatus) { + setDontPushSubmitButtonAnyMore(true) - let jsObject = nicelyFormatLinks(quantitativeComparisons, listOfElements) - await pushToMongo(jsObject) - console.log(jsObject) + 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 + alert("Comparisons completed. Background work might take a while, or straight-out fail") setIsListOrdered(true) setOrderedList(result) @@ -226,15 +229,21 @@ export default function ComparisonView({ listOfElementsForView }) { rows: tableRows, setTableRows }) + /* + setTimeout(async () => { + // Make sure to do this after the - }, 100); + }, 100); + */ + } } + } // Html return (
{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}
{/* Comparison section */}