Removed custom keyextractor of flatlist in musicList due to weird behaviours and still using special icon button for web
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable react/prop-types */
|
/* eslint-disable react/prop-types */
|
||||||
import React, { useMemo, memo } from 'react';
|
import React, { useMemo, memo } from 'react';
|
||||||
import { StyleSheet, ViewStyle, Image } from 'react-native';
|
import { StyleSheet, ViewStyle, Image, Platform } from 'react-native';
|
||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
HStack,
|
HStack,
|
||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
} from 'native-base';
|
} from 'native-base';
|
||||||
import { HeartAdd, HeartRemove, Play } from 'iconsax-react-native';
|
import { HeartAdd, HeartRemove, Play } from 'iconsax-react-native';
|
||||||
// import IconButton from './IconButton';
|
import WebIconButton from './IconButton';
|
||||||
import Spacer from '../../components/UI/Spacer';
|
import Spacer from '../../components/UI/Spacer';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
@@ -167,28 +167,48 @@ function MusicItemComponent(props: MusicItemType) {
|
|||||||
</Text>
|
</Text>
|
||||||
{screenSize === 'xl' && <Spacer height="xs" />}
|
{screenSize === 'xl' && <Spacer height="xs" />}
|
||||||
<Row style={styles.songContainer}>
|
<Row style={styles.songContainer}>
|
||||||
<Text isTruncated numberOfLines={1} style={{
|
<Text
|
||||||
flexShrink: 1,
|
isTruncated
|
||||||
}}>{props.song}</Text>
|
numberOfLines={1}
|
||||||
<IconButton
|
style={{
|
||||||
icon={
|
flexShrink: 1,
|
||||||
props.liked ? (
|
|
||||||
<HeartRemove
|
|
||||||
size={screenSize === 'xl' ? 24 : 18}
|
|
||||||
color={colors.primary[700]}
|
|
||||||
variant="Bold"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<HeartAdd
|
|
||||||
size={screenSize === 'xl' ? 24 : 18}
|
|
||||||
color={colors.primary[300]}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
onPress={() => {
|
|
||||||
props.onLike(!props.liked);
|
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
|
{props.song}
|
||||||
|
</Text>
|
||||||
|
{Platform.OS === 'web' ? (
|
||||||
|
<WebIconButton
|
||||||
|
colorActive={colors.text[700]}
|
||||||
|
color={colors.primary[300]}
|
||||||
|
icon={HeartAdd}
|
||||||
|
iconActive={HeartRemove}
|
||||||
|
activeVariant="Bold"
|
||||||
|
size={screenSize === 'xl' ? 24 : 18}
|
||||||
|
isActive={props.liked}
|
||||||
|
onPress={props.onLike}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<IconButton
|
||||||
|
variant={'unstyled'}
|
||||||
|
icon={
|
||||||
|
props.liked ? (
|
||||||
|
<HeartRemove
|
||||||
|
size={screenSize === 'xl' ? 24 : 18}
|
||||||
|
color={colors.primary[700]}
|
||||||
|
variant="Bold"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<HeartAdd
|
||||||
|
size={screenSize === 'xl' ? 24 : 18}
|
||||||
|
color={colors.primary[300]}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onPress={() => {
|
||||||
|
props.onLike(!props.liked);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
</Column>
|
</Column>
|
||||||
{[formattedLastScore, formattedBestScore].map((value, index) => (
|
{[formattedLastScore, formattedBestScore].map((value, index) => (
|
||||||
|
|||||||
@@ -107,9 +107,6 @@ function MusicListCC({
|
|||||||
const { mutateAsync } = useLikeSongMutation();
|
const { mutateAsync } = useLikeSongMutation();
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
const { colors } = useTheme();
|
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<Map<number, number>>(new Map());
|
|
||||||
|
|
||||||
if (!musics) {
|
if (!musics) {
|
||||||
return <LoadingView />;
|
return <LoadingView />;
|
||||||
@@ -136,14 +133,7 @@ function MusicListCC({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
keyExtractor={(item) => {
|
keyExtractor={(item) => {
|
||||||
if (!musicItemTracker.current.has(item.id)) {
|
return `${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}`;
|
|
||||||
}}
|
}}
|
||||||
ListFooterComponent={
|
ListFooterComponent={
|
||||||
hasMore ? (
|
hasMore ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user