Open comments on singlepost view
This commit is contained in:
@@ -21,7 +21,7 @@ let NotificationsView = ({ navigation, route }) => {
|
|||||||
<Text style={{ fontWeight: 'normal', fontSize: 12 }}>
|
<Text style={{ fontWeight: 'normal', fontSize: 12 }}>
|
||||||
{" " + Moment(item.ts).fromNow()}
|
{" " + Moment(item.ts).fromNow()}
|
||||||
</Text>
|
</Text>
|
||||||
<SinglePost postId={item.postid} />
|
<SinglePost postId={item.postid} hideComments={true} />
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ import GlobalState from '../contexts/GlobalState.js';
|
|||||||
import i18n from "../i18nMessages.js";
|
import i18n from "../i18nMessages.js";
|
||||||
import ProfilePhotoCircle from './ProfilePhotoCircle.js';
|
import ProfilePhotoCircle from './ProfilePhotoCircle.js';
|
||||||
import { posthog } from './../PostHog.js';
|
import { posthog } from './../PostHog.js';
|
||||||
|
import { useNavigation } from '@react-navigation/native';
|
||||||
|
|
||||||
|
|
||||||
let Post = (props) => {
|
let Post = (props) => {
|
||||||
const gState = useSnapshot(GlobalState);
|
const gState = useSnapshot(GlobalState);
|
||||||
const viewer = gState.me;
|
const viewer = gState.me;
|
||||||
let [showCommentsB, changeshowCommentsB] = useState(false);
|
let [showCommentsB, changeshowCommentsB] = useState(props.showComments || false);
|
||||||
let [post, changePost] = useState(props.post);
|
let [post, changePost] = useState(props.post);
|
||||||
let [likes, changeLikes] = useState(Object.keys(post.reactions).length);
|
let [likes, changeLikes] = useState(Object.keys(post.reactions).length);
|
||||||
let [bookmarked, changeBookmarked] = useState(post.bookmarks && post.bookmarks.includes(viewer._id));
|
let [bookmarked, changeBookmarked] = useState(post.bookmarks && post.bookmarks.includes(viewer._id));
|
||||||
let toProfileText = post.toProfile && post.toProfile !== post.profileid ?
|
let toProfileText = post.toProfile && post.toProfile !== post.profileid ?
|
||||||
<ProfilePhotoCircle profileid={post.toProfile} small={true} /> : undefined;
|
<ProfilePhotoCircle profileid={post.toProfile} small={true} /> : undefined;
|
||||||
let cleanContent = post.content.replace(/@[A-z]+:.+\w/g, '').trim();
|
let cleanContent = post.content.replace(/@[A-z]+:.+\w/g, '').trim();
|
||||||
|
const navigation = useNavigation();
|
||||||
//cleanContent = convertLinks(cleanContent);
|
//cleanContent = convertLinks(cleanContent);
|
||||||
const newComentAdded = (commentData) => {
|
const newComentAdded = (commentData) => {
|
||||||
let newPostObj = { ...post };
|
let newPostObj = { ...post };
|
||||||
@@ -105,7 +107,13 @@ let Post = (props) => {
|
|||||||
{likes}
|
{likes}
|
||||||
</Button>
|
</Button>
|
||||||
<Button icon="forum" labelStyle={{ fontSize: 17 }} style={{ flow: 1 }}
|
<Button icon="forum" labelStyle={{ fontSize: 17 }} style={{ flow: 1 }}
|
||||||
onPress={() => { changeshowCommentsB(!showCommentsB) }}
|
onPress={() => {
|
||||||
|
// changeshowCommentsB(!showCommentsB) // Show comments
|
||||||
|
// Change view to single post
|
||||||
|
navigation.navigate("SinglePost", {
|
||||||
|
postid: post._id,
|
||||||
|
});
|
||||||
|
}}
|
||||||
color="#555"
|
color="#555"
|
||||||
>
|
>
|
||||||
{post.comments.length}
|
{post.comments.length}
|
||||||
@@ -133,12 +141,11 @@ let Post = (props) => {
|
|||||||
{showCommentsB && <NewComment postid={post._id} newComentAdded={newComentAdded} />}
|
{showCommentsB && <NewComment postid={post._id} newComentAdded={newComentAdded} />}
|
||||||
{
|
{
|
||||||
showCommentsB &&
|
showCommentsB &&
|
||||||
<ScrollView style={{ maxHeight: 300 }}>
|
|
||||||
<FlatList
|
<FlatList
|
||||||
data={post.comments}
|
data={post.comments}
|
||||||
renderItem={renderComment}
|
renderItem={renderComment}
|
||||||
keyExtractor={item => item.createdAt}
|
keyExtractor={item => item.createdAt}
|
||||||
/></ScrollView>
|
/>
|
||||||
}
|
}
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { ScrollView } from 'react-native';
|
import { FlatList } from 'react-native';
|
||||||
import API from './../API.js';
|
import API from './../API.js';
|
||||||
import Post from './Post.js';
|
import Post from './Post.js';
|
||||||
|
|
||||||
let SinglePostComponent = ({ postId }) => {
|
let SinglePostComponent = ({ postId, hideComments }) => {
|
||||||
let [post, setPost] = useState({});
|
let [post, setPost] = useState({});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let subscribed = true;
|
let subscribed = true;
|
||||||
@@ -19,9 +19,12 @@ let SinglePostComponent = ({ postId }) => {
|
|||||||
}
|
}
|
||||||
}, [postId]);
|
}, [postId]);
|
||||||
return (post._id ? (
|
return (post._id ? (
|
||||||
<ScrollView>
|
<FlatList
|
||||||
<Post post={post}/>
|
data={[post]}
|
||||||
</ScrollView>
|
renderItem={({ item }) => <Post post={item} showComments={hideComments ? false : true}/>}
|
||||||
|
keyExtractor={item => item._id}
|
||||||
|
/>
|
||||||
|
|
||||||
) : null);
|
) : null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user