-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFavActorList.js
More file actions
108 lines (104 loc) · 3.18 KB
/
FavActorList.js
File metadata and controls
108 lines (104 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// App.js
import React, { useEffect, useState, useCallback } from "react";
import {
View,
Text,
StyleSheet,
FlatList,
Image,
TouchableOpacity,
} from "react-native";
import { fetchActor } from "./Database";
import { useFocusEffect, useNavigation } from "@react-navigation/native";
import PersonProfileStack from "./PersonProfile";
import { createStackNavigator } from "@react-navigation/stack";
const Stack = createStackNavigator();
const FavActorStack = () => {
return (
<Stack.Navigator>
<Stack.Screen
name="FavActor"
component={FavActorList}
options={{
headerTitle: "Favorite Actors",
headerTitleAlign: "center",
headerTintColor: "#14b8a6",
headerStyle: { backgroundColor: "#5b21b6" },
}}
/>
{/* <Stack.Screen
name="FavActorProfile"
component={PersonProfileStack}
options={{ headerShown: false }}
/> */}
</Stack.Navigator>
);
};
const FavActorList = () => {
const navigation = useNavigation();
const [localActorList, setLocalActorList] = useState([]);
const fetchActorsFromDatabase = async () => {
try {
const actorsListFromDB = await fetchActor();
setLocalActorList(actorsListFromDB);
console.log("fetched actor: ", actorsListFromDB);
} catch (error) {
console.log("Error fetching actors list:", error);
}
};
useFocusEffect(
useCallback(() => {
fetchActorsFromDatabase();
}, [])
);
return localActorList && localActorList.length > 0 ? (
<FlatList
style={{ backgroundColor: "#14b8a6" }}
data={localActorList}
renderItem={({ item }) => {
return (
<TouchableOpacity
className="flex flex-row justify-start h-40 p-px bg-teal-500 border-2 border-blue-800"
onPress={() => {
navigation.navigate("FavActorProfile", {
person_id: item.actorId,
header: item.name,
origin: "myactor",
});
}}
>
<View className="w-fit">
{item.profileImageUrl && item.profileImageUrl.length > 0 ? (
<Image
source={{
uri: `https://image.tmdb.org/t/p/w185/${item.profileImageUrl}`,
}}
className="w-24 h-full mr-1 rounded-lg"
/>
) : (
<Image
source={require("./assets/blank.png")}
className="w-24 h-full mr-1 rounded-lg"
/>
)}
</View>
<View className="flex items-start justify-center w-[71%] ">
<Text className="text-lg font-bold text-[#0d253f]">
{item.name}
</Text>
</View>
</TouchableOpacity>
);
}}
keyExtractor={(item) => item.id}
/>
) : (
<View className="flex items-center justify-center w-full h-full bg-teal-500">
<Text className="text-2xl font-bold text-center text-blue-800">
Looks like you have not set any actor as your favorites yet. Like some
people to see changes!
</Text>
</View>
);
};
export default FavActorStack;