diff --git a/API.js b/API.js index fef0523..d0e136b 100644 --- a/API.js +++ b/API.js @@ -143,6 +143,9 @@ const API = { if (userid) return getCall("/post/usr/" + userid); return getCall("/post/"); }, + getPostsByTag(tag) { + return getCall("/post/tag/" + tag); + }, getPostsWithTag(userid, tag = "images") { if (userid) return getCall("/post/usr/" + userid + "/" + tag); return getCall("/post/" + tag); diff --git a/App.js b/App.js index eff0643..42cc5c8 100644 --- a/App.js +++ b/App.js @@ -8,6 +8,7 @@ import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; import Login from "./Views/Login.js" import Feed from "./Views/Feed.js" import Profile from "./Views/Profile.js" +import Tags from "./Views/Tags.js" import Search from './Views/Search.js'; import Groups from './Views/Groups.js'; import Courses from './Views/Courses.js'; @@ -306,6 +307,10 @@ export default function App() { name="Profile" component={Profile} /> + { + 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 (); + }); + + const header = ( + + + + ) + + return ( + + + {!loading ? + 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 + } + + + + ); +} + +export default Tags; + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: "#edf2f7", + }, +}); diff --git a/components/Post.js b/components/Post.js index ee91a45..1999cb6 100644 --- a/components/Post.js +++ b/components/Post.js @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { Text, Pressable, FlatList, StyleSheet, View, Share } from 'react-native'; +import { Text, Pressable, FlatList, StyleSheet, View, Share, Alert, Linking } from 'react-native'; import Hyperlink from 'react-native-hyperlink' import { Button, Card, Chip } from 'react-native-paper'; import API from './../API.js'; @@ -14,6 +14,7 @@ import i18n from "../i18nMessages.js"; import ProfilePhotoCircle from './ProfilePhotoCircle.js'; import { posthog } from './../PostHog.js'; import { useNavigation } from '@react-navigation/native'; +import ParsedText from 'react-native-parsed-text'; let Post = (props) => { @@ -67,6 +68,29 @@ let Post = (props) => { const renderComment = ({ item }) => ( ); + const handleTagPress = (tag) => { + // Alert.alert("tag pressed", `You pressed the tag: ${tag}`); + // You can navigate to another screen or perform any other action here + //remove hastag from tag + tag = tag.replace("#", ""); + navigation.navigate("Tags", { tag: tag }); + }; + const handleLinkPress = (url) => { + Linking.canOpenURL(url) + .then((supported) => { + if (supported) { + Linking.openURL(url); + } else { + Alert.alert('Error', 'Unable to open the link.'); + } + }) + .catch((err) => console.error('An error occurred', err)); + }; + const handleLinkLongPress = (url) => { + Share.share({ + url: url + }); + }; return ( { margin: 0, marginBottom: 0 }}> - - {!post.nonOrganicType ? - - - - {toProfileText} - - { - if(cleanContent.length > 10){ - Share.share({ - message: cleanContent - }); - } - }}> - { - cleanContent - } - - - : - - {i18n.t("message.news")} - {cleanContent} - + {!post.nonOrganicType ? + + + + {toProfileText} + - } - + { + if (cleanContent.length > 10) { + Share.share({ + message: cleanContent + }); + } + }}> + + {cleanContent} + + + + + : + + {i18n.t("message.news")} + {cleanContent} + + + }