67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
import { StatusBar } from 'expo-status-bar';
|
|
import React, { useState, useEffect } from 'react';
|
|
import { View, ScrollView, StyleSheet, SafeAreaView } from 'react-native';
|
|
import API from './../API.js';
|
|
import Post from './../components/Post.js';
|
|
import { Provider as PaperProvider } from 'react-native-paper';
|
|
import AwesomeIcon from 'react-native-vector-icons/FontAwesome';
|
|
|
|
|
|
|
|
let Feed = ({ navigation, route }) => {
|
|
let [Me, setMeProfile] = useState({});
|
|
let [Posts, setPosts] = useState([]);
|
|
useEffect(async () => {
|
|
navigation.setOptions({ title: "Loading..." });
|
|
let r = await API.getMe();
|
|
setMeProfile(r);
|
|
if (route.params && route.params.profileid) {
|
|
setPosts([]);
|
|
API.getPosts(route.params.profileid).then((data) => {
|
|
API.getUserProfile(route.params.profileid).then((profile)=>{
|
|
navigation.setOptions({ title: profile.profile.firstName + " " + profile.profile.lastName });
|
|
});
|
|
setPosts(data);
|
|
});
|
|
} else {
|
|
let posts = await API.getPosts();
|
|
setPosts(posts);
|
|
navigation.setOptions({ title: "Feed" });
|
|
}
|
|
//console.log(posts)
|
|
}, [route.params]);
|
|
|
|
return (
|
|
<PaperProvider settings={{
|
|
icon: props => <AwesomeIcon {...props} />,
|
|
}}>
|
|
<SafeAreaView style={styles.container}>
|
|
<View>
|
|
<ScrollView>
|
|
{
|
|
Posts.map((post, i) => {
|
|
return (
|
|
//<Text key={i}>{post.content}</Text>
|
|
<Post post={post} viewer={Me} key={i} />
|
|
)
|
|
})
|
|
}
|
|
</ScrollView>
|
|
</View>
|
|
<StatusBar style="auto" />
|
|
</SafeAreaView>
|
|
</PaperProvider>
|
|
);
|
|
}
|
|
|
|
export default Feed;
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
backgroundColor: "#edf2f7"
|
|
},
|
|
});
|