From 6e25f8bcd29444dbf5de94cc3cc387eff1283386 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 31 May 2022 23:50:27 +0300 Subject: [PATCH] feat: question page style changes --- src/web/common/BoxedLink.tsx | 23 ++++ .../questions/components/CaptureQuestion.tsx | 77 +++++++---- src/web/questions/components/PlatformLink.tsx | 14 +- .../components/QuestionCard/index.tsx | 126 +++++++++--------- src/web/questions/pages/QuestionPage.tsx | 71 +++++----- 5 files changed, 169 insertions(+), 142 deletions(-) create mode 100644 src/web/common/BoxedLink.tsx 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 8167322..883b500 100644 --- a/src/web/questions/components/CaptureQuestion.tsx +++ b/src/web/questions/components/CaptureQuestion.tsx @@ -1,7 +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"; @@ -80,6 +79,15 @@ const MetaculusSource: React.FC<{ ); }; +const GrayContainer: React.FC<{ title: string }> = ({ title, children }) => ( +
+
+ {title}: +
+
{children}
+
+); + interface Props { question: QuestionFragment; } @@ -121,42 +129,53 @@ export const CaptureQuestion: React.FC = ({ question }) => { if (imgSrc) { return ( -
-
- -
+
+ + + + +
-
- -
-
- -
+ {question.platform.id === "metaculus" ? ( + <> +
+ +
+
+ +
+ + ) : null}
); } return ( -
- -
- -
-
-
- -
+
+ + +
+ ( +
{children}
+ )} + question={question} + showTimeStamp={true} + showExpandButton={false} + expandFooterToFullWidth={true} + /> +
+
+
+
); }; 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..9903c92 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 6b08379..f1d6e85 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"; @@ -44,12 +43,33 @@ export const getServerSideProps: GetServerSideProps = async ( }; const Section: React.FC<{ title: string }> = ({ title, children }) => ( -
-

{title}

+
+
+

{title}

+
{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,7 +85,7 @@ const LargeQuestionCard: React.FC<{
-
+
-
-
- -
-
+
+ +
+
+ +
+
); }; -const QuestionScreen: React.FC<{ question: QuestionWithHistoryFragment }> = ({ - question, -}) => ( -
- -
- -

Capture

-
- -
-
- -

Embed

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