From 9150817c05f3b9de09a0c46f58ae5c3ab8884c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 15 Jan 2024 01:48:52 +0100 Subject: [PATCH] Removed custom keyextractor of flatlist in musicList due to weird behaviours and still using special icon button for web --- front/components/UI/MusicItem.tsx | 66 ++++++++++++++++++++----------- front/components/UI/MusicList.tsx | 12 +----- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/front/components/UI/MusicItem.tsx b/front/components/UI/MusicItem.tsx index ef24c1f..9b15b8d 100644 --- a/front/components/UI/MusicItem.tsx +++ b/front/components/UI/MusicItem.tsx @@ -1,6 +1,6 @@ /* eslint-disable react/prop-types */ import React, { useMemo, memo } from 'react'; -import { StyleSheet, ViewStyle, Image } from 'react-native'; +import { StyleSheet, ViewStyle, Image, Platform } from 'react-native'; import { Column, HStack, @@ -12,7 +12,7 @@ import { IconButton, } from 'native-base'; import { HeartAdd, HeartRemove, Play } from 'iconsax-react-native'; -// import IconButton from './IconButton'; +import WebIconButton from './IconButton'; import Spacer from '../../components/UI/Spacer'; import { useTranslation } from 'react-i18next'; @@ -167,28 +167,48 @@ function MusicItemComponent(props: MusicItemType) { {screenSize === 'xl' && } - {props.song} - - ) : ( - - ) - } - onPress={() => { - props.onLike(!props.liked); + + > + {props.song} + + {Platform.OS === 'web' ? ( + + ) : ( + + ) : ( + + ) + } + onPress={() => { + props.onLike(!props.liked); + }} + /> + )} {[formattedLastScore, formattedBestScore].map((value, index) => ( diff --git a/front/components/UI/MusicList.tsx b/front/components/UI/MusicList.tsx index 768a41b..8f47c02 100644 --- a/front/components/UI/MusicList.tsx +++ b/front/components/UI/MusicList.tsx @@ -107,9 +107,6 @@ function MusicListCC({ const { mutateAsync } = useLikeSongMutation(); const navigation = useNavigation(); const { colors } = useTheme(); - // since we can not easily extract a unique key for each - // item because there is multiple time the same song played - const musicItemTracker = useRef>(new Map()); if (!musics) { return ; @@ -136,14 +133,7 @@ function MusicListCC({ /> )} keyExtractor={(item) => { - if (!musicItemTracker.current.has(item.id)) { - musicItemTracker.current.set(item.id, 0); - } - const count = musicItemTracker.current.get(item.id)!; - musicItemTracker.current.set(item.id, count + 1); - // this is fine because the musics are - // always returned in the same order of play - return `${item.id}-${count}`; + return `${item.id}`; }} ListFooterComponent={ hasMore ? (