Add basic album duplicate filtering
This commit is contained in:
parent
a27a6281a0
commit
cfc628fa59
@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { Box, Grid, ResponsiveContext, Heading } from 'grommet';
|
import { Box, Grid, ResponsiveContext, Heading } from 'grommet';
|
||||||
|
|
||||||
import { Album } from './Album';
|
import { Album } from './Album';
|
||||||
import { Artists } from '../interfaces';
|
import { Artists, Albums } from '../interfaces';
|
||||||
import { Other } from './Other';
|
import { Other } from './Other';
|
||||||
|
|
||||||
export const Results = ({
|
export const Results = ({
|
||||||
@ -15,8 +15,20 @@ export const Results = ({
|
|||||||
const {
|
const {
|
||||||
name: selectedName,
|
name: selectedName,
|
||||||
image: selectedImage,
|
image: selectedImage,
|
||||||
albums: selectedAlbums,
|
albums,
|
||||||
} = artists[0];
|
} = artists[0];
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid
|
<Grid
|
||||||
@ -62,7 +74,7 @@ export const Results = ({
|
|||||||
<ResponsiveContext.Consumer>
|
<ResponsiveContext.Consumer>
|
||||||
{(size) => (
|
{(size) => (
|
||||||
<Box gridArea='other' direction='row' wrap>
|
<Box gridArea='other' direction='row' wrap>
|
||||||
{artists.slice(1, artists.length).map((artist) => (
|
{otherArtists.map((artist) => (
|
||||||
<Other
|
<Other
|
||||||
key={artist.id}
|
key={artist.id}
|
||||||
image={artist.image}
|
image={artist.image}
|
||||||
|
@ -12,3 +12,4 @@ export interface Artist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type Artists = Artist[];
|
export type Artists = Artist[];
|
||||||
|
export type Albums = Album[];
|
||||||
|
Loading…
Reference in New Issue
Block a user