[FIX] MusicList, MusicItem, IconButton: Prevent double-add on consecutive likes
Fixes the issue where consecutive likes on a track mistakenly added it twice to the liked list. Now ensures correct toggling between like and unlike.
This commit is contained in:
committed by
Clément Le Bihan
parent
a103666caf
commit
5ef3885f72
@@ -30,7 +30,7 @@ type IconButtonProps = {
|
||||
/**
|
||||
* Callback function triggered when the button is pressed.
|
||||
*/
|
||||
onPress?: () => void | Promise<void>;
|
||||
onPress?: (state: boolean) => void | Promise<void>;
|
||||
|
||||
/**
|
||||
* Size of the icon.
|
||||
@@ -183,7 +183,7 @@ const IconButton: React.FC<IconButtonProps> = ({
|
||||
const toggleState = async () => {
|
||||
// Execute onPress if provided.
|
||||
if (onPress) {
|
||||
await onPress();
|
||||
await onPress(!isActiveState);
|
||||
}
|
||||
|
||||
// Toggle isActiveState.
|
||||
|
||||
@@ -33,7 +33,7 @@ export interface MusicItemType {
|
||||
style?: ViewStyle | ViewStyle[];
|
||||
|
||||
/** Callback function triggered when the like button is pressed. */
|
||||
onLike: () => void;
|
||||
onLike: (state: boolean) => void;
|
||||
|
||||
/** Callback function triggered when the song is played. */
|
||||
onPlay: () => void;
|
||||
|
||||
@@ -237,8 +237,6 @@ const styles = StyleSheet.create({
|
||||
// Using `memo` to optimize rendering performance by memorizing the component's output.
|
||||
// This ensures that the component only re-renders when its props change.
|
||||
const MusicList = memo(MusicListComponent, (prev, next) => {
|
||||
console.log('AAAAA');
|
||||
console.log(prev.initialMusics, next.initialMusics);
|
||||
return prev.initialMusics.length == next.initialMusics.length;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user