bug fix
This commit is contained in:
@@ -50,14 +50,12 @@ const SearchBarComponent = (props: { onValidate: (searchData: searchProps) => vo
|
||||
const isMobileView = screenSize == 'small';
|
||||
|
||||
const handleValidate = () => {
|
||||
// Construct an object with the data you want to pass to the parent component
|
||||
const searchData = {
|
||||
query: query,
|
||||
artist: artistsQuery.data?.find((a) => a.name === artist)?.id ?? undefined,
|
||||
genre: genresQuery.data?.find((g) => g.name === genre)?.id ?? undefined,
|
||||
};
|
||||
|
||||
// Call the parent's onValidate callback with the searchData
|
||||
props.onValidate(searchData);
|
||||
};
|
||||
|
||||
|
||||
@@ -16,35 +16,28 @@ export type searchProps = {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
const SearchView = (props: RouteProps<{}>) => {
|
||||
const navigation = useNavigation();
|
||||
const [searchResult, setSearchResult] = React.useState([] as MusicItemType[]);
|
||||
// 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.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 }),
|
||||
})) ?? [];
|
||||
setSearchResult(result ?? []);
|
||||
};
|
||||
const rawResult = useQuery(API.searchSongs(searchQuery), { enabled: !!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 }),
|
||||
})) ?? [];
|
||||
|
||||
return (
|
||||
<ScaffoldCC routeName={props.route.name}>
|
||||
<SearchBarComponent onValidate={handleSearch} />
|
||||
<MusicList initialMusics={searchResult} />
|
||||
<SearchBarComponent onValidate={setSearchQuery} />
|
||||
<MusicList initialMusics={result} />
|
||||
</ScaffoldCC>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user