deactivating refetchOnWindowFocus globally and fetching songs from /song

This commit is contained in:
Clément Le Bihan
2023-02-23 23:23:44 +01:00
parent 67a03f196e
commit c00a96a987
2 changed files with 29 additions and 5 deletions
+22 -4
View File
@@ -10,6 +10,7 @@ import Constants from "expo-constants";
import store from "./state/Store";
import { Platform } from "react-native";
import { en } from "./i18n/Translations";
import { useQuery, QueryClient } from "react-query";
type AuthenticationInput = { username: string; password: string };
type RegistrationInput = AuthenticationInput & { email: string };
@@ -195,8 +196,26 @@ export default class API {
return "11111";
}
public static async getAllSongs(): Promise<Song[]> {
let songs = await API.fetch({
route: "/song",
});
// this is a dummy illustration, we will need to fetch the real one from the API
return songs.data.map((song: any) => ({
id: song.id as number,
name: song.name as string,
artistId: song.artistId as number,
albumId: song.albumId as number,
genreId: song.genreId as number,
details: song.difficulties,
cover: getDummyIllustration(),
metrics: {},
} as Song));
}
/**
* Retrive a song
* Retrieve a song
* @param songId the id to find the song
*/
public static async getSong(songId: number): Promise<Song> {
@@ -310,9 +329,8 @@ export default class API {
* Retrieve the authenticated user's recommendations
*/
public static async getUserRecommendations(): Promise<Song[]> {
// we can assume at least 5 songs
// in the future the API will return the songs directly to avoid spamming the API
return Promise.all([1, 2, 3, 4, 5].map(API.getSong));
const queryClient = new QueryClient();
return await queryClient.fetchQuery(["API", "allsongs"], API.getAllSongs);
}
/**
+7 -1
View File
@@ -9,7 +9,13 @@ import { PersistGate } from "redux-persist/integration/react";
import LanguageGate from "./i18n/LanguageGate";
import ThemeProvider, { ColorSchemeProvider } from './Theme';
const queryClient = new QueryClient();
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
},
});
export default function App() {