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 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,9 +229,15 @@ export default function ComparisonView({ listOfElementsForView }) {
rows: tableRows,
setTableRows
})
/*
setTimeout(async () => {
// Make sure to do this after the
}, 100);
}, 100);
*/
}
}
}
// Html
@ -249,6 +258,7 @@ export default function ComparisonView({ listOfElementsForView }) {
Utility Function Extractor
</h1>
{/* Approximate progress indicator */}
<p>{`${numSteps} out of ~${expectedSteps} (max ${maxSteps}) comparisons`}</p>
{/* Comparison section */}
@ -292,6 +302,7 @@ export default function ComparisonView({ listOfElementsForView }) {
reasoning={reasoning}
toComparePair={toComparePair}
nextStepSlider={nextStepSlider}
dontPushSubmitButtonAnyMore={dontPushSubmitButtonAnyMore}
/>
</div>
</div>
@ -364,7 +375,7 @@ export default function ComparisonView({ listOfElementsForView }) {
</button>
</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 */}
<div className="my-4 px-4 w-1/3 overflow-hidden">
<button

View File

@ -125,25 +125,28 @@ 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
let onClick = (event) => {
//event.preventDefault();
let obj = { posList, binaryComparisons, sliderValue, reasoning, element1: toComparePair[1], element2: toComparePair[0] }
//
console.log("input@SubmitSliderButton")
console.log(obj)
if (!!Number(sliderValue) && sliderValue >= 0) {
nextStepSlider(obj)
} else if (!!Number(sliderValue) && sliderValue < 0) {
alert("Negative numbers not yet allowed")
} else {
alert("Your input is not a number")
if(!dontPushSubmitButtonAnyMore){
//event.preventDefault();
let obj = { posList, binaryComparisons, sliderValue, reasoning, element1: toComparePair[1], element2: toComparePair[0] }
//
console.log("input@SubmitSliderButton")
console.log(obj)
if (!!Number(sliderValue) && sliderValue >= 0) {
nextStepSlider(obj)
} else if (!!Number(sliderValue) && sliderValue < 0) {
alert("Negative numbers not yet allowed")
} else {
alert("Your input is not a number")
}
}
}
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}>
Submit
</button>)