From 5de6a18e1030f133e5109c47b8586a2893cc53a3 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Wed, 8 Dec 2021 16:46:17 +0100 Subject: [PATCH] fix: Kill submit button once end is reached --- lib/comparisonView.js | 67 +++++++++++++++++++++++++------------------ lib/slider.js | 29 ++++++++++--------- 2 files changed, 55 insertions(+), 41 deletions(-) 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 (
- + {/* Webpage name & favicon */}
@@ -243,18 +252,19 @@ export default function ComparisonView({ listOfElementsForView }) {
- + {/* Heading */}

Utility Function Extractor

{/* Approximate progress indicator */} +

{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}

{/* Comparison section */}
- + {/* Element 1 */}
@@ -292,10 +302,11 @@ export default function ComparisonView({ listOfElementsForView }) { reasoning={reasoning} toComparePair={toComparePair} nextStepSlider={nextStepSlider} + dontPushSubmitButtonAnyMore={dontPushSubmitButtonAnyMore} />
- + {/* Element 2 */}
@@ -353,7 +364,7 @@ export default function ComparisonView({ listOfElementsForView }) {
- + {/* Convenience functions */}
-
+
{/* Button: Restart */}
)