-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewsItem.js
125 lines (119 loc) · 3.37 KB
/
NewsItem.js
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { Image, ScrollView, StyleSheet, Text, TouchableOpacity, View } from "react-native";
import React from "react";
import Loader from "./Loader";
import Related from "./Related";
import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome";
import { faArrowLeft } from "@fortawesome/free-solid-svg-icons";
import { useNavigation } from "@react-navigation/native";
export default function NewsItem(props) {
const item = props.route.params.item;
let image = props.route.params.image;
const index = props.route.params.index;
image = image.toString();
const navigation = useNavigation();
const [loading, setLoading] = React.useState(true);
const fetchDetails = async () => {
await fetch(
`https://newsurdu.herokuapp.com/fetch/${props.route.params.id}`,
{
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
}
)
.then((res) => res.json())
.then((data) => {
setDetails(data.details);
setLoading(false);
})
.catch((err) => console.log(err));
};
const [details, setDetails] = React.useState([]);
React.useEffect(() => {
fetchDetails();
}, [item, image]);
console.log(details.details);
return (
<ScrollView
contentContainerStyle={{ flexGrow: 1 }}
showsVerticalScrollIndicator={false}
>
<View style={{ position: "absolute", zIndex: 1, top: 10, left: 10 }}>
<TouchableOpacity onPress={() => navigation.goBack()}>
<FontAwesomeIcon
icon={faArrowLeft}
size={30}
color={"white"}
/>
</TouchableOpacity>
</View>
<View style={styles.item}>
<Image source={{ uri: image }} style={{ width: "100%", height: 300 }} />
<View>
<Text
style={{
paddingHorizontal: 15,
paddingTop: 15,
paddingBottom: 0,
color: "white",
fontSize: 25,
fontWeight: "bold",
textAlign: "right",
}}
>
{item}
</Text>
{loading ? (
<Loader />
) : (
details.map((item, index) => {
return (
<View
key={index}
style={{ paddingHorizontal: 15, paddingVertical: 10 }}
>
<Text
style={{ color: "white", fontSize: 18, textAlign: "right" }}
>
{item}
</Text>
</View>
);
})
)}
<View style={styles.more}>
<Text
style={{
color: "white",
fontSize: 25,
fontWeight: "bold",
paddingBottom: 10,
}}
>
More Like This
</Text>
<Related data={props.route.params.data} />
<Related data={props.route.params.data} />
<Related data={props.route.params.data} />
</View>
</View>
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
item: {
flex: 1,
backgroundColor: "black",
},
more: {
flex: 1,
justifyContent: "flex-start",
alignItems: "flex-start",
paddingTop: 20,
paddingHorizontal: 15,
paddingBottom: 30,
},
});