From 277fa8fc3c37a5254ace26185c338fa0c508ef5b Mon Sep 17 00:00:00 2001 From: Chris Elliott Date: Sun, 27 Jun 2021 11:25:42 -0700 Subject: [PATCH 1/4] Fix link bugs. --- .../src/components/problem/editor/ProblemDisplay.tsx | 9 +++++++-- frontend/src/views/VerifiedProblemsPage.tsx | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/problem/editor/ProblemDisplay.tsx b/frontend/src/components/problem/editor/ProblemDisplay.tsx index 103c961a..910f063b 100644 --- a/frontend/src/components/problem/editor/ProblemDisplay.tsx +++ b/frontend/src/components/problem/editor/ProblemDisplay.tsx @@ -130,10 +130,15 @@ function ProblemDisplay(props: ProblemDisplayParams) { { - // eslint-disable-next-line no-alert if (JSON.stringify(problem) === JSON.stringify(newProblem) + // eslint-disable-next-line no-alert || window.confirm('Go back? Your unsaved changes will be lost.')) { - history.goBack(); + // Use the return link if available; otherwise, use dashboard. + if (history.action !== 'POP') { + history.goBack(); + } else { + history.push('/'); + } } }} > diff --git a/frontend/src/views/VerifiedProblemsPage.tsx b/frontend/src/views/VerifiedProblemsPage.tsx index 4561d4ff..55f3dbaf 100644 --- a/frontend/src/views/VerifiedProblemsPage.tsx +++ b/frontend/src/views/VerifiedProblemsPage.tsx @@ -37,7 +37,7 @@ function VerifiedProblemsPage() { return ( Verified Problems - Create new problem → + Create new problem → From 52fb77285bc523e965608c2778a8ac251a5405ec Mon Sep 17 00:00:00 2001 From: Chris Elliott Date: Sun, 27 Jun 2021 12:49:55 -0700 Subject: [PATCH 2/4] Only set problem on problem page once. --- frontend/src/views/ProblemPage.tsx | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/frontend/src/views/ProblemPage.tsx b/frontend/src/views/ProblemPage.tsx index baa8c247..337fbabe 100644 --- a/frontend/src/views/ProblemPage.tsx +++ b/frontend/src/views/ProblemPage.tsx @@ -37,18 +37,21 @@ function ProblemPage() { return; } - setLoading(true); - getSingleProblem(params.id, token!) - .then((res) => { - res.testCases.forEach((testCase) => { - // eslint-disable-next-line no-param-reassign - testCase.id = generateRandomId(); - }); - setProblem(res); - }) - .catch((err) => setError(err.message)) - .finally(() => setLoading(false)); - }, [params, token]); + // Checks added to ensure problem fetched only once. + if (!problem && !loading) { + setLoading(true); + getSingleProblem(params.id, token!) + .then((res) => { + res.testCases.forEach((testCase) => { + // eslint-disable-next-line no-param-reassign + testCase.id = generateRandomId(); + }); + setProblem(res); + }) + .catch((err) => setError(err.message)) + .finally(() => setLoading(false)); + } + }, [params, token, problem, loading]); if (!problem) { if (error && !loading) { From f17d68da1e5c62a02cf269e623f1a4a2e3af0aa7 Mon Sep 17 00:00:00 2001 From: Chris Elliott Date: Sun, 27 Jun 2021 13:05:22 -0700 Subject: [PATCH 3/4] Update the problem card to restrict description to one line. --- frontend/src/components/card/ProblemCard.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/card/ProblemCard.tsx b/frontend/src/components/card/ProblemCard.tsx index c2720f0e..c75d0dba 100644 --- a/frontend/src/components/card/ProblemCard.tsx +++ b/frontend/src/components/card/ProblemCard.tsx @@ -43,6 +43,14 @@ const TitleText = styled(LargeText)` vertical-align: middle; `; +const DescriptionText = styled(Text)` + display: -webkit-box; + -webkit-line-clamp: 1; + overflow: hidden; + -webkit-box-orient: vertical; + word-break: break-all; +`; + function ProblemCard(props: ProblemCardProps) { const { problem } = props; @@ -52,7 +60,7 @@ function ProblemCard(props: ProblemCardProps) { {problem.name} {getDifficultyDisplayButton(problem.difficulty, true)} - {`${problem.description.substring(0, 80)}...`} + {problem.description} {problem.problemTags.map((tag) => ( From 0b91059485580c5bd73c223a605445a193b99861 Mon Sep 17 00:00:00 2001 From: Chris Elliott Date: Thu, 1 Jul 2021 20:24:55 -0700 Subject: [PATCH 4/4] Create the single line text component. --- frontend/src/components/card/ProblemCard.tsx | 12 ++---------- frontend/src/components/core/Text.tsx | 8 ++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/card/ProblemCard.tsx b/frontend/src/components/card/ProblemCard.tsx index c75d0dba..49c10ee9 100644 --- a/frontend/src/components/card/ProblemCard.tsx +++ b/frontend/src/components/card/ProblemCard.tsx @@ -1,7 +1,7 @@ import React from 'react'; import styled from 'styled-components'; import { Problem } from '../../api/Problem'; -import { LargeText, SelectedItemText, Text } from '../core/Text'; +import { LargeText, SelectedItemText, SingleLineText } from '../core/Text'; import { getDifficultyDisplayButton } from '../core/Button'; import { SelectedItemContainer } from '../core/Container'; import { DivLink } from '../core/Link'; @@ -43,14 +43,6 @@ const TitleText = styled(LargeText)` vertical-align: middle; `; -const DescriptionText = styled(Text)` - display: -webkit-box; - -webkit-line-clamp: 1; - overflow: hidden; - -webkit-box-orient: vertical; - word-break: break-all; -`; - function ProblemCard(props: ProblemCardProps) { const { problem } = props; @@ -60,7 +52,7 @@ function ProblemCard(props: ProblemCardProps) { {problem.name} {getDifficultyDisplayButton(problem.difficulty, true)} - {problem.description} + {problem.description} {problem.problemTags.map((tag) => ( diff --git a/frontend/src/components/core/Text.tsx b/frontend/src/components/core/Text.tsx index 79555de2..90d15950 100644 --- a/frontend/src/components/core/Text.tsx +++ b/frontend/src/components/core/Text.tsx @@ -153,3 +153,11 @@ export const SelectedItemText = styled.p` display: inline; margin: 0 10px; `; + +export const SingleLineText = styled(Text)` + display: -webkit-box; + -webkit-line-clamp: 1; + overflow: hidden; + -webkit-box-orient: vertical; + word-break: break-all; +`;