liked handled properly
This commit is contained in:
@@ -156,6 +156,7 @@ const SearchBarComponent = (props: { onValidate: (searchData: searchProps) => vo
|
|||||||
key={index}
|
key={index}
|
||||||
name={artist.name}
|
name={artist.name}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
|
props.onValidate({artist: artist.id, genre: genresQuery.data?.find((g) => g.name === genre)?.id ?? undefined, query: query})
|
||||||
setArtist(artist.name);
|
setArtist(artist.name);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import API from '../../API';
|
|||||||
import { useMutation } from 'react-query';
|
import { useMutation } from 'react-query';
|
||||||
import LoadingComponent from '../../components/Loading';
|
import LoadingComponent from '../../components/Loading';
|
||||||
import ErrorView from '../ErrorView';
|
import ErrorView from '../ErrorView';
|
||||||
|
import { useLikeSongMutation } from '../../utils/likeSongMutation';
|
||||||
|
|
||||||
export type searchProps = {
|
export type searchProps = {
|
||||||
artist: number | undefined;
|
artist: number | undefined;
|
||||||
@@ -96,15 +97,12 @@ const SearchView = (props: RouteProps<{}>) => {
|
|||||||
const [searchQuery, setSearchQuery] = React.useState({} as searchProps);
|
const [searchQuery, setSearchQuery] = React.useState({} as searchProps);
|
||||||
const rawResult = useQuery(API.searchSongs(searchQuery));
|
const rawResult = useQuery(API.searchSongs(searchQuery));
|
||||||
const userQuery = useQuery(API.getUserInfo());
|
const userQuery = useQuery(API.getUserInfo());
|
||||||
let result: any[] = [];
|
const likedSongs = useQuery(API.getLikedSongs());
|
||||||
|
const { mutateAsync } = useLikeSongMutation();
|
||||||
|
|
||||||
const { mutate } = useMutation((songId: number) => API.addLikedSong(songId), {
|
let result: any[] = [];;
|
||||||
onSuccess: () => {
|
|
||||||
rawResult.refetch();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (userQuery.isLoading) {
|
if (userQuery.isLoading || likedSongs.isLoading || userQuery.isLoading) {
|
||||||
return <LoadingComponent />;
|
return <LoadingComponent />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,11 +121,10 @@ const SearchView = (props: RouteProps<{}>) => {
|
|||||||
level: song?.difficulties.chordcomplexity,
|
level: song?.difficulties.chordcomplexity,
|
||||||
lastScore: song?.lastScore,
|
lastScore: song?.lastScore,
|
||||||
bestScore: song?.bestScore,
|
bestScore: song?.bestScore,
|
||||||
liked:
|
liked: likedSongs.data?.some(x => x.songId === song.id) ?? false,
|
||||||
song?.likedByUsers?.some((user) => user.userId === userQuery.data.id) ?? false,
|
|
||||||
onLike: () => {
|
onLike: () => {
|
||||||
mutate(song.id);
|
mutateAsync({ songId: song.id, like: false }).then(() => likedSongs.refetch());
|
||||||
},
|
},
|
||||||
onPlay: () => navigation.navigate('Play', { songId: song.id }),
|
onPlay: () => navigation.navigate('Play', { songId: song.id }),
|
||||||
})) ?? [];
|
})) ?? [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user