Skip to content

Commit 85e2daa

Browse files
committed
More inlining
1 parent 965f1d5 commit 85e2daa

File tree

3 files changed

+67
-83
lines changed

3 files changed

+67
-83
lines changed

website/src/components/ErrorMessage.tsx

-32
This file was deleted.

website/src/components/Home.tsx

+67-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import React, {useCallback, useState} from 'react';
22
import {useHistory, useLocation} from 'react-router-dom';
3+
import styled from 'styled-components';
34

45
import {fetchShortestPaths} from '../api.ts';
56
import {WikipediaPage, WikipediaPageId} from '../types.ts';
67
import {getRandomPageTitle} from '../utils.ts';
8+
import {Button} from './common/Button.tsx';
79
import {Logo} from './common/Logo.tsx';
8-
import {ErrorMessage} from './ErrorMessage.tsx';
910
import {InputFlexContainer, Modal, P} from './Home.styles.ts';
1011
import {Loading} from './Loading.tsx';
1112
import {NavLinks} from './NavLinks.tsx';
1213
import {PageInput} from './PageInput.tsx';
1314
import {Results} from './Results.tsx';
14-
import {SearchButton} from './SearchButton.tsx';
1515
import {SwapInputValuesButton} from './SwapInputValuesButton.tsx';
1616

1717
interface ShortestPathsState {
@@ -24,6 +24,50 @@ interface ShortestPathsState {
2424
readonly durationInSeconds: string;
2525
}
2626

27+
const SearchButtonWrapper = styled(Button)`
28+
width: 240px;
29+
height: 72px;
30+
margin: 0 auto 40px;
31+
font-size: 32px;
32+
border-radius: 8px;
33+
34+
@media (max-width: 600px) {
35+
width: 200px;
36+
height: 60px;
37+
font-size: 28px;
38+
}
39+
`;
40+
41+
const ErrorMessageWrapper = styled.p`
42+
width: 700px;
43+
margin: 40px auto;
44+
font-size: 28px;
45+
text-align: center;
46+
line-height: 1.5;
47+
color: ${({theme}) => theme.colors.red};
48+
text-shadow: black 1px 1px;
49+
50+
@media (max-width: 1200px) {
51+
width: 70%;
52+
font-size: 24px;
53+
}
54+
`;
55+
56+
const ErrorMessage: React.FC<{
57+
readonly text: string;
58+
}> = ({text}) => {
59+
const tokens = text.split('"');
60+
61+
return (
62+
<ErrorMessageWrapper>
63+
{tokens.map((token, i) =>
64+
// Bold page titles in the provided error message.
65+
i % 2 === 0 ? <span key={i}>{token}</span> : <b key={i}>"{token}"</b>
66+
)}
67+
</ErrorMessageWrapper>
68+
);
69+
};
70+
2771
export const Home: React.FC = () => {
2872
const history = useHistory();
2973
const location = useLocation();
@@ -39,7 +83,7 @@ export const Home: React.FC = () => {
3983
const [targetPagePlaceholderText, setTargetPagePlaceholderText] = useState(getRandomPageTitle());
4084

4185
const [shortestPathsState, setShortestPathsState] = useState<ShortestPathsState | null>(null);
42-
const [isFetchingShortestPaths, setIsFetchingShortestPaths] = useState(false);
86+
const [isFetchingResults, setIsFetchingResults] = useState(false);
4387
const [errorMessage, setErrorMessage] = useState<string | null>(null);
4488

4589
const handleOpenModal = () => setShowModal(true);
@@ -49,7 +93,7 @@ export const Home: React.FC = () => {
4993
const startTimeInMilliseconds = Date.now();
5094

5195
setShortestPathsState(null);
52-
setIsFetchingShortestPaths(true);
96+
setIsFetchingResults(true);
5397
setErrorMessage(null);
5498

5599
const actualSourcePageTitle = sourcePageTitle || sourcePagePlaceholderText;
@@ -96,7 +140,7 @@ export const Home: React.FC = () => {
96140
}
97141
}
98142

99-
setIsFetchingShortestPaths(false);
143+
setIsFetchingResults(false);
100144
}, [
101145
history,
102146
sourcePagePlaceholderText,
@@ -115,7 +159,7 @@ export const Home: React.FC = () => {
115159

116160
// Reset shortest paths reponse data.
117161
setShortestPathsState(null);
118-
setIsFetchingShortestPaths(false);
162+
setIsFetchingResults(false);
119163
setErrorMessage(null);
120164
}}
121165
/>
@@ -168,25 +212,26 @@ export const Home: React.FC = () => {
168212
/>
169213
</InputFlexContainer>
170214

171-
<SearchButton
172-
sourcePageTitle={sourcePageTitle}
173-
targetPageTitle={targetPageTitle}
174-
isFetchingResults={isFetchingShortestPaths}
175-
onClick={async () => {
176-
if (sourcePageTitle.trim().length === 0) {
177-
setSourcePageTitle(sourcePagePlaceholderText);
178-
}
179-
if (targetPageTitle.trim().length === 0) {
180-
setTargetPageTitle(targetPagePlaceholderText);
181-
}
182-
183-
await handleFetchShortestPaths();
184-
}}
185-
/>
215+
{isFetchingResults ? (
216+
<SearchButtonWrapper
217+
onClick={async () => {
218+
if (sourcePageTitle.trim().length === 0) {
219+
setSourcePageTitle(sourcePagePlaceholderText);
220+
}
221+
if (targetPageTitle.trim().length === 0) {
222+
setTargetPageTitle(targetPagePlaceholderText);
223+
}
224+
225+
await handleFetchShortestPaths();
226+
}}
227+
>
228+
Go!
229+
</SearchButtonWrapper>
230+
) : null}
186231

187232
{errorMessage !== null ? (
188233
<ErrorMessage text={errorMessage} />
189-
) : isFetchingShortestPaths ? (
234+
) : isFetchingResults ? (
190235
<Loading />
191236
) : shortestPathsState ? (
192237
<Results

website/src/components/SearchButton.tsx

-29
This file was deleted.

0 commit comments

Comments
 (0)