2020-07-23 12:07:29 +00:00
|
|
|
import React from 'react';
|
2020-07-23 22:12:31 +00:00
|
|
|
import { Box, Grid, ResponsiveContext, Heading } from 'grommet';
|
2020-07-23 09:43:12 +00:00
|
|
|
|
2020-07-23 22:12:31 +00:00
|
|
|
import { Album } from './Album';
|
2020-07-24 12:14:16 +00:00
|
|
|
import { Artists, Albums } from '../interfaces';
|
2020-07-23 22:12:31 +00:00
|
|
|
import { Other } from './Other';
|
2020-07-23 12:07:29 +00:00
|
|
|
|
2020-07-23 23:10:57 +00:00
|
|
|
export const Results = ({
|
|
|
|
artists,
|
|
|
|
handleClick,
|
|
|
|
}: {
|
|
|
|
artists: Artists;
|
2020-07-24 11:58:02 +00:00
|
|
|
handleClick: (name: string) => void;
|
2020-07-23 23:10:57 +00:00
|
|
|
}) => {
|
2020-07-23 17:53:47 +00:00
|
|
|
const {
|
|
|
|
name: selectedName,
|
|
|
|
image: selectedImage,
|
2020-07-24 12:14:16 +00:00
|
|
|
albums,
|
2020-07-23 17:53:47 +00:00
|
|
|
} = artists[0];
|
2020-07-24 12:14:16 +00:00
|
|
|
const otherArtists = artists.slice(1, artists.length);
|
|
|
|
let selectedAlbums: Albums = [];
|
|
|
|
|
|
|
|
// Remove duplicate albums based on `name`
|
|
|
|
// Might need to refine this according to the data quality
|
|
|
|
const uniqueAlbums = new Set();
|
|
|
|
albums.forEach((album) => {
|
|
|
|
if (!uniqueAlbums.has(album.name)) {
|
|
|
|
uniqueAlbums.add(album.name);
|
|
|
|
selectedAlbums.push(album);
|
|
|
|
}
|
|
|
|
});
|
2020-07-23 12:07:29 +00:00
|
|
|
|
2020-07-23 14:23:15 +00:00
|
|
|
return (
|
2020-07-23 12:07:29 +00:00
|
|
|
<Grid
|
2020-07-23 22:12:31 +00:00
|
|
|
as='section'
|
2020-07-23 17:53:47 +00:00
|
|
|
rows={['fit', 'fit']}
|
2020-07-23 22:12:31 +00:00
|
|
|
columns={['fit', '2/3']}
|
2020-07-23 12:07:29 +00:00
|
|
|
gap='small'
|
|
|
|
areas={[
|
2020-07-23 22:12:31 +00:00
|
|
|
['artist-title', 'other-title'],
|
2020-07-23 19:17:31 +00:00
|
|
|
['artist', 'other'],
|
2020-07-23 22:12:31 +00:00
|
|
|
['disco-title', 'disco-title'],
|
2020-07-23 12:07:29 +00:00
|
|
|
['discography', 'discography'],
|
|
|
|
]}
|
2020-07-23 09:43:12 +00:00
|
|
|
>
|
2020-07-23 22:12:31 +00:00
|
|
|
<Heading
|
|
|
|
level='1'
|
|
|
|
gridArea='artist-title'
|
|
|
|
margin={{ vertical: 'none' }}
|
|
|
|
>
|
|
|
|
{selectedName}
|
|
|
|
</Heading>
|
2020-07-23 23:10:57 +00:00
|
|
|
<Grid gridArea='artist' margin={{ bottom: 'medium' }}>
|
2020-07-23 22:12:31 +00:00
|
|
|
<Box
|
|
|
|
round='full'
|
|
|
|
background={{
|
|
|
|
repeat: 'no-repeat',
|
|
|
|
size: 'cover',
|
|
|
|
image: `url(${selectedImage})`,
|
|
|
|
}}
|
|
|
|
height='300px'
|
|
|
|
width='300px'
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
<Heading
|
|
|
|
level='2'
|
|
|
|
gridArea='other-title'
|
|
|
|
margin={{ vertical: 'none' }}
|
|
|
|
alignSelf='end'
|
2020-07-23 23:10:57 +00:00
|
|
|
size='small'
|
2020-07-23 22:12:31 +00:00
|
|
|
>
|
|
|
|
Other results
|
|
|
|
</Heading>
|
|
|
|
<ResponsiveContext.Consumer>
|
|
|
|
{(size) => (
|
|
|
|
<Box gridArea='other' direction='row' wrap>
|
2020-07-24 12:14:16 +00:00
|
|
|
{otherArtists.map((artist) => (
|
2020-07-23 22:12:31 +00:00
|
|
|
<Other
|
|
|
|
key={artist.id}
|
|
|
|
image={artist.image}
|
|
|
|
name={artist.name}
|
2020-07-23 23:10:57 +00:00
|
|
|
handleClick={handleClick}
|
2020-07-23 22:12:31 +00:00
|
|
|
/>
|
|
|
|
))}
|
2020-07-23 17:53:47 +00:00
|
|
|
</Box>
|
2020-07-23 22:12:31 +00:00
|
|
|
)}
|
|
|
|
</ResponsiveContext.Consumer>
|
|
|
|
<Heading level='2' gridArea='disco-title' size='large'>
|
|
|
|
Discography
|
|
|
|
</Heading>
|
2020-07-23 19:17:31 +00:00
|
|
|
<ResponsiveContext.Consumer>
|
|
|
|
{(size) => (
|
|
|
|
<Grid
|
|
|
|
gridArea='discography'
|
|
|
|
align='start'
|
|
|
|
columns={{ count: 'fill', size: '300px' }}
|
2020-07-23 22:12:31 +00:00
|
|
|
gap='large'
|
2020-07-23 19:17:31 +00:00
|
|
|
>
|
|
|
|
{selectedAlbums.map((album) => (
|
|
|
|
<Album
|
|
|
|
key={album.id}
|
|
|
|
image={album.image}
|
|
|
|
name={album.name}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Grid>
|
|
|
|
)}
|
|
|
|
</ResponsiveContext.Consumer>
|
2020-07-23 12:07:29 +00:00
|
|
|
</Grid>
|
2020-07-23 09:43:12 +00:00
|
|
|
);
|
|
|
|
};
|