diff --git a/package-lock.json b/package-lock.json index bd2247f..c92c2ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,6 +61,7 @@ "postcss-preset-env": "^7.3.2", "prisma": "^3.11.1", "query-string": "^7.1.1", + "re-resizable": "^6.9.9", "react": "^17.0.2", "react-component-export-image": "^1.0.6", "react-compound-slider": "^3.3.1", @@ -37219,6 +37220,15 @@ "rc": "cli.js" } }, + "node_modules/re-resizable": { + "version": "6.9.9", + "resolved": "https://registry.npmjs.org/re-resizable/-/re-resizable-6.9.9.tgz", + "integrity": "sha512-l+MBlKZffv/SicxDySKEEh42hR6m5bAHfNu3Tvxks2c4Ah+ldnWjfnVRwxo/nxF27SsUsxDS0raAzFuJNKABXA==", + "peerDependencies": { + "react": "^16.13.1 || ^17.0.0 || ^18.0.0", + "react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/react": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz", @@ -67696,6 +67706,12 @@ "strip-json-comments": "~2.0.1" } }, + "re-resizable": { + "version": "6.9.9", + "resolved": "https://registry.npmjs.org/re-resizable/-/re-resizable-6.9.9.tgz", + "integrity": "sha512-l+MBlKZffv/SicxDySKEEh42hR6m5bAHfNu3Tvxks2c4Ah+ldnWjfnVRwxo/nxF27SsUsxDS0raAzFuJNKABXA==", + "requires": {} + }, "react": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz", diff --git a/package.json b/package.json index 80e9ced..adb6c02 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "postcss-preset-env": "^7.3.2", "prisma": "^3.11.1", "query-string": "^7.1.1", + "re-resizable": "^6.9.9", "react": "^17.0.2", "react-component-export-image": "^1.0.6", "react-compound-slider": "^3.3.1", diff --git a/src/web/common/BoxedLink.tsx b/src/web/common/BoxedLink.tsx new file mode 100644 index 0000000..57f2117 --- /dev/null +++ b/src/web/common/BoxedLink.tsx @@ -0,0 +1,23 @@ +import { FaExternalLinkAlt } from "react-icons/fa"; + +type Props = { + url: string; + size?: "normal" | "small"; +}; + +export const BoxedLink: React.FC = ({ + url, + size = "normal", + children, +}) => ( + + {children} + + +); diff --git a/src/web/questions/components/CaptureQuestion.tsx b/src/web/questions/components/CaptureQuestion.tsx index c33cfe6..883b500 100644 --- a/src/web/questions/components/CaptureQuestion.tsx +++ b/src/web/questions/components/CaptureQuestion.tsx @@ -1,6 +1,6 @@ import domtoimage from "dom-to-image"; // https://github.com/tsayen/dom-to-image +import { Resizable } from "re-resizable"; import { useEffect, useRef, useState } from "react"; - import { Button } from "../../common/Button"; import { CopyParagraph } from "../../common/CopyParagraph"; import { QuestionFragment } from "../../fragments.generated"; @@ -79,6 +79,15 @@ const MetaculusSource: React.FC<{ ); }; +const GrayContainer: React.FC<{ title: string }> = ({ title, children }) => ( +
+
+ {title}: +
+
{children}
+
+); + interface Props { question: QuestionFragment; } @@ -118,35 +127,55 @@ export const CaptureQuestion: React.FC = ({ question }) => { await exportAsPictureAndCode(); }; - return ( -
-
- -
-
- -
- {imgSrc ? ( - <> -
+ if (imgSrc) { + return ( +
+ + + + +
+ +
+ {question.platform.id === "metaculus" ? ( + <> +
+ +
+
+ +
+ + ) : null} +
+ ); + } + + return ( +
+ + +
+ ( +
{children}
+ )} + question={question} + showTimeStamp={true} + showExpandButton={false} + expandFooterToFullWidth={true} + />
-
- -
-
- -
-
- -
- - ) : null} +
+
+
); }; diff --git a/src/web/questions/components/PlatformLink.tsx b/src/web/questions/components/PlatformLink.tsx index 7435bab..0805114 100644 --- a/src/web/questions/components/PlatformLink.tsx +++ b/src/web/questions/components/PlatformLink.tsx @@ -1,16 +1,6 @@ -import { FaExternalLinkAlt } from "react-icons/fa"; - +import { BoxedLink } from "../../common/BoxedLink"; import { QuestionFragment } from "../../fragments.generated"; export const PlatformLink: React.FC<{ question: QuestionFragment }> = ({ question, -}) => ( - - {question.platform.label} - - -); +}) => {question.platform.label}; diff --git a/src/web/questions/components/QuestionCard/index.tsx b/src/web/questions/components/QuestionCard/index.tsx index 14d3608..7468b92 100644 --- a/src/web/questions/components/QuestionCard/index.tsx +++ b/src/web/questions/components/QuestionCard/index.tsx @@ -1,7 +1,7 @@ import Link from "next/link"; +import { ReactElement, ReactNode } from "react"; import { FaExpand } from "react-icons/fa"; import ReactMarkdown from "react-markdown"; - import { Card } from "../../../common/Card"; import { CopyText } from "../../../common/CopyText"; import { QuestionFragment } from "../../../fragments.generated"; @@ -63,6 +63,7 @@ const LastUpdated: React.FC<{ timestamp: Date }> = ({ timestamp }) => ( // Main component interface Props { + container?: (children: ReactNode) => ReactElement; question: QuestionFragment; showTimeStamp: boolean; expandFooterToFullWidth: boolean; @@ -71,6 +72,7 @@ interface Props { } export const QuestionCard: React.FC = ({ + container = (children) => {children}, question, showTimeStamp, expandFooterToFullWidth, @@ -82,72 +84,70 @@ export const QuestionCard: React.FC = ({ const isBinary = isQuestionBinary(question); - return ( - -
-
- {showIdToggle ? ( -
- -
- ) : null} -
- {showExpandButton ? ( - - - - - - ) : null} - - - {question.title} + return container( +
+
+ {showIdToggle ? ( +
+ +
+ ) : null} +
-
- -
- -
-
- - {question.platform.id !== "guesstimate" && options.length < 3 && ( -
- -
- )} - - {question.platform.id === "guesstimate" && question.visualization && ( - Guesstimate Screenshot - )} + + ) : null} + + + {question.title} + +
-
- {/* This one is exclusively for mobile*/} - -
-
-
- +
+ +
+
+ + {question.platform.id !== "guesstimate" && options.length < 3 && ( +
+ +
+ )} + + {question.platform.id === "guesstimate" && question.visualization && ( + Guesstimate Screenshot + )} +
+
+ {/* This one is exclusively for mobile*/} + +
+
+
+ +
- +
); }; diff --git a/src/web/questions/pages/QuestionPage.tsx b/src/web/questions/pages/QuestionPage.tsx index 25b5efd..d19af1e 100644 --- a/src/web/questions/pages/QuestionPage.tsx +++ b/src/web/questions/pages/QuestionPage.tsx @@ -1,11 +1,10 @@ import { GetServerSideProps, NextPage } from "next"; import NextError from "next/error"; import ReactMarkdown from "react-markdown"; - +import { BoxedLink } from "../../common/BoxedLink"; import { Card } from "../../common/Card"; import { CopyParagraph } from "../../common/CopyParagraph"; import { Layout } from "../../common/Layout"; -import { LineHeader } from "../../common/LineHeader"; import { Query } from "../../common/Query"; import { QuestionWithHistoryFragment } from "../../fragments.generated"; import { ssrUrql } from "../../urql"; @@ -43,13 +42,51 @@ export const getServerSideProps: GetServerSideProps = async ( }; }; -const Section: React.FC<{ title: string }> = ({ title, children }) => ( -
-

{title}

+const Section: React.FC<{ title: string; id?: string }> = ({ + title, + children, + id, +}) => ( +
+
+

+ {title} + {id ? ( + <> + {" "} + + # + + + ) : null} +

+
{children}
); +const EmbedSection: React.FC<{ question: QuestionWithHistoryFragment }> = ({ + question, +}) => { + const url = getBasePath() + `/questions/embed/${question.id}`; + return ( +
+
+ + Preview + +
+ `} + buttonText="Copy HTML" + /> +
+ ); +}; + const LargeQuestionCard: React.FC<{ question: QuestionWithHistoryFragment; }> = ({ question }) => { @@ -65,8 +102,8 @@ const LargeQuestionCard: React.FC<{
-
-
+
+
-
-
- -
-
+
+ +
+
+ +
+
); }; -const QuestionScreen: React.FC<{ question: QuestionWithHistoryFragment }> = ({ - question, -}) => ( -
- -
- -

Capture

-
- - -

Embed

-
-
- `} - buttonText="Copy HTML" - /> -
-
-
-); const QuestionPage: NextPage = ({ id }) => { return ( @@ -115,7 +130,7 @@ const QuestionPage: NextPage = ({ id }) => { {({ data }) => data.result ? ( - + ) : ( )