From 1abf26ce60d3cd60c93dd132d140dffba1b86cc0 Mon Sep 17 00:00:00 2001 From: aeroreyna Date: Sat, 12 Mar 2022 21:52:08 -0800 Subject: [PATCH] Add moment --- Views/Notifications.js | 10 ++++++--- Views/Profile.js | 46 +++++++++++++++++++----------------------- components/Post.js | 6 +++++- package.json | 1 + 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Views/Notifications.js b/Views/Notifications.js index ffe5c46..be693a9 100644 --- a/Views/Notifications.js +++ b/Views/Notifications.js @@ -4,6 +4,7 @@ import { View, Text, StyleSheet, SafeAreaView, FlatList } from 'react-native'; import { Card } from 'react-native-paper'; import API from './../API.js'; import Post from './../components/Post.js'; +import Moment from 'moment'; let LoadPost = ({ postid, viewer }) => { @@ -24,13 +25,16 @@ let Notifications = ({ navigation, route }) => { }, [route.params]); const renderNotification = (({ item }) => { //return (); - const gotToPost = ()=>{ - navigation.navigate('SinglePost', {postid: item.postid, viewer: Me}); + const gotToPost = () => { + navigation.navigate('SinglePost', { postid: item.postid, viewer: Me }); }; return ( - + {item.body} + + {" " + Moment(item.ts).fromNow()} + ) diff --git a/Views/Profile.js b/Views/Profile.js index d361296..c48b69f 100644 --- a/Views/Profile.js +++ b/Views/Profile.js @@ -3,8 +3,6 @@ import React, { useState, useEffect } from 'react'; 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 MaterialIcons from 'react-native-vector-icons/MaterialIcons'; import NewPost from "./../components/NewPost.js"; @@ -17,7 +15,7 @@ let Profile = ({ navigation, route }) => { let r = await API.getMe(); setMeProfile(r); if (route.params && route.params.profileid) { - API.getUserProfile(route.params.profileid).then(({profile}) => { + API.getUserProfile(route.params.profileid).then(({ profile }) => { navigation.setOptions({ title: profile.firstName + " " + profile.lastName }); }); API.getPosts(route.params.profileid).then((data) => { @@ -28,32 +26,30 @@ let Profile = ({ navigation, route }) => { } }, [route.params]); const renderPost = (({ item }) => { + if (item.nonOrganicType) + return (<>); return (); }); return ( - , - }}> - - - {Posts.length === 0 && } - {Posts.length !== 0 && - item._id || item.createdAt} - ListHeaderComponent={ setPosts([newPost, ...Posts])} />} - refreshing={Posts.length === 0} - onRefresh={()=>{ - API.getPosts(route.params.profileid).then(setPosts); - }} - /> - } - - - - + + + {Posts.length === 0 && } + {Posts.length !== 0 && + item._id || item.createdAt} + ListHeaderComponent={ setPosts([newPost, ...Posts])} />} + refreshing={Posts.length === 0} + onRefresh={() => { + API.getPosts(route.params.profileid).then(setPosts); + }} + /> + } + + + ); } diff --git a/components/Post.js b/components/Post.js index 29dcf42..a008885 100644 --- a/components/Post.js +++ b/components/Post.js @@ -6,6 +6,7 @@ import UserName from './UserName.js'; import Media from './Media.js'; import Comment from "./Comment"; import NewComment from './NewComment.js'; +import Moment from 'moment'; let Post = (props) => { @@ -58,12 +59,15 @@ let Post = (props) => { {toProfileText} + + {" " + Moment(post.createdAt).fromNow()} + {cleanContent} : - News + News {cleanContent} } diff --git a/package.json b/package.json index 6d8af52..1fd79a8 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@react-navigation/native-stack": "^6.5.0", "expo": "~43.0.2", "expo-status-bar": "~1.1.0", + "moment": "^2.29.1", "react": "17.0.1", "react-dom": "17.0.1", "react-google-material-icons": "^1.0.4",