stupid hooks rules

This commit is contained in:
danis
2023-12-07 20:08:21 +01:00
parent 5d103c6687
commit 11ed8f90fd
4 changed files with 45 additions and 41 deletions
+14 -14
View File
@@ -781,17 +781,17 @@ export default class API {
return `${API.baseUrl}/song/${songId}/assets/partition`;
}
public static searchSongs(query: searchProps): Query<Song[]> {
return {
key: ['search'],
exec: () => {
return API.fetch(
{
route: `/search/songs/`,
},
{ handler: ListHandler(SongHandler) }
)
}
}
}
}
public static searchSongs(query: searchProps): Query<Song[]> {
return {
key: ['search'],
exec: () => {
return API.fetch(
{
route: `/search/songs/${query.query}`,
},
{ handler: ListHandler(SongHandler) }
);
},
};
}
}
+6 -5
View File
@@ -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}
</View>
</ScrollView>
@@ -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);
}}
>
<Select.Item label={translate('emptySelection')} value="" />
{genresQuery.data?.map((data, index) => (
+2 -1
View File
@@ -51,8 +51,9 @@ const SearchView = (props: RouteProps<SearchViewProps>) => {
const [filter, setFilter] = useState<Filter>('all');
const [stringQuery, setStringQuery] = useState<string>(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 }
);
+23 -21
View File
@@ -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} />