TabBar Navigator and Proper adding posts and comments

This commit is contained in:
aeroreyna
2022-03-08 20:20:17 -08:00
parent 983ac258b3
commit 82e0ded56c
8 changed files with 121 additions and 47 deletions

View File

@@ -1,10 +1,9 @@
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
import { View, ScrollView, StyleSheet, SafeAreaView } from 'react-native';
import { View, ActivityIndicator, StyleSheet, SafeAreaView, FlatList } 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';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import NewPost from "./../components/NewPost.js";
@@ -18,9 +17,7 @@ let Feed = ({ navigation, route }) => {
let r = await API.getMe();
setMeProfile(r);
if (route.params && route.params.profileid) {
API.getPosts(route.params.profileid).then((data) => {
setPosts(data);
});
navigation.navigate('Profile', {profileid: route.params.profileid})
} else {
let posts = await API.getPosts();
setPosts(posts);
@@ -28,6 +25,10 @@ let Feed = ({ navigation, route }) => {
}
//console.log(posts)
}, [route.params]);
const renderPost = (({ item }) => {
return (<Post post={item} viewer={Me} />);
});
return (
<PaperProvider settings={{
@@ -35,17 +36,13 @@ let Feed = ({ navigation, route }) => {
}}>
<SafeAreaView style={styles.container}>
<View>
<ScrollView>
<NewPost />
{
Posts.map((post, i) => {
return (
//<Text key={i}>{post.content}</Text>
<Post post={post} viewer={Me} key={i} />
)
})
}
</ScrollView>
{Posts.length === 0 && <ActivityIndicator />}
<FlatList
data={Posts}
renderItem={renderPost}
keyExtractor={item => item._id || item.createdAt}
ListHeaderComponent={<NewPost newPostCB={(newPost) => setPosts([newPost, ...Posts])} />}
/>
</View>
<StatusBar style="auto" />
</SafeAreaView>