-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display the top artists as part of the results
- Loading branch information
1 parent
0dea433
commit fbc8400
Showing
7 changed files
with
106 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useEffect } from 'react' | ||
import styled from 'styled-components' | ||
import 'react-lazy-load-image-component/src/effects/opacity.css' | ||
import Box from 'components/Box' | ||
import Card from 'components/Card' | ||
import Typography from 'components/Typography' | ||
|
||
const CustomCard = styled(Card)` | ||
display: flex; | ||
align-items: flex-start; | ||
flex-wrap: wrap; | ||
` | ||
|
||
const MainContainer = styled.ul` | ||
list-style: none; | ||
padding-left: 0; | ||
min-width: 300px; | ||
` | ||
|
||
const ArtistContainer = styled.li` | ||
margin-bottom: 16px; | ||
` | ||
|
||
const ArtistHit = ({ hit }) => { | ||
useEffect(() => { | ||
if (!hit._highlightResult) { | ||
// eslint-disable-next-line no-console | ||
console.warn('Your hits have no field. Please check your index settings.') | ||
} | ||
}, [hit._highlightResult]) | ||
|
||
return ( | ||
<ArtistContainer> | ||
<CustomCard> | ||
<Box width={200} mr={4} flexShrink={0}> | ||
{hit.artist} | ||
</Box> | ||
</CustomCard> | ||
</ArtistContainer> | ||
) | ||
} | ||
|
||
const ArtistHits = ({ hits, index, limit = 4 }) => ( | ||
<MainContainer> | ||
<Typography variant="typo1" color="main.default" mb={3}> | ||
Top Artists | ||
</Typography> | ||
{hits.slice(0, limit).map((artistHit) => ( | ||
<ArtistHit key={`artists-${index}-${artistHit.id}`} hit={artistHit} /> | ||
))} | ||
</MainContainer> | ||
) | ||
|
||
export default ArtistHits |
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,15 @@ | ||
import React, { createContext, useContext, useState, useMemo } from 'react' | ||
|
||
const ArtistsContext = createContext() | ||
|
||
export const useArtists = () => useContext(ArtistsContext) | ||
|
||
export const ArtistsProvider = ({ children }) => { | ||
const [artists, setArtists] = useState([]) | ||
|
||
const value = useMemo(() => ({ artists, setArtists }), [artists]) | ||
|
||
return ( | ||
<ArtistsContext.Provider value={value}>{children}</ArtistsContext.Provider> | ||
) | ||
} |