fix: Kill submit button once end is reached

This commit is contained in:
NunoSempere 2021-12-08 16:46:17 +01:00
parent 9a22936ed7
commit 5de6a18e10
2 changed files with 55 additions and 41 deletions

View File

@ -56,6 +56,7 @@ export default function ComparisonView({ listOfElementsForView }) {
let initialMaxSteps = maxMergeSortSteps(listOfElementsForView.length) let initialMaxSteps = maxMergeSortSteps(listOfElementsForView.length)
let initialExpectedSteps = expectedNumMergeSortSteps(listOfElementsForView.length) let initialExpectedSteps = expectedNumMergeSortSteps(listOfElementsForView.length)
let initialTableRows = [] let initialTableRows = []
let initialDontPushSubmitButtonAnyMore = false
// state variables and functions // state variables and functions
const [listOfElements, setListOfElements] = useState(initialListOfElements) const [listOfElements, setListOfElements] = useState(initialListOfElements)
@ -68,6 +69,7 @@ export default function ComparisonView({ listOfElementsForView }) {
const [isListOrdered, setIsListOrdered] = useState(initialIsListOdered) const [isListOrdered, setIsListOrdered] = useState(initialIsListOdered)
const [orderedList, setOrderedList] = useState(initialOrderedList) const [orderedList, setOrderedList] = useState(initialOrderedList)
const [dontPushSubmitButtonAnyMore, setDontPushSubmitButtonAnyMore] = useState(initialDontPushSubmitButtonAnyMore)
let [showAdvancedOptions, changeShowAdvanceOptions] = useState(initialShowAdvancedOptions); let [showAdvancedOptions, changeShowAdvanceOptions] = useState(initialShowAdvancedOptions);
let [showComparisons, changeShowComparisons] = useState(initialShowComparisons); let [showComparisons, changeShowComparisons] = useState(initialShowComparisons);
@ -88,6 +90,7 @@ export default function ComparisonView({ listOfElementsForView }) {
changeNumSteps(initialNumSteps) changeNumSteps(initialNumSteps)
removeOldSvg() removeOldSvg()
setTableRows(initialTableRows) setTableRows(initialTableRows)
setDontPushSubmitButtonAnyMore(initialDontPushSubmitButtonAnyMore)
} }
let changeDataSet = (listOfElementsNew) => { let changeDataSet = (listOfElementsNew) => {
@ -190,7 +193,8 @@ export default function ComparisonView({ listOfElementsForView }) {
} }
} }
let nextStepSlider = async ({ posList, binaryComparisons, sliderValue, Reasoning, element1, element2 }) => { let nextStepSlider = async ({ posList, binaryComparisons, sliderValue, reasoning, element1, element2 }) => {
if (!dontPushSubmitButtonAnyMore) {
if (sliderValue < 1 && sliderValue > 0) { if (sliderValue < 1 && sliderValue > 0) {
sliderValue = 1 / sliderValue; sliderValue = 1 / sliderValue;
[element1, element2] = [element2, element1] [element1, element2] = [element2, element1]
@ -207,14 +211,13 @@ export default function ComparisonView({ listOfElementsForView }) {
setReasoning('') setReasoning('')
changeNumSteps(numSteps + 1) changeNumSteps(numSteps + 1)
if (successStatus) { if (successStatus) {
setDontPushSubmitButtonAnyMore(true)
let jsObject = nicelyFormatLinks(quantitativeComparisons, listOfElements) let jsObject = nicelyFormatLinks(quantitativeComparisons, listOfElements)
await pushToMongo(jsObject) await pushToMongo(jsObject)
console.log(jsObject) console.log(jsObject)
alert("Comparisons completed. Background work might take a while, or straight-out fail") alert("Comparisons completed. Background work might take a while, or straight-out fail")
setTimeout(async () => {
// Make sure to do this after the
setIsListOrdered(true) setIsListOrdered(true)
setOrderedList(result) setOrderedList(result)
@ -226,11 +229,17 @@ export default function ComparisonView({ listOfElementsForView }) {
rows: tableRows, rows: tableRows,
setTableRows setTableRows
}) })
/*
setTimeout(async () => {
// Make sure to do this after the
}, 100); }, 100);
*/
} }
} }
}
// Html // Html
return ( return (
<div className="flex flex-col items-center justify-center min-h-screen py-2"> <div className="flex flex-col items-center justify-center min-h-screen py-2">
@ -249,6 +258,7 @@ export default function ComparisonView({ listOfElementsForView }) {
Utility Function Extractor Utility Function Extractor
</h1> </h1>
{/* Approximate progress indicator */} {/* Approximate progress indicator */}
<p>{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}</p> <p>{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}</p>
{/* Comparison section */} {/* Comparison section */}
@ -292,6 +302,7 @@ export default function ComparisonView({ listOfElementsForView }) {
reasoning={reasoning} reasoning={reasoning}
toComparePair={toComparePair} toComparePair={toComparePair}
nextStepSlider={nextStepSlider} nextStepSlider={nextStepSlider}
dontPushSubmitButtonAnyMore={dontPushSubmitButtonAnyMore}
/> />
</div> </div>
</div> </div>
@ -364,7 +375,7 @@ export default function ComparisonView({ listOfElementsForView }) {
</button> </button>
</div> </div>
<div className={showAdvancedOptions? "flex flex-wrap -mx-4 overflow-hidden" : "hidden"}> <div className={showAdvancedOptions ? "flex flex-wrap -mx-4 overflow-hidden" : "hidden"}>
{/* Button: Restart */} {/* Button: Restart */}
<div className="my-4 px-4 w-1/3 overflow-hidden"> <div className="my-4 px-4 w-1/3 overflow-hidden">
<button <button

View File

@ -125,9 +125,10 @@ export function SliderElement({ onChange, value, displayFunction, domain }) {
) )
} }
export function SubmitSliderButton({ posList, binaryComparisons, sliderValue, reasoning, toComparePair, nextStepSlider }) { export function SubmitSliderButton({ posList, binaryComparisons, sliderValue, reasoning, toComparePair, nextStepSlider, dontPushSubmitButtonAnyMore }) {
// This element didn't necessarily have to exist, but it made it easier for debugging purposes // This element didn't necessarily have to exist, but it made it easier for debugging purposes
let onClick = (event) => { let onClick = (event) => {
if(!dontPushSubmitButtonAnyMore){
//event.preventDefault(); //event.preventDefault();
let obj = { posList, binaryComparisons, sliderValue, reasoning, element1: toComparePair[1], element2: toComparePair[0] } let obj = { posList, binaryComparisons, sliderValue, reasoning, element1: toComparePair[1], element2: toComparePair[0] }
// //
@ -142,8 +143,10 @@ export function SubmitSliderButton({ posList, binaryComparisons, sliderValue, re
} }
} }
}
return (<button return (<button
className="bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded mt-5" className={!dontPushSubmitButtonAnyMore ? "bg-transparent hover:bg-blue-500 text-blue-700 font-semibold hover:text-white py-2 px-4 border border-blue-500 hover:border-transparent rounded mt-5" : "bg-transparent text-blue-700 font-semibold py-2 px-4 border border-blue-500 rounded mt-5"}
onClick={onClick}> onClick={onClick}>
Submit Submit
</button>) </button>)