import React from 'react'; import { Box, Grid, ResponsiveContext, Heading } from 'grommet'; import { Album } from './Album'; import { Artists, Albums } from '../interfaces'; import { Other } from './Other'; import placeholder from '../assets/placeholder-music.jpg'; export const Results = ({ artists, handleClick, }: { artists: Artists; handleClick: (name: string) => void; }) => { const { name: selectedName, image, albums } = artists[0]; const otherArtists = artists.slice(1, artists.length); let selectedAlbums: Albums = []; let selectedImage: string = image; // Load placeholder image if none provided if (!image) { selectedImage = placeholder; } // 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 ( {selectedName} Other results {(size) => ( {otherArtists.map((artist) => ( ))} )} Discography {(size) => ( {selectedAlbums.map((album) => ( ))} )} ); };