Add tag functionality to posts and implement Tags screen

This commit is contained in:
Adolfo Reyna
2025-02-28 00:21:00 -05:00
parent f5c7ff38dd
commit 8cdcfefa0d
6 changed files with 177 additions and 34 deletions

77
Views/Tags.js Normal file
View File

@@ -0,0 +1,77 @@
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
import { View, ActivityIndicator, StyleSheet, SafeAreaView, FlatList } from 'react-native';
import { Button, IconButton } from 'react-native-paper';
import API from './../API.js';
import Post from './../components/Post.js';
import NewPost from "./../components/NewPost.js";
import ProfileHeader from '../components/ProfileHeader.js';
import AsyncStorage from '@react-native-async-storage/async-storage';
let Tags = ({ navigation, route }) => {
let [Posts, setPosts] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
let subscribed = true;
const getData = async () => {
setPosts([]);
console.log("Posts by tag", route.params.tag);
API.getPostsByTag(route.params.tag).then((data) => {
if(!subscribed) return 0;
console.log("Posts by tag", data);
setPosts(data);
setLoading(false);
});
}
getData();
return ()=>{
subscribed = false;
}
}, [route.params?.tag]);
const renderPost = (({ item }) => {
if (item.nonOrganicType)
return (<></>);
return (<Post post={item} />);
});
const header = (
<View>
</View>
)
return (
<SafeAreaView style={styles.container}>
<View>
{!loading ?
<FlatList
data={Posts}
renderItem={renderPost}
keyExtractor={item => item.lastUpdated || item._id || item.ceatedAt}
ListHeaderComponent={header}
refreshing={loading}
initialNumToRender={3}
maxToRenderPerBatch={3}
removeClippedSubviews={true}
onRefresh={() => {
API.getPostsByTag(route.params.tag).then(setPosts);
}}
/> :
<></> //TODO: Add empty profile card here
}
</View>
<StatusBar style="auto" />
</SafeAreaView>
);
}
export default Tags;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#edf2f7",
},
});