Skip to content

Commit 4534009

Browse files
🔨 Switch Search to use useOvermind (codesandbox#3048)
* 🔨 Switch Search to use useOvermind * Use RouteComponentProps types * Export Search as a named export * Update search.ts Co-authored-by: Sara Vieira <[email protected]>
1 parent 69dd788 commit 4534009

File tree

6 files changed

+415
-406
lines changed

6 files changed

+415
-406
lines changed

‎packages/app/src/app/pages/Search/elements.js‎

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Row from '@codesandbox/common/lib/components/flex/Row';
2+
import styled, { css } from 'styled-components';
3+
4+
import { Title as TitleBase } from 'app/components/Title';
5+
6+
export const Content = styled.div`
7+
margin-top: 5%;
8+
text-align: left;
9+
color: white;
10+
`;
11+
12+
export const Title = styled(TitleBase)`
13+
${({ theme }) => css`
14+
font-family: 'Poppins', sans-serif;
15+
font-weight: 600;
16+
font-size: 36px;
17+
display: flex;
18+
color: ${theme.lightText};
19+
margin-bottom: 16px;
20+
`};
21+
`;
22+
23+
export const Main = styled(Row)`
24+
display: grid;
25+
grid-template-columns: 1fr 340px;
26+
grid-gap: 24px;
27+
28+
@media (max-width: 768px) {
29+
grid-template-columns: 1fr;
30+
}
31+
`;
32+
33+
export const Container = styled.div`
34+
${({ theme }) => css`
35+
background: ${theme.background5};
36+
width: 100vw;
37+
`};
38+
`;

‎packages/app/src/app/pages/Search/index.tsx‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,47 @@ import {
33
ALGOLIA_APPLICATION_ID,
44
ALGOLIA_DEFAULT_INDEX,
55
} from '@codesandbox/common/lib/utils/config';
6-
import { Helmet } from 'react-helmet';
76
import MaxWidth from '@codesandbox/common/lib/components/flex/MaxWidth';
87
import Margin from '@codesandbox/common/lib/components/spacing/Margin';
8+
import { RouteComponentProps } from 'react-router-dom';
99
import qs from 'qs';
10-
import React, { useCallback, useEffect, useRef, useState } from 'react';
10+
import React, {
11+
FunctionComponent,
12+
useCallback,
13+
useEffect,
14+
useRef,
15+
useState,
16+
} from 'react';
17+
import { Helmet } from 'react-helmet';
1118
import {
19+
Configure,
1220
InstantSearch,
13-
SearchBox,
1421
PoweredBy,
15-
Configure,
22+
SearchBox,
1623
} from 'react-instantsearch/dom';
17-
import { History, Location } from 'history';
1824

19-
import { Navigation } from 'app/pages/common/Navigation';
2025
import { useOvermind } from 'app/overmind';
26+
import { Navigation } from 'app/pages/common/Navigation';
2127

2228
import 'instantsearch.css/themes/reset.css';
2329

24-
import { Container, Content, Main, StyledTitle } from './elements';
30+
import { Container, Content, Main, Title } from './elements';
2531
import Filters from './Filters';
2632
import Results from './Results';
2733
import Styles from './search';
2834

29-
interface ISearchProps {
30-
history: History;
31-
location: Location;
32-
}
33-
3435
const updateAfter = 700;
3536

3637
const createURL = state => `?${qs.stringify(state)}`;
3738

3839
const searchStateToUrl = (location, searchState) =>
3940
searchState ? `${location.pathname}${createURL(searchState)}` : '';
4041

41-
const Search: React.FC<ISearchProps> = ({ history, location }) => {
42+
type Props = RouteComponentProps;
43+
export const Search: FunctionComponent<Props> = ({ history, location }) => {
4244
const {
4345
actions: { searchMounted },
4446
} = useOvermind();
45-
4647
const [searchState, setSearchState] = useState(
4748
qs.parse(location.search.slice(1))
4849
);
@@ -83,6 +84,7 @@ const Search: React.FC<ISearchProps> = ({ history, location }) => {
8384
<Helmet>
8485
<title>Search - CodeSandbox</title>
8586
</Helmet>
87+
8688
<Styles />
8789

8890
<MaxWidth>
@@ -91,8 +93,8 @@ const Search: React.FC<ISearchProps> = ({ history, location }) => {
9193

9294
<Content>
9395
<InstantSearch
94-
appId={ALGOLIA_APPLICATION_ID}
9596
apiKey={ALGOLIA_API_KEY}
97+
appId={ALGOLIA_APPLICATION_ID}
9698
createURL={createURL}
9799
indexName={ALGOLIA_DEFAULT_INDEX}
98100
onSearchStateChange={onSearchStateChange}
@@ -102,7 +104,7 @@ const Search: React.FC<ISearchProps> = ({ history, location }) => {
102104

103105
<Main alignItems="flex-start">
104106
<div>
105-
<StyledTitle>Search</StyledTitle>
107+
<Title>Search</Title>
106108

107109
<PoweredBy />
108110

@@ -123,6 +125,3 @@ const Search: React.FC<ISearchProps> = ({ history, location }) => {
123125
</Container>
124126
);
125127
};
126-
127-
// eslint-disable-next-line import/no-default-export
128-
export default Search;

0 commit comments

Comments
 (0)