-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62a57c5
commit afe636e
Showing
31 changed files
with
1,308 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Image from 'next/image' | ||
import Link from 'next/link' | ||
|
||
import { Highlight } from 'react-instantsearch-dom' | ||
import { getImageUrl } from 'utils/getImageUrl' | ||
import formatPrice from 'utils/format-price' | ||
|
||
import { Apple, Windows, Linux } from '@styled-icons/fa-brands' | ||
import * as S from './styles' | ||
|
||
import { GameHitProps, Platform } from '.' | ||
|
||
export type HitProps = { | ||
hit: GameHitProps | ||
} | ||
|
||
const Hit = ({ hit }: HitProps) => { | ||
const platformIcons = { | ||
linux: <Linux title="Linux" />, | ||
mac: <Apple title="Mac" />, | ||
windows: <Windows title="Windows" /> | ||
} | ||
const releaseYear = | ||
hit.release_date && new Date(hit.release_date).getFullYear() | ||
|
||
return ( | ||
<Link href={`game/${hit.slug}`} passHref> | ||
<S.Result> | ||
<S.ImageWrapper> | ||
<Image | ||
src={`${getImageUrl(hit.cover?.url)}`} | ||
alt={hit.name} | ||
layout="fill" | ||
objectFit="cover" | ||
/> | ||
</S.ImageWrapper> | ||
<S.Info> | ||
<S.Title> | ||
<Highlight attribute="name" hit={hit} /> | ||
{releaseYear && ( | ||
<S.ReleaseYear | ||
itemProp="releaseYear" | ||
dateTime={hit.release_date!} | ||
> | ||
{releaseYear} | ||
</S.ReleaseYear> | ||
)} | ||
</S.Title> | ||
<S.Details> | ||
<S.Price>{formatPrice(hit.price)}</S.Price> | ||
<S.Platform> | ||
{hit.platforms.map((icon: Platform) => ( | ||
<S.PlatformIcon key={`${hit.id}${icon.name}`}> | ||
{platformIcons[icon.name]} | ||
</S.PlatformIcon> | ||
))} | ||
</S.Platform> | ||
</S.Details> | ||
<S.Description> | ||
<Highlight attribute="short_description" hit={hit} /> | ||
</S.Description> | ||
</S.Info> | ||
</S.Result> | ||
</Link> | ||
) | ||
} | ||
|
||
export default Hit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { connectHits, connectStateResults } from 'react-instantsearch-dom' | ||
|
||
import NoResults from '../NoResults' | ||
import Hit from './Hit' | ||
|
||
import * as S from './styles' | ||
|
||
export type Platform = { | ||
name: 'windows' | 'linux' | 'mac' | ||
} | ||
|
||
export type Cover = { | ||
url: string | ||
} | ||
|
||
export type GameHitProps = { | ||
id: string | ||
name: string | ||
short_description: string | ||
cover: Cover | null | ||
slug: string | ||
price: number | ||
platforms: Platform[] | ||
release_date: string | null | ||
} | ||
|
||
export type HitsProps = { | ||
hits: GameHitProps[] | ||
} | ||
|
||
const Hits = connectHits(({ hits }: HitsProps) => ( | ||
<S.List> | ||
{hits.length ? ( | ||
hits.map((hit) => ( | ||
<S.ListItem key={hit.id}> | ||
<Hit hit={hit} /> | ||
</S.ListItem> | ||
)) | ||
) : ( | ||
<NoResults /> | ||
)} | ||
</S.List> | ||
)) | ||
|
||
export default connectStateResults(({ searchState }) => | ||
searchState?.query ? <Hits /> : null | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { GameHitProps } from '.' | ||
|
||
export default [ | ||
{ | ||
id: '1', | ||
name: 'Game 1', | ||
short_description: 'Description', | ||
cover: { | ||
url: '/cover-1.jpg' | ||
}, | ||
slug: 'game-1', | ||
price: 25, | ||
platforms: [{ name: 'windows' }], | ||
release_date: '2015-12-05' | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Game 2', | ||
short_description: 'Description', | ||
cover: { | ||
url: '/cover-2.jpg' | ||
}, | ||
slug: 'game-2', | ||
price: 12, | ||
platforms: [{ name: 'linux' }], | ||
release_date: '2006-10-30' | ||
} | ||
] as GameHitProps[] |
Oops, something went wrong.