stupid hooks rules
This commit is contained in:
@@ -5,40 +5,42 @@ import { RouteProps, useNavigation } from '../../Navigation';
|
||||
import MusicList from '../../components/UI/MusicList';
|
||||
import { useQuery } from '../../Queries';
|
||||
import API from '../../API';
|
||||
import Song from '../../models/Song';
|
||||
import { MusicItemType } from '../../components/UI/MusicItem';
|
||||
|
||||
export type searchProps = {
|
||||
artist: number | undefined,
|
||||
genre: number | undefined,
|
||||
query: string,
|
||||
}
|
||||
artist: number | undefined;
|
||||
genre: number | undefined;
|
||||
query: string;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
const SearchView = (props: RouteProps<{}>) => {
|
||||
const navigation = useNavigation();
|
||||
const [searchResult, setSearchResult] = React.useState([] as MusicItemType[]);
|
||||
const [searchQuery, setSearchQuery] = React.useState({artist: undefined, genre: undefined, query: ''} as searchProps)
|
||||
const rawResult = useQuery(API.searchSongs(searchQuery), en);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const handleSearch = async (searchQuery: searchProps) => {
|
||||
const rawResult = useQuery(API.getAllSongs());
|
||||
// const rawResult = useQuery(API.searchSongs(searchQuery));
|
||||
setSearchQuery(searchQuery);
|
||||
const result =
|
||||
rawResult.data?.map((song) => ({
|
||||
artist: song.artist!.name,
|
||||
song: song.name,
|
||||
image: song.cover,
|
||||
level: 42,
|
||||
lastScore: 42,
|
||||
bestScore: 42,
|
||||
liked: true,
|
||||
onLike: () => {
|
||||
console.log('onLike');
|
||||
},
|
||||
onPlay: () => navigation.navigate('Play', { songId: song.id }),
|
||||
})) ?? [];
|
||||
rawResult.data?.map((song) => ({
|
||||
artist: song.artist!.name,
|
||||
song: song.name,
|
||||
image: song.cover,
|
||||
level: 42,
|
||||
lastScore: 42,
|
||||
bestScore: 42,
|
||||
liked: true,
|
||||
onLike: () => {
|
||||
console.log('onLike');
|
||||
},
|
||||
onPlay: () => navigation.navigate('Play', { songId: song.id }),
|
||||
})) ?? [];
|
||||
setSearchResult(result ?? []);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<ScaffoldCC routeName={props.route.name}>
|
||||
<SearchBarComponent onValidate={handleSearch} />
|
||||
|
||||
Reference in New Issue
Block a user