This commit is contained in:
danis
2023-12-07 20:17:18 +01:00
parent 11ed8f90fd
commit dac9849ef5
2 changed files with 18 additions and 27 deletions

View File

@@ -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);
};

View File

@@ -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>
);
};