From eee51ffdddf75fcc355e2cd0b6e2ef0e546ee5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 23 Feb 2023 23:42:53 +0100 Subject: [PATCH] Using a random subset of all songs in searchHistory and PlayHistory --- front/API.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/front/API.ts b/front/API.ts index ec7a4d4..fcb35eb 100644 --- a/front/API.ts +++ b/front/API.ts @@ -322,7 +322,11 @@ export default class API { * @param lessonId the id to find the lesson */ public static async getSearchHistory(): Promise { - return Promise.all([1, 2].map(API.getSong)); + const queryClient = new QueryClient(); + let songs = await queryClient.fetchQuery(["API", "allsongs"], API.getAllSongs); + const shuffled = [...songs].sort(() => 0.5 - Math.random()); + + return shuffled.slice(0, 2); } /** @@ -337,7 +341,11 @@ export default class API { * Retrieve the authenticated user's play history */ public static async getUserPlayHistory(): Promise { - return Promise.all([3, 4].map(API.getSong)); + const queryClient = new QueryClient(); + let songs = await queryClient.fetchQuery(["API", "allsongs"], API.getAllSongs); + const shuffled = [...songs].sort(() => 0.5 - Math.random()); + + return shuffled.slice(0, 3); } /**