diff --git a/front/views/GenreDetailsView.tsx b/front/views/GenreDetailsView.tsx index 9d75337..a0ff410 100644 --- a/front/views/GenreDetailsView.tsx +++ b/front/views/GenreDetailsView.tsx @@ -15,10 +15,11 @@ type GenreDetailsViewProps = { const GenreDetailsView = ({ genreId }: RouteProps) => { const genreQuery = useQuery(API.getGenre(genreId)) const songsQuery = useQuery(API.getSongsByGenre(genreId)) - const artistQueries = useQueries(songsQuery.data.map((song) => song.artistId).map((artistId) => API.getArtist(artistId))); - const songWithArtist = songsQuery.data.map((song) => ({ + const artistQueries = useQueries(songsQuery.data?.map((song) => song.artistId).map((artistId) => API.getArtist(artistId)) ?? []); + // Here, .artist will always be defined + const songWithArtist = songsQuery?.data?.map((song) => ({ ...song, - artist: artistQueries.find((query) => query.data.id == song.artistId) + artist: artistQueries.find((query) => query.data?.id == song.artistId)?.data })).filter((song) => song.artist !== undefined); const screenSize = useBreakpointValue({ base: "small", md: "big" }); @@ -29,7 +30,7 @@ const GenreDetailsView = ({ genreId }: RouteProps) => { navigation.navigate('Error'); return <>; } - if (!genreQuery.data || songsQuery.data === undefined) { + if (!genreQuery.data || songsQuery.data === undefined || songWithArtist === undefined) { return ; } @@ -57,7 +58,7 @@ const GenreDetailsView = ({ genreId }: RouteProps) => { content={songWithArtist.map((songData) => ({ name: songData.name, cover: songData.cover, - artistName: songData.artist.name, + artistName: songData.artist!.name, songId: songData.id, onPress: () => { API.createSearchHistoryEntry(songData.name, 'song');