From 3f0d0d523be2b48c428ec350f657036ba6ad2f93 Mon Sep 17 00:00:00 2001 From: Amaury Danis Cousandier Date: Fri, 12 Jan 2024 09:19:06 +0100 Subject: [PATCH] like state --- front/views/V2/SearchView.tsx | 36 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/front/views/V2/SearchView.tsx b/front/views/V2/SearchView.tsx index 0171e8e..380bd36 100644 --- a/front/views/V2/SearchView.tsx +++ b/front/views/V2/SearchView.tsx @@ -111,21 +111,27 @@ const SearchView = (props: RouteProps<{}>) => { if (userQuery.isSuccess) { result = - rawResult.data?.map((song) => ({ - artist: - artistsQuery.data?.find((artist) => artist.id == song?.artist?.id)?.name ?? - 'unknown artist', - song: song?.name, - image: song?.cover, - level: song?.difficulties.chordcomplexity, - lastScore: song?.lastScore, - bestScore: song?.bestScore, - liked: likedSongs.data?.some((x) => x.songId == song.id) ?? false, - onLike: () => { - mutateAsync({ songId: song.id, like: false }).then(() => likedSongs.refetch()); - }, - onPlay: () => navigation.navigate('Play', { songId: song.id }), - })) ?? []; + rawResult.data?.map((song) => { + const isLiked = likedSongs.data?.some((x) => x.songId == song.id) ?? false; + + return { + artist: + artistsQuery.data?.find((artist) => artist.id == song?.artist?.id)?.name ?? + 'unknown artist', + song: song?.name, + image: song?.cover, + level: song?.difficulties.chordcomplexity, + lastScore: song?.lastScore, + bestScore: song?.bestScore, + liked: isLiked, + onLike: () => { + mutateAsync({ songId: song.id, like: !isLiked }).then(() => + likedSongs.refetch() + ); + }, + onPlay: () => navigation.navigate('Play', { songId: song.id }), + }; + }) ?? []; } return (