You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
import React, {useEffect, useState} from "react";
|
|
import {FlatList, Text, View} from "react-native";
|
|
import {useSelector} from 'react-redux';
|
|
import ArtistCard from "./ArtistCard";
|
|
import {getLikeArtist} from './../../AsyncStorage/likeArtistStorage'
|
|
|
|
const ArtistList = ({ navigation, type }) => {
|
|
const [artistsList, setArtistsList] = useState([]);
|
|
|
|
const artists = useSelector((state) => {
|
|
if (type === "search") {
|
|
// @ts-ignore
|
|
return state.ReducerArtist.artistsSearch;
|
|
} else if (type === "liked") {
|
|
// @ts-ignore
|
|
return state.ReducerArtist.likedArtists;
|
|
}
|
|
return [];
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (type === "liked") {
|
|
async function fetchLikedArtists() {
|
|
const likedArtists = await getLikeArtist();
|
|
setArtistsList(likedArtists);
|
|
}
|
|
fetchLikedArtists();
|
|
}
|
|
}, [type]);
|
|
|
|
useEffect(() => {
|
|
setArtistsList(artists);
|
|
}, [artists]);
|
|
|
|
if(artistsList == undefined){
|
|
return <Text>Loading...</Text>
|
|
}
|
|
|
|
return (
|
|
<View>
|
|
<FlatList
|
|
data={artistsList}
|
|
renderItem={({ item }) => (
|
|
<ArtistCard key={item.id} navigation={navigation} item={item} />
|
|
)}
|
|
keyExtractor={(item) => item.id}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
export default ArtistList;
|
|
|
|
|