Skip to content

Commit 5389da0

Browse files
authored
Merge pull request #175 from CodeJoustHQ/LinkBugFixes
Fix link bugs and add style improvements.
2 parents a2e1435 + 0b91059 commit 5389da0

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

frontend/src/components/card/ProblemCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import styled from 'styled-components';
33
import { Problem } from '../../api/Problem';
4-
import { LargeText, SelectedItemText, Text } from '../core/Text';
4+
import { LargeText, SelectedItemText, SingleLineText } from '../core/Text';
55
import { getDifficultyDisplayButton } from '../core/Button';
66
import { SelectedItemContainer } from '../core/Container';
77
import { DivLink } from '../core/Link';
@@ -52,7 +52,7 @@ function ProblemCard(props: ProblemCardProps) {
5252
<InnerContent>
5353
<TitleText>{problem.name}</TitleText>
5454
{getDifficultyDisplayButton(problem.difficulty, true)}
55-
<Text>{`${problem.description.substring(0, 80)}...`}</Text>
55+
<SingleLineText>{problem.description}</SingleLineText>
5656

5757
{problem.problemTags.map((tag) => (
5858
<ProblemTagContainer key={tag.name}>

frontend/src/components/core/Text.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,11 @@ export const SelectedItemText = styled.p`
153153
display: inline;
154154
margin: 0 10px;
155155
`;
156+
157+
export const SingleLineText = styled(Text)`
158+
display: -webkit-box;
159+
-webkit-line-clamp: 1;
160+
overflow: hidden;
161+
-webkit-box-orient: vertical;
162+
word-break: break-all;
163+
`;

frontend/src/components/problem/editor/ProblemDisplay.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,15 @@ function ProblemDisplay(props: ProblemDisplayParams) {
130130
<TopButtonsContainer>
131131
<InvertedSmallButton
132132
onClick={() => {
133-
// eslint-disable-next-line no-alert
134133
if (JSON.stringify(problem) === JSON.stringify(newProblem)
134+
// eslint-disable-next-line no-alert
135135
|| window.confirm('Go back? Your unsaved changes will be lost.')) {
136-
history.goBack();
136+
// Use the return link if available; otherwise, use dashboard.
137+
if (history.action !== 'POP') {
138+
history.goBack();
139+
} else {
140+
history.push('/');
141+
}
137142
}
138143
}}
139144
>

frontend/src/views/ProblemPage.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,21 @@ function ProblemPage() {
3737
return;
3838
}
3939

40-
setLoading(true);
41-
getSingleProblem(params.id, token!)
42-
.then((res) => {
43-
res.testCases.forEach((testCase) => {
44-
// eslint-disable-next-line no-param-reassign
45-
testCase.id = generateRandomId();
46-
});
47-
setProblem(res);
48-
})
49-
.catch((err) => setError(err.message))
50-
.finally(() => setLoading(false));
51-
}, [params, token]);
40+
// Checks added to ensure problem fetched only once.
41+
if (!problem && !loading) {
42+
setLoading(true);
43+
getSingleProblem(params.id, token!)
44+
.then((res) => {
45+
res.testCases.forEach((testCase) => {
46+
// eslint-disable-next-line no-param-reassign
47+
testCase.id = generateRandomId();
48+
});
49+
setProblem(res);
50+
})
51+
.catch((err) => setError(err.message))
52+
.finally(() => setLoading(false));
53+
}
54+
}, [params, token, problem, loading]);
5255

5356
if (!problem) {
5457
if (error && !loading) {

frontend/src/views/VerifiedProblemsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function VerifiedProblemsPage() {
3737
return (
3838
<Content>
3939
<LargeText>Verified Problems</LargeText>
40-
<TextLink to="/game/create">Create new problem &#8594;</TextLink>
40+
<TextLink to="/problem/create">Create new problem &#8594;</TextLink>
4141

4242
<FilteredProblemList problems={verifiedProblems} />
4343

0 commit comments

Comments
 (0)