Basic Navigation

This commit is contained in:
aeroreyna
2022-03-06 21:45:35 -08:00
parent b948927e4c
commit 8b1a52a3af
8 changed files with 329 additions and 48 deletions

66
Views/Feed.js Normal file
View File

@@ -0,0 +1,66 @@
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"
},
});