fix: Kill submit button once end is reached
This commit is contained in:
parent
9a22936ed7
commit
5de6a18e10
|
@ -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,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) {
|
||||
sliderValue = 1 / sliderValue;
|
||||
[element1, element2] = [element2, element1]
|
||||
|
@ -207,14 +211,13 @@ export default function ComparisonView({ listOfElementsForView }) {
|
|||
setReasoning('')
|
||||
changeNumSteps(numSteps + 1)
|
||||
if (successStatus) {
|
||||
setDontPushSubmitButtonAnyMore(true)
|
||||
|
||||
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
|
||||
setIsListOrdered(true)
|
||||
setOrderedList(result)
|
||||
|
||||
|
@ -226,11 +229,17 @@ export default function ComparisonView({ listOfElementsForView }) {
|
|||
rows: tableRows,
|
||||
setTableRows
|
||||
})
|
||||
/*
|
||||
setTimeout(async () => {
|
||||
// Make sure to do this after the
|
||||
|
||||
}, 100);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Html
|
||||
return (
|
||||
<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
|
||||
</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
|
||||
|
|
|
@ -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
|
||||
let onClick = (event) => {
|
||||
if(!dontPushSubmitButtonAnyMore){
|
||||
//event.preventDefault();
|
||||
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
|
||||
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>)
|
||||
|
|
Loading…
Reference in New Issue
Block a user