2022-01-30 15:29:45 +00:00
|
|
|
import React, { useState } from "react";
|
2022-01-28 17:50:45 +00:00
|
|
|
|
2022-01-30 15:29:45 +00:00
|
|
|
export function ComparisonsChanger({ handleSubmit }) {
|
2022-01-28 18:48:47 +00:00
|
|
|
// let defaultText=JSON.stringify(nicelyFormatLinks(quantitativeComparisons, listOfElements), null, 4)
|
|
|
|
|
2022-01-30 15:29:45 +00:00
|
|
|
let [value, setValue] = useState(``);
|
|
|
|
const [displayingDoneMessage, setDisplayingDoneMessage] = useState(false);
|
|
|
|
const [displayingDoneMessageTimer, setDisplayingDoneMessageTimer] =
|
|
|
|
useState(null);
|
2022-01-28 17:50:45 +00:00
|
|
|
|
|
|
|
let handleChange = (event) => {
|
2022-01-30 15:29:45 +00:00
|
|
|
setValue(event.target.value);
|
|
|
|
};
|
2022-01-28 17:50:45 +00:00
|
|
|
|
|
|
|
let handleSubmitInner = (event) => {
|
2022-01-30 15:29:45 +00:00
|
|
|
clearTimeout(displayingDoneMessageTimer);
|
2022-01-28 17:50:45 +00:00
|
|
|
event.preventDefault();
|
|
|
|
//console.log(event)
|
2022-01-30 15:29:45 +00:00
|
|
|
console.log("value@handleSubmitInner@ComparisonsChanger");
|
2022-01-28 17:50:45 +00:00
|
|
|
//console.log(typeof(value));
|
|
|
|
console.log(value);
|
2022-01-30 15:29:45 +00:00
|
|
|
try {
|
|
|
|
let newData = JSON.parse(value);
|
2022-01-28 17:50:45 +00:00
|
|
|
//console.log(typeof(newData))
|
|
|
|
//console.log(newData)
|
2022-01-30 15:29:45 +00:00
|
|
|
handleSubmit(newData);
|
2022-01-28 18:48:47 +00:00
|
|
|
/*
|
2022-01-28 17:50:45 +00:00
|
|
|
if(!newData.length || newData.length < 2){
|
|
|
|
throw Error("Not enough objects")
|
|
|
|
}
|
2022-01-28 18:48:47 +00:00
|
|
|
*/
|
2022-01-30 15:29:45 +00:00
|
|
|
setDisplayingDoneMessage(true);
|
2022-01-28 17:50:45 +00:00
|
|
|
let timer = setTimeout(() => setDisplayingDoneMessage(false), 3000);
|
2022-01-30 15:29:45 +00:00
|
|
|
setDisplayingDoneMessageTimer(timer);
|
|
|
|
} catch (error) {
|
|
|
|
setDisplayingDoneMessage(false);
|
2022-01-28 17:50:45 +00:00
|
|
|
//alert(error)
|
|
|
|
//console.log(error)
|
|
|
|
let substituteText = `Error: ${error.message}
|
|
|
|
|
|
|
|
Try something like:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"source": "x",
|
|
|
|
"target": "y",
|
|
|
|
"distance": 99999.99999999999,
|
|
|
|
"reasoning": "blah blah"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"source": "y",
|
|
|
|
"target": "z",
|
|
|
|
"distance": 1,
|
|
|
|
"reasoning": "blah blah"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"source": "x",
|
|
|
|
"target": "z",
|
|
|
|
"distance": 10,
|
|
|
|
"reasoning": "blah blah"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-01-30 15:29:45 +00:00
|
|
|
Your old input was: ${value}`;
|
|
|
|
setValue(substituteText);
|
2022-01-28 17:50:45 +00:00
|
|
|
}
|
2022-01-30 15:29:45 +00:00
|
|
|
};
|
2022-01-28 17:50:45 +00:00
|
|
|
return (
|
|
|
|
<form onSubmit={handleSubmitInner} className="inline">
|
2022-01-28 20:09:41 +00:00
|
|
|
<p>Load comparisons in the same style as in "Show comparisons".</p>
|
|
|
|
<p>These will override your current comparisons.</p>
|
2022-01-30 15:29:45 +00:00
|
|
|
<br />
|
|
|
|
<textarea
|
|
|
|
value={value}
|
|
|
|
onChange={handleChange}
|
|
|
|
rows="10"
|
|
|
|
cols="50"
|
2022-01-28 17:50:45 +00:00
|
|
|
className=""
|
|
|
|
/>
|
2022-01-30 15:29:45 +00:00
|
|
|
<br />
|
|
|
|
<button
|
2022-01-28 17:50:45 +00:00
|
|
|
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 p-10"
|
2022-01-30 15:29:45 +00:00
|
|
|
onClick={handleSubmitInner}
|
|
|
|
>
|
2022-01-28 18:48:47 +00:00
|
|
|
Change comparisons
|
2022-01-28 17:50:45 +00:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
2022-01-30 15:29:45 +00:00
|
|
|
className={
|
|
|
|
displayingDoneMessage
|
|
|
|
? "bg-transparent text-blue-700 font-semibold py-2 px-4 border border-blue-500 rounded mt-5 p-10"
|
|
|
|
: "hidden"
|
|
|
|
}
|
2022-01-28 17:50:45 +00:00
|
|
|
>
|
|
|
|
Done!
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
);
|
2022-01-30 15:29:45 +00:00
|
|
|
}
|
|
|
|
|