From dc0af5902dc8cb9fa5478e2158d9d0712fd3e13c Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Thu, 25 Nov 2021 11:58:50 +0000 Subject: [PATCH] feat: Added reasoning field --- lib/slider.js | 4 ++-- pages/index.js | 18 ++++++++++++++---- pages/research.js | 20 +++++++++++++++----- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/slider.js b/lib/slider.js index 16c097a..30bf400 100644 --- a/lib/slider.js +++ b/lib/slider.js @@ -125,11 +125,11 @@ export function SliderElement({ onChange, value, displayFunction, domain }) { ) } -export function SubmitSliderButton({ posList, binaryComparisons, sliderValue, toComparePair, nextStepSlider }) { +export function SubmitSliderButton({ posList, binaryComparisons, sliderValue, reasoning, toComparePair, nextStepSlider }) { // 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, element1: toComparePair[1], element2: toComparePair[0] } + let obj = { posList, binaryComparisons, sliderValue, reasoning, element1: toComparePair[1], element2: toComparePair[0] } // console.log("input@SubmitSliderButton") console.log(obj) diff --git a/pages/index.js b/pages/index.js index ee093e0..6cadbba 100644 --- a/pages/index.js +++ b/pages/index.js @@ -18,7 +18,7 @@ import { toLocale, transformSliderValueToPracticalValue, transformSliderValueToA /* Helpers */ let increasingList = (n) => Array.from(Array(n).keys()) -let buildLinks = quantitativeComparisons => quantitativeComparisons.map(([element1, element2, distance]) => ({ source: element1, target: element2, distance: distance })) +let buildLinks = quantitativeComparisons => quantitativeComparisons.map(([element1, element2, distance, reasoning]) => ({ source: element1, target: element2, distance: distance, reasoning: reasoning })) Array.prototype.containsArray = function (val) { var hash = {}; @@ -59,7 +59,7 @@ let displayFunctionSlider = (value) => { }; -let nicelyFormatLinks = (quantitativeComparisons, listOfElements) => quantitativeComparisons.map(([element1, element2, distance]) => ({ source: listOfElements[element1].name, target: listOfElements[element2].name, distance: distance })) +let nicelyFormatLinks = (quantitativeComparisons, listOfElements) => quantitativeComparisons.map(([element1, element2, distance, reasoning]) => ({ source: listOfElements[element1].name, target: listOfElements[element2].name, distance: distance, reasoning: reasoning })) /* React components */ // fs can only be used here. @@ -88,6 +88,7 @@ export default function Home({ listOfElementsDefault }) { //let initialComparePair = [list[list.length-2], list[list.length-1]] let initialComparePair = [initialPosList[initialPosList.length - 2], initialPosList[initialPosList.length - 1]] let initialSliderValue = 1 + let initialReasoning = '' let initialBinaryComparisons = [] let initialQuantitativeComparisons = [] let initialIsListOdered = false @@ -103,6 +104,7 @@ export default function Home({ listOfElementsDefault }) { const [toComparePair, setToComparePair] = useState(initialComparePair) const [sliderValue, setSliderValue] = useState(initialSliderValue) + const [reasoning, setReasoning] = useState(initialReasoning) const [binaryComparisons, setBinaryComparisons] = useState(initialBinaryComparisons) const [quantitativeComparisons, setQuantitativeComparisons] = useState(initialQuantitativeComparisons) // More expressive, but more laborious to search through. For the ordering step, I only manipulate the binaryComparisons. @@ -220,7 +222,7 @@ export default function Home({ listOfElementsDefault }) { } } - let nextStepSlider = ({ posList, binaryComparisons, sliderValue, element1, element2 }) => { + let nextStepSlider = ({ posList, binaryComparisons, sliderValue, Reasoning, element1, element2 }) => { if (sliderValue < 1 && sliderValue > 0) { sliderValue = 1/sliderValue; [element1, element2] = [element2, element1] @@ -229,11 +231,12 @@ export default function Home({ listOfElementsDefault }) { console.log(posList) let successStatus = nextStepSimple(posList, binaryComparisons, element1, element2) - let newQuantitativeComparison = [element1, element2, transformSliderValueToActualValue(sliderValue)] + let newQuantitativeComparison = [element1, element2, transformSliderValueToActualValue(sliderValue), reasoning] let newQuantitativeComparisons = [...quantitativeComparisons, newQuantitativeComparison] setQuantitativeComparisons(newQuantitativeComparisons) setSliderValue(1) + setReasoning('') if (successStatus) { let jsObject = nicelyFormatLinks(quantitativeComparisons, listOfElements) pushToMongo(jsObject) @@ -290,12 +293,19 @@ export default function Home({ listOfElementsDefault }) { {`times as valuable as ...`}
+
+