feat: top du mois

This commit is contained in:
2026-01-13 16:43:57 +01:00
parent 01888f2c52
commit c36cc5f020
2 changed files with 799 additions and 280 deletions
+781 -254
View File
File diff suppressed because it is too large Load Diff
+18 -26
View File
@@ -49,35 +49,27 @@ const HitParade = () => {
const [selectedCategory, setSelectedCategory] = useState('Chansons') const [selectedCategory, setSelectedCategory] = useState('Chansons')
const navigateToMusicDetails = useNavigateToMusicDetails() const navigateToMusicDetails = useNavigateToMusicDetails()
const { data: allSongs } = useDataFromRef({ const { data: allSongs } = useDataFromRef({
ref: projectsRef.orderBy('updatedAt', 'desc'), ref: projectsRef.where('hasSong', '==', true),
format: (docs) => docs.filter((item) => item?.hasPlayback !== true), format: (docs) => docs.filter((item) => item?.hasPlayback !== true),
simpleRef: false, simpleRef: false,
listener: true, listener: true,
condition: true, condition: true,
}) })
const previousMonthKey = useMemo(() => { const { data: topMonthSongs } = useDataFromRef({
const now = new Date() ref: projectsRef.where('monthViews', '>', 0).orderBy('monthViews', 'desc').limit(20),
const target = new Date(now.getFullYear(), now.getMonth(), 1) format: (docs) => docs.filter((item) => item?.hasPlayback !== true),
target.setMonth(target.getMonth() - 1) simpleRef: false,
const month = String(target.getMonth() + 1).padStart(2, '0')
return `${target.getFullYear()}-${month}`
}, [])
const { data: monthlyTopDoc } = useDataFromRef({
ref: firebase.firestore().collection('monthlyTopSongs').doc(previousMonthKey),
initialState: null,
simpleRef: true,
listener: false, listener: false,
condition: true, condition: true,
}) })
const songsList = useMemo(() => (Array.isArray(allSongs) ? allSongs : []), [allSongs]) const songsList = useMemo(() => (Array.isArray(allSongs) ? allSongs : []), [allSongs])
const topMonthList = useMemo(() => { const topMonthList = useMemo(
const items = monthlyTopDoc?.topProjects () => (Array.isArray(topMonthSongs) ? topMonthSongs : []),
return Array.isArray(items) ? items : [] [topMonthSongs]
}, [monthlyTopDoc]) )
// === RENDUS PAR PLATEFORME === // === RENDUS PAR PLATEFORME ===
const renderSongsMobile = () => ( const renderSongsMobile = () => (
@@ -114,17 +106,17 @@ const HitParade = () => {
paddingBottom: responsiveHeight(20), paddingBottom: responsiveHeight(20),
}} }}
data={topMonthList} data={topMonthList}
keyExtractor={(item) => item.projectId} keyExtractor={(item) => item.id}
renderItem={({ item }) => ( renderItem={({ item, index }) => (
<SongCard <SongCard
rank={item?.rank} rank={index + 1}
title={item?.title || 'Sans titre'} title={item?.title || 'Sans titre'}
artist={item?.userName} artist={item?.userName}
coverUrl={item?.coverUrl || null} coverUrl={item?.coverUrl || null}
subscriptionLevel={getCreatorLevel(item)} subscriptionLevel={getCreatorLevel(item)}
onPress={() => onPress={() =>
navigateToMusicDetails({ navigateToMusicDetails({
projectId: item?.projectId, projectId: item?.id,
songUrl: item?.songUrl, songUrl: item?.songUrl,
}) })
} }
@@ -157,17 +149,17 @@ const HitParade = () => {
const renderTopMonthColumns = () => ( const renderTopMonthColumns = () => (
<View style={{ gap: 10 }}> <View style={{ gap: 10 }}>
{topMonthList.map((item) => ( {topMonthList.map((item, index) => (
<SongCard <SongCard
key={item.projectId} key={item.id}
rank={item?.rank} rank={index + 1}
title={item?.title || 'Sans titre'} title={item?.title || 'Sans titre'}
artist={item?.userName} artist={item?.userName}
coverUrl={item?.coverUrl || null} coverUrl={item?.coverUrl || null}
subscriptionLevel={getCreatorLevel(item)} subscriptionLevel={getCreatorLevel(item)}
onPress={() => onPress={() =>
navigateToMusicDetails({ navigateToMusicDetails({
projectId: item?.projectId, projectId: item?.id,
songUrl: item?.songUrl, songUrl: item?.songUrl,
}) })
} }
@@ -360,7 +352,7 @@ const HitParade = () => {
? 'Coups de coeur des utilisateurs' ? 'Coups de coeur des utilisateurs'
: `Coups de coeur des utilisateurs catégorie ${selectedCategory}` : `Coups de coeur des utilisateurs catégorie ${selectedCategory}`
const heroSubtitle = 'Les 3 musiques les plus likées du mois reçoivent des tokens.' const heroSubtitle = 'Les 3 musiques les plus écoutées du mois reçoivent des tokens.'
const renderHero = () => ( const renderHero = () => (
<View style={{ gap: 11, maxWidth: 800, width: '100%', alignSelf: 'center' }}> <View style={{ gap: 11, maxWidth: 800, width: '100%', alignSelf: 'center' }}>