- {getInfoToDisplayForecastsFunction(displayForecastsWrapper, {
+
+ {getInfoToDisplayForecastsFunction({
results,
- hasDisplayBeenCaptured,
- setHasDisplayBeenCaptured,
whichResultToDisplayAndCapture,
showIdToggle,
})}
-
-
- {"Can't find what you were looking for?"}
-
+ {
- setQueryParameters({
- ...queryParameters,
- numDisplay: queryParameters.numDisplay * 2,
- });
- }}
- key={"common-4-1-1"}
>
- {" Show more, or"}
-
{" "}
-
- suggest a question on Metaculus
-
-
-
+ {"Can't find what you were looking for?"}
+
{
+ setQueryParameters({
+ ...queryParameters,
+ numDisplay: queryParameters.numDisplay * 2,
+ });
+ }}
+ >
+ {" Show more, or"}
+ {" "}
+
+ suggest a question on Metaculus
+
+
+
);
-}
+};
+
+export default CommonDisplay;
diff --git a/src/web/display/displayForecastsWrappers.tsx b/src/web/display/displayForecastsWrappers.tsx
index e0d4b0b..ca048bb 100644
--- a/src/web/display/displayForecastsWrappers.tsx
+++ b/src/web/display/displayForecastsWrappers.tsx
@@ -15,22 +15,12 @@ export function displayForecastsWrapperForSearch({
export function displayForecastsWrapperForCapture({
results,
- hasDisplayBeenCaptured,
- setHasDisplayBeenCaptured,
whichResultToDisplayAndCapture,
}) {
- console.log({
- results,
- hasDisplayBeenCaptured,
- setHasDisplayBeenCaptured,
- whichResultToDisplayAndCapture,
- });
return (
-
+
{displayOneForecast({
result: results[whichResultToDisplayAndCapture],
- hasDisplayBeenCaptured,
- setHasDisplayBeenCaptured,
})}
);
diff --git a/src/web/display/displayOneForecastForCapture.js b/src/web/display/displayOneForecastForCapture.tsx
similarity index 87%
rename from src/web/display/displayOneForecastForCapture.js
rename to src/web/display/displayOneForecastForCapture.tsx
index 1c701f7..1ce715d 100644
--- a/src/web/display/displayOneForecastForCapture.js
+++ b/src/web/display/displayOneForecastForCapture.tsx
@@ -1,10 +1,11 @@
-import domtoimage from "dom-to-image"; // https://github.com/tsayen/dom-to-image
-import { useRef, useState } from "react";
-import { CopyToClipboard } from "react-copy-to-clipboard";
-import { uploadToImgur } from "../worker/uploadToImgur";
-import { displayForecast } from "./displayForecasts.js";
+import domtoimage from 'dom-to-image'; // https://github.com/tsayen/dom-to-image
+import { useEffect, useRef, useState } from 'react';
+import { CopyToClipboard } from 'react-copy-to-clipboard';
-function displayOneForecastInner(result, containerRef, onLoadCallback) {
+import { uploadToImgur } from '../worker/uploadToImgur';
+import { displayForecast } from './displayForecasts.js';
+
+function displayOneForecastInner(result, containerRef) {
return (
{result
@@ -21,7 +22,6 @@ function displayOneForecastInner(result, containerRef, onLoadCallback) {
let domToImageWrapper = (reactRef) => {
let node = reactRef.current;
- console.log(node);
const scale = 3; // Increase for better quality
const style = {
transform: "scale(" + scale + ")",
@@ -36,7 +36,6 @@ let domToImageWrapper = (reactRef) => {
style,
};
let image = domtoimage.toPng(node, param);
- console.log(image);
return image;
};
@@ -103,18 +102,17 @@ let generateIframeURL = (result) => {
let iframeURL = "";
if (result) {
// if check not strictly necessary today
- iframeURL = result.item.url
+ let parts = result.item.url
.replace("questions", "questions/embed")
.split("/");
- iframeURL.pop();
- iframeURL.pop();
- iframeURL = iframeURL.join("/");
+ parts.pop();
+ parts.pop();
+ iframeURL = parts.join("/");
}
return iframeURL;
};
let metaculusEmbed = (result) => {
- //console.log(item.url)
let platform = "";
let iframeURL = "";
if (result) {
@@ -171,20 +169,24 @@ let generateMetaculusSource = (result, hasDisplayBeenCaptured) => {
}
};
-export default function displayOneForecast({
- result,
- hasDisplayBeenCaptured,
- setHasDisplayBeenCaptured,
-}) {
+interface Props {
+ result: any;
+}
+
+const DisplayOneForecast: React.FC
= ({ result }) => {
+ const [hasDisplayBeenCaptured, setHasDisplayBeenCaptured] = useState(false);
+
+ useEffect(() => {
+ setHasDisplayBeenCaptured(false);
+ }, [result]);
+
const containerRef = useRef(null);
const [imgSrc, setImgSrc] = useState("");
const [mainButtonStatus, setMainButtonStatus] = useState(
"Capture image and generate code"
);
- const [clickedAlreadyBool, setClickAlreadyBool] = useState(false);
let exportAsPictureAndCode = () => {
- console.log(containerRef.current);
let handleGettingImgurlImage = (imgurUrl) => {
setImgSrc(imgurUrl);
setMainButtonStatus("Done!");
@@ -215,7 +217,7 @@ export default function displayOneForecast({
return (
@@ -232,10 +234,7 @@ export default function displayOneForecast({
{generateCaptureButton(result, onCaptureButtonClick)}
-
+
{generateSource(result, imgSrc, hasDisplayBeenCaptured)}
@@ -249,7 +248,9 @@ export default function displayOneForecast({
);
-}
+};
+
+export default DisplayOneForecast;
// https://stackoverflow.com/questions/39501289/in-reactjs-how-to-copy-text-to-clipboard
// Note: https://stackoverflow.com/questions/66016033/can-no-longer-upload-images-to-imgur-from-localhost
diff --git a/src/web/display/multiSelectPlatforms.js b/src/web/display/multiSelectPlatforms.js
index d0795ea..20d1f16 100644
--- a/src/web/display/multiSelectPlatforms.js
+++ b/src/web/display/multiSelectPlatforms.js
@@ -1,7 +1,7 @@
import chroma from "chroma-js";
import React from "react";
import Select from "react-select";
-import { platformsWithLabels } from "../platforms.js";
+import { platformsWithLabels } from "../platforms";
const colourStyles = {
control: (styles) => ({ ...styles, backgroundColor: "white" }),
diff --git a/src/web/platforms.js b/src/web/platforms.ts
similarity index 76%
rename from src/web/platforms.js
rename to src/web/platforms.ts
index 2a869d6..6a5c68a 100644
--- a/src/web/platforms.js
+++ b/src/web/platforms.ts
@@ -42,11 +42,19 @@ export const platformNames = [
"X-risk estimates",
];
-export const platformsWithLabels = platformNames.map((name, i) => ({
- value: name,
- label: name,
- color: distinctColors[i],
-}));
+export interface PlatformWithLabel {
+ value: string;
+ label: string;
+ color: string;
+}
+
+export const platformsWithLabels: PlatformWithLabel[] = platformNames.map(
+ (name, i) => ({
+ value: name,
+ label: name,
+ color: distinctColors[i],
+ })
+);
export const platforms = platformsWithLabels;