Skip to content

Commit

Permalink
feat: add search page
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardocasares committed Oct 28, 2020
1 parent 9da6711 commit 370fbb9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/components/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { Container, Cover, Button, Title, Subtitle, Body } from "./style";
const DEFAULT_SUBTITLE = "Global";

export type Card = {
hash: string;
title: string;
subtitle: string;
onClick: (ev: React.MouseEvent) => void;
};

export const Card: FC<Card> = ({ title, subtitle, onClick }) => (
export const Card: FC<Card> = ({ hash, title, subtitle, onClick }) => (
<Container>
<Cover hash={[title, subtitle].join("-")}>
<Cover hash={hash || Date.now().toString()}>
<Button onClick={onClick}>
<PlayCircle size={64} />
</Button>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Card/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styled from "@emotion/styled";
import gradient from "random-gradient";

export const Container = styled.div`
border-radius: var(--sz2);
border-radius: var(--sz1);
`;

export type Cover = {
Expand All @@ -14,8 +14,8 @@ export const Cover = styled.div<Cover>`
place-items: center;
min-width: 100%;
min-height: 120px;
border-top-left-radius: var(--sz2);
border-top-right-radius: var(--sz2);
border-top-left-radius: var(--sz1);
border-top-right-radius: var(--sz1);
background: ${({ hash }) => gradient(hash, "vertical")};
`;

Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Header = () => (
</Link>

<Navigation>
<Link href="/">
<Link href="/search">
<a>
<Search />
</a>
Expand Down
19 changes: 19 additions & 0 deletions src/components/SearchInput/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import styled from "@emotion/styled";

export const SearchInput = styled.input`
width: 100%;
padding: var(--sz3);
font-size: var(--sz4);
border-radius: var(--sz1);
margin-bottom: var(--sz4);
color: var(--foreground);
background: var(--background);
border: 1px solid var(--accents-2);
outline: none;
transition: border-color 0.2s;
:hover,
:focus {
border-color: var(--accents-4);
}
`;
3 changes: 2 additions & 1 deletion src/components/StationCardList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const GQLStations: FC<StationSearchInput> = graphql(
<AutoGrid gridGap={["var(--sz4)"]}>
{query.stations({ search }).map((station) => (
<Card
key={[station.stationuuid, station.url].join("-")}
key={[station.url, station.stationuuid].join()}
hash={station.stationuuid}
title={station.name}
subtitle={station.country}
onClick={() => load(station)}
Expand Down
32 changes: 32 additions & 0 deletions src/pages/search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useState, useRef, useEffect } from "react";
import { Box } from "@/components/Box";
import { Heading } from "@/components/Typography";
import { SearchInput } from "@/components/SearchInput";
import { StationCardList } from "@/components/StationCardList";

export const Index = () => {
const input = useRef<HTMLInputElement>(null);
const [query, setQuery] = useState("");

const showList = query.length >= 3;
const onChange = ({ target: { value } }) => setQuery(value);

useEffect(() => input.current.focus(), []);

return (
<Box p={["var(--sz4)"]}>
<Heading as="h3">Search</Heading>

<SearchInput
type="text"
onChange={onChange}
ref={input}
placeholder="Type something ..."
/>

{showList && <StationCardList name={query} limit={20} />}
</Box>
);
};

export default Index;

0 comments on commit 370fbb9

Please sign in to comment.