From ce9571ec7fd86e4b84db85509f2d3c6730b0363b Mon Sep 17 00:00:00 2001 From: leon-morival Date: Fri, 3 Oct 2025 15:04:53 +0200 Subject: [PATCH] randome hit parade --- src/screens/HitParade/HitParade.js | 65 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/screens/HitParade/HitParade.js b/src/screens/HitParade/HitParade.js index 7ef14ee..7a7c94d 100644 --- a/src/screens/HitParade/HitParade.js +++ b/src/screens/HitParade/HitParade.js @@ -1,4 +1,4 @@ -import React, { useMemo, useState } from "react"; +import React, { useCallback, useMemo, useState } from "react"; import { FlatList, Image, @@ -32,14 +32,6 @@ const HitParade = () => { condition: true, }); - console.log( - "top songs", - JSON.stringify( - topSongs.map((song) => song.userId), - null, - 2 - ) - ); const { data: topPlaybacks } = useDataFromRef({ ref: projectsRef.where("views", ">", 0).orderBy("views", "desc").limit(50), format: (docs) => docs.filter((d) => d?.playbackUrl != null).slice(0, 10), @@ -136,21 +128,21 @@ const HitParade = () => { {songsCol2.length > 0 && ( {songsCol2.map((item, idx) => ( - - navigateToMusicDetails({ - projectId: item.id, - songUrl: item?.songUrl, - }) - } - /> - ))} - + + navigateToMusicDetails({ + projectId: item.id, + songUrl: item?.songUrl, + }) + } + /> + ))} + )} @@ -200,6 +192,21 @@ const HitParade = () => { ); const isWeb = Platform.OS === "web"; + const handlePlayRandomSong = useCallback(() => { + const arr = Array.isArray(topSongs) ? topSongs : []; + + if (!arr.length) { + console.warn("Aucune chanson disponible pour le moment."); + return; + } + + const randomSong = arr[Math.floor(Math.random() * arr.length)]; + + navigateToMusicDetails({ + projectId: randomSong.id, + songUrl: randomSong?.songUrl, + }); + }, [navigateToMusicDetails, topSongs]); return ( { source={icons.hitParadeLogo} style={{ alignSelf: "center" }} /> - + + +