From 11ed8f90fd270326893c80aa00f78bbe6dc55c7b Mon Sep 17 00:00:00 2001 From: danis Date: Thu, 7 Dec 2023 20:08:21 +0100 Subject: [PATCH] stupid hooks rules --- front/API.ts | 28 ++++++++++---------- front/components/V2/SearchBar.tsx | 11 ++++---- front/views/SearchView.tsx | 3 ++- front/views/V2/SearchView.tsx | 44 ++++++++++++++++--------------- 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/front/API.ts b/front/API.ts index 5df79e8..74a7f2d 100644 --- a/front/API.ts +++ b/front/API.ts @@ -781,17 +781,17 @@ export default class API { return `${API.baseUrl}/song/${songId}/assets/partition`; } - public static searchSongs(query: searchProps): Query { - return { - key: ['search'], - exec: () => { - return API.fetch( - { - route: `/search/songs/`, - }, - { handler: ListHandler(SongHandler) } - ) - } - } - } -} \ No newline at end of file + public static searchSongs(query: searchProps): Query { + return { + key: ['search'], + exec: () => { + return API.fetch( + { + route: `/search/songs/${query.query}`, + }, + { handler: ListHandler(SongHandler) } + ); + }, + }; + } +} diff --git a/front/components/V2/SearchBar.tsx b/front/components/V2/SearchBar.tsx index 8de5b62..63116b2 100644 --- a/front/components/V2/SearchBar.tsx +++ b/front/components/V2/SearchBar.tsx @@ -6,7 +6,6 @@ import ButtonBase from '../UI/ButtonBase'; import { AddSquare, CloseCircle, SearchNormal1 } from 'iconsax-react-native'; import { useQuery } from '../../Queries'; import API from '../../API'; -import Genre from '../../models/Genre'; import { translate } from '../../i18n/i18n'; import { searchProps } from '../../views/V2/SearchView'; @@ -57,7 +56,7 @@ const SearchBarComponent = (props: { onValidate: (searchData: searchProps) => vo 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); }; @@ -162,8 +161,8 @@ const SearchBarComponent = (props: { onValidate: (searchData: searchProps) => vo onPress={() => { setArtist(artist.name); }} - /> - )) + />// eslint-disable-next-line no-mixed-spaces-and-tabs + )) : null} @@ -172,7 +171,9 @@ const SearchBarComponent = (props: { onValidate: (searchData: searchProps) => vo selectedValue={genre} placeholder={translate('genreFilter')} accessibilityLabel="Genre" - onValueChange={(itemValue) => {setGenre(itemValue)}} + onValueChange={(itemValue) => { + setGenre(itemValue); + }} > {genresQuery.data?.map((data, index) => ( diff --git a/front/views/SearchView.tsx b/front/views/SearchView.tsx index 3af01fc..a06a9c8 100644 --- a/front/views/SearchView.tsx +++ b/front/views/SearchView.tsx @@ -51,8 +51,9 @@ const SearchView = (props: RouteProps) => { const [filter, setFilter] = useState('all'); const [stringQuery, setStringQuery] = useState(props?.query ?? ''); + //flemme de corriger de toute facon c'est déprecié et bientot remplacé const { isLoading: isLoadingSong, data: songData = [] } = useQuery( - API.searchSongs(stringQuery), + API.searchSongs({ artist: undefined, genre: undefined, query: 'zeruigze' }), { enabled: !!stringQuery } ); diff --git a/front/views/V2/SearchView.tsx b/front/views/V2/SearchView.tsx index 965addc..e958316 100644 --- a/front/views/V2/SearchView.tsx +++ b/front/views/V2/SearchView.tsx @@ -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 (