-
Notifications
You must be signed in to change notification settings - Fork 69
/
postScreen.tsx
93 lines (79 loc) · 2.67 KB
/
postScreen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React, { useState, useRef, useEffect } from 'react';
import { View } from 'react-native';
// Components
import { BasicHeader, IconButton, PostDisplay, PostOptionsModal } from '../../../components';
import styles from '../styles/postScreen.styles';
// Component
import { postQueries } from '../../../providers/queries';
import FastImage from 'react-native-fast-image';
const PostScreen = ({ route }) => {
const params = route.params || {};
// // refs
const isNewPost = useRef(route.params?.isNewPost).current;
const postOptionsModalRef = useRef<typeof PostOptionsModal | null>(null);
const [author, setAuthor] = useState(params.content?.author || params.author);
const [permlink, setPermlink] = useState(params.content?.permlink || params.permlink);
const getPostQuery = postQueries.useGetPostQuery(author, permlink, params.content);
const getParentPostQuery = postQueries.useGetPostQuery();
useEffect(()=>{
return () => {
//clears FastImage RAM, not disk usage;
FastImage.clearMemoryCache();
}
},[])
useEffect(() => {
const post = getPostQuery.data;
if (post) {
if (post && post.depth > 0 && post.parent_author && post.parent_permlink) {
getParentPostQuery.setAuthor(post.parent_author);
getParentPostQuery.setPermlink(post.parent_permlink);
}
}
}, [getPostQuery.data]);
// // Component Functions
const _loadPost = async (_author = null, _permlink = null) => {
if (_author && _permlink && _author !== author && _permlink !== _permlink) {
setAuthor(_author);
setPermlink(_permlink);
}
getPostQuery.refetch();
};
const _isPostUnavailable = !getPostQuery.isLoading && getPostQuery.error;
const _onPostOptionsBtnPress = (content = getPostQuery.data) => {
if (postOptionsModalRef.current) {
postOptionsModalRef.current.show(content);
}
};
const _postOptionsBtn = (
<IconButton
iconStyle={styles.optionsIcon}
iconType="MaterialCommunityIcons"
name="dots-vertical"
onPress={_onPostOptionsBtnPress}
size={24}
/>
);
return (
<View style={styles.container}>
<BasicHeader
isHasDropdown={true}
title="Post"
content={getPostQuery.data}
dropdownComponent={_postOptionsBtn}
isNewPost={isNewPost}
/>
<PostDisplay
author={author}
permlink={permlink}
isPostUnavailable={_isPostUnavailable}
fetchPost={_loadPost}
isFetchComments={true}
isNewPost={isNewPost}
parentPost={getParentPostQuery.data}
post={getPostQuery.data}
/>
<PostOptionsModal ref={postOptionsModalRef} />
</View>
);
};
export default PostScreen;