diff --git a/front/API.ts b/front/API.ts index 87c2151..a34288d 100644 --- a/front/API.ts +++ b/front/API.ts @@ -498,84 +498,6 @@ export default class API { }; } - /** - * Search a song by its name - * @param query the string used to find the songs - */ - // public static searchSongs(query: string): Query { - // return { - // key: ['search', 'song', query], - // exec: () => - // API.fetch( - // { - // route: `/search/songs/${query}`, - // }, - // { handler: ListHandler(SongHandler) } - // ), - // }; - // } - - /** - * Search artists by name - * @param query the string used to find the artists - */ - public static searchArtists(query: string): Query { - return { - key: ['search', 'artist', query], - exec: () => - API.fetch( - { - route: `/search/artists/${query}`, - }, - { handler: ListHandler(ArtistHandler) } - ), - }; - } - - /** - * Search Album by name - * @param query the string used to find the album - */ - public static searchAlbum(query: string): Query { - return { - key: ['search', 'album', query], - exec: async () => [ - { - id: 1, - name: 'Super Trooper', - }, - { - id: 2, - name: 'Kingdom Heart 365/2 OST', - }, - { - id: 3, - name: 'The Legend Of Zelda Ocarina Of Time OST', - }, - { - id: 4, - name: 'Random Access Memories', - }, - ], - }; - } - - /** - * Retrieve music genres - */ - public static searchGenres(query: string): Query { - return { - key: ['search', 'genre', query], - exec: () => - API.fetch( - { - route: `/search/genres/${query}`, - }, - { handler: ListHandler(GenreHandler) } - ), - }; - } - /** * Retrieve a lesson * @param lessonId the id to find the lesson @@ -782,12 +704,19 @@ export default class API { } public static searchSongs(query: searchProps): Query { + const queryParams: string[] = []; + + if (query.artist) queryParams.push(`artistId=${query.artist}`); + if (query.genre) queryParams.push(`genreId=${query.genre}`); + + const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : ''; + return { key: ['search'], exec: () => { - return API.fetch( - { - route: `/search/songs/${query.query}`, + return API.fetch( + { + route: `/search/songs/${query.query}${queryString}`, }, { handler: ListHandler(SongHandler) } ); diff --git a/front/views/V2/SearchView.tsx b/front/views/V2/SearchView.tsx index 4124492..c5781b7 100644 --- a/front/views/V2/SearchView.tsx +++ b/front/views/V2/SearchView.tsx @@ -1,15 +1,15 @@ import React, { useMemo } from 'react'; -import ScaffoldCC from '../../components/UI/ScaffoldCC'; -import SearchBarComponent from '../../components/V2/SearchBar'; -import { RouteProps, useNavigation } from '../../Navigation'; -import { useQuery } from '../../Queries'; -import API from '../../API'; -import { View, StyleSheet } from 'react-native'; -import SearchHistory from '../../components/V2/SearchHistory'; -import MusicItem from '../../components/UI/MusicItem'; import { FlatList, HStack, useBreakpointValue, useTheme, Text, Row } from 'native-base'; +import { RouteProps, useNavigation } from '../../Navigation'; +import { ArrowRotateLeft, Cup } from 'iconsax-react-native'; +import { View, StyleSheet } from 'react-native'; +import { useQuery } from '../../Queries'; import { translate } from '../../i18n/i18n'; -import { ArrowDown2, ArrowRotateLeft, Cup, Icon } from 'iconsax-react-native'; +import SearchBarComponent from '../../components/V2/SearchBar'; +import SearchHistory from '../../components/V2/SearchHistory'; +import ScaffoldCC from '../../components/UI/ScaffoldCC'; +import MusicItem from '../../components/UI/MusicItem'; +import API from '../../API'; export type searchProps = { artist: number | undefined; @@ -74,22 +74,6 @@ const Oui = ({yes}: {yes: any[]}) => { ); return ( - // - // {yes.map((song) => ( - // { - // console.log('onLike'); - // }} - // onPlay={() => navigation.navigate('Play', { songId: song.id })} - // /> - // ))} - // { data={yes} renderItem={({ item }) => } keyExtractor={(item) => item.artist + item.song} - // ListFooterComponent={ - // musicListState.hasMoreMusics ? ( - // - // {musicListState.loading ? ( - // - // ) : ( - // - // )} - // - // ) : null - // } /> ); } @@ -120,7 +89,7 @@ const Oui = ({yes}: {yes: any[]}) => { const SearchView = (props: RouteProps<{}>) => { const navigation = useNavigation(); const [searchQuery, setSearchQuery] = React.useState({} as searchProps); - const rawResult = useQuery(API.getAllSongs(searchQuery.query)); + const rawResult = useQuery(API.searchSongs(searchQuery)); const result = rawResult.data?.map((song) => ({ artist: song?.artist?.name ?? 'duh', @@ -142,18 +111,10 @@ const SearchView = (props: RouteProps<{}>) => { console.log('raw:' + rawResult); } - const handleClear = () => { - console.log('stage cleared'); - setSearchQuery({} as searchProps); - } - - console.table('result:', result); - console.table('raw:', rawResult); - return ( - handleLog(data)} /> + setSearchQuery(query)} /> {result.length != 0 ? : } @@ -168,12 +129,7 @@ const styles = StyleSheet.create({ gap: 2, borderRadius: 10, overflow: 'hidden', - }, - footerContainer: { - height: 60, - justifyContent: 'center', - alignItems: 'center', - }, + } }); export default SearchView; \ No newline at end of file