like state

This commit is contained in:
Amaury Danis Cousandier
2024-01-12 09:19:06 +01:00
parent 29a9ffce74
commit 3f0d0d523b

View File

@@ -111,7 +111,10 @@ const SearchView = (props: RouteProps<{}>) => {
if (userQuery.isSuccess) {
result =
rawResult.data?.map((song) => ({
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',
@@ -120,12 +123,15 @@ const SearchView = (props: RouteProps<{}>) => {
level: song?.difficulties.chordcomplexity,
lastScore: song?.lastScore,
bestScore: song?.bestScore,
liked: likedSongs.data?.some((x) => x.songId == song.id) ?? false,
liked: isLiked,
onLike: () => {
mutateAsync({ songId: song.id, like: false }).then(() => likedSongs.refetch());
mutateAsync({ songId: song.id, like: !isLiked }).then(() =>
likedSongs.refetch()
);
},
onPlay: () => navigation.navigate('Play', { songId: song.id }),
})) ?? [];
};
}) ?? [];
}
return (