@@ -18,8 +31,8 @@ export function ComparisonActuator({ dataProps, onSubmit }) {
{`times as valuable as ...`}
diff --git a/packages/webpage-refactor/components/homepage.js b/packages/webpage-refactor/components/homepage.js
index 2c5c75f..82a7b47 100644
--- a/packages/webpage-refactor/components/homepage.js
+++ b/packages/webpage-refactor/components/homepage.js
@@ -1,20 +1,33 @@
import React, { useState } from "react";
+import { mergeSort } from "utility-tools";
+
import { Title } from "./title.js";
import { ProgressIndicator } from "./progressIndicator.js";
import { DisplayElementForComparison } from "./displayElementForComparison.js";
-
import { ComparisonActuator } from "./comparisonActuator.js";
+import { resolveToNumIfPossible } from "../lib/squiggle.js";
export function Homepage({ listOfElementsInit }) {
/* Statefull elements */
- const [listOfElements, setListOfElements] = useState(listOfElementsInit);
+ // list of elements
+ const [listOfElements, setListOfElements] = useState(
+ listOfElementsInit.slice(0, 3)
+ );
+
+ // number of steps
const numStepsInit = 0;
const [numStepsNow, setNumStepsNow] = useState(numStepsInit);
const increaseNumSteps = (n) => setNumStepsNow(n + 1);
+ // is list ordered?
const isListOrdered = false;
+ // list of comparisons
+ const [links, setLinks] = useState([]);
+ const addLink = (link, links) => setLinks([...links, link]);
+
+ // paired being currently compared
const pairCurrentlyBeingComparedInit = [
listOfElementsInit[0],
listOfElementsInit[1],
@@ -30,6 +43,39 @@ export function Homepage({ listOfElementsInit }) {
let n2 = (n1 + 1 + Math.floor(Math.random() * l)) % l;
changePairCurrentlyBeingCompared(listOfElements[n1], listOfElements[n2]);
};
+
+ // process next step
+ const moveToNextStep = async ({
+ listOfElements,
+ pairCurrentlyBeingCompared,
+ comparisonString,
+ }) => {
+ let newLink = {
+ source: pairCurrentlyBeingCompared[0].name,
+ target: pairCurrentlyBeingCompared[1].name,
+ squiggleString: comparisonString,
+ };
+
+ let numOption = await resolveToNumIfPossible(comparisonString);
+ if (numOption.asNum == false) {
+ alert(JSON.stringify(numOption.errorMsg));
+ } else if (numOption.asNum == true) {
+ // addLink({ ...newLink, distance: numOption.num }, links);
+ let newLinks = [...links, { ...newLink, distance: numOption.num }];
+ setLinks(newLinks);
+ console.log("links: ", newLinks);
+ let mergeSortOutput = mergeSort({ list: listOfElements, links: links });
+ if (mergeSortOutput.finishedOrderingList == false) {
+ let newPairToCompare = mergeSortOutput.uncomparedElements;
+ setPairCurrentlyBeingCompared(newPairToCompare);
+ } else {
+ alert(JSON.stringify(mergeSortOutput, null, 4));
+ // chooseNextPairToCompareRandomly({ listOfElements });
+ // return 1;
+ }
+ }
+ };
+
return (
@@ -45,8 +91,9 @@ export function Homepage({ listOfElementsInit }) {
>
= 2.1.2 < 3":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
@@ -2252,6 +2688,11 @@ scheduler@^0.20.2:
loose-envify "^1.1.0"
object-assign "^4.1.1"
+seedrandom@^3.0.5:
+ version "3.0.5"
+ resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7"
+ integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==
+
selfsigned@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.0.1.tgz#8b2df7fa56bf014d19b6007655fff209c0ef0a56"
@@ -2345,6 +2786,13 @@ string_decoder@^1.1.1:
dependencies:
safe-buffer "~5.2.0"
+string_decoder@~1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
+ integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
+ dependencies:
+ safe-buffer "~5.1.0"
+
strip-final-newline@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
@@ -2445,6 +2893,11 @@ tar-stream@^2.1.4:
inherits "^2.0.3"
readable-stream "^3.1.1"
+tiny-emitter@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"
+ integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==
+
tiny-glob@^0.2.9:
version "0.2.9"
resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.9.tgz#2212d441ac17928033b110f8b3640683129d31e2"
@@ -2484,6 +2937,11 @@ tunnel-agent@^0.6.0:
dependencies:
safe-buffer "^5.0.1"
+typed-function@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/typed-function/-/typed-function-2.1.0.tgz#ded6f8a442ba8749ff3fe75bc41419c8d46ccc3f"
+ integrity sha512-bctQIOqx2iVbWGDGPWwIm18QScpu2XRmkC19D8rQGFsjKSgteq/o1hTZvIG/wuDq8fanpBDrLkLq+aEN/6y5XQ==
+
ufo@^0.7.10, ufo@^0.7.11, ufo@^0.7.9:
version "0.7.11"
resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.7.11.tgz#17defad497981290383c5d26357773431fdbadcb"
@@ -2576,7 +3034,7 @@ unstorage@^0.2.8:
ufo "^0.7.9"
ws "^8.2.1"
-util-deprecate@^1.0.1, util-deprecate@^1.0.2:
+util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==
@@ -2588,6 +3046,13 @@ util@^0.10.3:
dependencies:
inherits "2.0.3"
+utility-tools@^0.2.2:
+ version "0.2.2"
+ resolved "https://registry.yarnpkg.com/utility-tools/-/utility-tools-0.2.2.tgz#fdea9678d4d3b6e8b76184b35e6ac97e20c6079d"
+ integrity sha512-Bbp5jZaxPSeALD75A2AGh0rvmuYSXBqZ3h6W5+VJIoRympXYwAJ3k8UmBNCBuM0uLu6XdSeYIfR4sRlgg+jrIA==
+ dependencies:
+ "@quri/squiggle-lang" "^0.2.11"
+
vfile-message@^2.0.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-2.0.4.tgz#5b43b88171d409eae58477d13f23dd41d52c371a"