mirror of
https://github.com/ecency/ecency-mobile.git
synced 2025-01-08 07:02:25 +03:00
simplified post screen params and reading params
This commit is contained in:
parent
4e5b74785c
commit
807c1f2a93
@ -17,7 +17,8 @@ const ParentPost = ({ post }) => {
|
||||
? navigation.navigate({
|
||||
name: ROUTES.SCREENS.POST,
|
||||
params: {
|
||||
content: post,
|
||||
author: post.author,
|
||||
permlink: post.permlink
|
||||
},
|
||||
key: post.permlink,
|
||||
})
|
||||
|
@ -92,7 +92,8 @@ const PostCardContainer = ({
|
||||
navigation.navigate({
|
||||
name: ROUTES.SCREENS.POST,
|
||||
params: {
|
||||
content: value,
|
||||
author: value.author,
|
||||
permlink: value.permlink
|
||||
},
|
||||
key: get(value, 'permlink'),
|
||||
});
|
||||
|
@ -131,20 +131,20 @@ const PostDisplayContainer = ({
|
||||
<PostDisplayView
|
||||
author={author}
|
||||
currentAccount={currentAccount}
|
||||
isPostUnavailable={isPostUnavailable}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isNewPost={isNewPost}
|
||||
parentPost={parentPost}
|
||||
post={post}
|
||||
activeVotes={activeVotes}
|
||||
activeVotesCount={activeVotesCount}
|
||||
reblogs={reblogs}
|
||||
fetchPost={_fetchPost}
|
||||
handleOnEditPress={_handleOnEditPress}
|
||||
handleOnRemovePress={_handleDeleteComment}
|
||||
handleOnReplyPress={_handleOnReplyPress}
|
||||
handleOnVotersPress={_handleOnVotersPress}
|
||||
handleOnReblogsPress={_handleOnReblogsPress}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isNewPost={isNewPost}
|
||||
isPostUnavailable={isPostUnavailable}
|
||||
parentPost={parentPost}
|
||||
post={post}
|
||||
activeVotes={activeVotes}
|
||||
activeVotesCount={activeVotesCount}
|
||||
reblogs={reblogs}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -117,7 +117,8 @@ export const QuickReplyModalContent = forwardRef(
|
||||
RootNavigation.navigate({
|
||||
name: ROUTES.SCREENS.POST,
|
||||
params: {
|
||||
content: selectedPost,
|
||||
author: selectedPost.author,
|
||||
permlink: selectedPost.permlink
|
||||
},
|
||||
key: get(selectedPost, 'permlink'),
|
||||
});
|
||||
|
@ -16,7 +16,20 @@ export const useGetPostQuery = (_author?:string, _permlink?:string) => {
|
||||
if(!author || !permlink){
|
||||
return null;
|
||||
}
|
||||
return getPost(author, permlink, currentAccount?.username );
|
||||
|
||||
try {
|
||||
const post = await getPost(author, permlink, currentAccount?.username );
|
||||
if(post?.post_id > 0){
|
||||
return post;
|
||||
}
|
||||
|
||||
new Error("Post unavailable")
|
||||
|
||||
} catch(err){
|
||||
console.warn("Failed to get post", err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -1,10 +1,8 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { connect, useSelector } from 'react-redux';
|
||||
import get from 'lodash/get';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
// Services and Action
|
||||
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';
|
||||
import { getPost } from '../../../providers/hive/dhive';
|
||||
|
||||
// Component
|
||||
import PostScreen from '../screen/postScreen';
|
||||
@ -20,15 +18,9 @@ const PostContainer = ({ currentAccount, isLoggedIn, route }) => {
|
||||
|
||||
const params = route.params || {};
|
||||
|
||||
const [post, setPost] = useState<any>(null);
|
||||
const [error, setError] = useState<Error|null>(null);
|
||||
const [isPostUnavailable, setIsPostUnavailable] = useState(false);
|
||||
|
||||
const [author, setAuthor] = useState(params.content?.author || params.author);
|
||||
const [permlink, setPermlink] = useState(params.content?.permlink || params.permlink);
|
||||
|
||||
const deviceOrientation = useAppSelector((state) => state.ui.deviceOrientation);
|
||||
|
||||
//refs
|
||||
const isNewPost = useRef(route.params?.isNewPost).current;
|
||||
|
||||
@ -37,35 +29,23 @@ const PostContainer = ({ currentAccount, isLoggedIn, route }) => {
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const { content } = route.params ?? {};
|
||||
if (!author && !permlink && content) {
|
||||
setPost(content);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(()=>{
|
||||
if(getPostQuery.data){
|
||||
setPost(getPostQuery.data);
|
||||
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])
|
||||
|
||||
useEffect(()=>{
|
||||
if(post && post.depth > 0 && post.parent_author && post.parent_permlink){
|
||||
getParentPostQuery.setAuthor(post.parent_author);
|
||||
getParentPostQuery.setPermlink(post.parent_permlink);
|
||||
}
|
||||
}, [post])
|
||||
|
||||
|
||||
// Component Functions
|
||||
|
||||
const _loadPost = async (_author = null, _permlink = null) => {
|
||||
|
||||
if(_author && _permlink && _author !== author && _permlink !== _permlink){
|
||||
if (_author && _permlink && _author !== author && _permlink !== _permlink) {
|
||||
setAuthor(_author);
|
||||
setPermlink(_permlink);
|
||||
}
|
||||
|
||||
getPostQuery.refetch();
|
||||
};
|
||||
|
||||
@ -73,25 +53,24 @@ const PostContainer = ({ currentAccount, isLoggedIn, route }) => {
|
||||
const { isFetch: nextIsFetch } = route.params ?? {};
|
||||
if (nextIsFetch) {
|
||||
const { author: _author, permlink } = route.params;
|
||||
|
||||
_loadPost(_author, permlink);
|
||||
}
|
||||
}, [route.params.isFetch]);
|
||||
|
||||
|
||||
const _isPostUnavailable = !getPostQuery.isLoading && getPostQuery.error;
|
||||
|
||||
return (
|
||||
<PostScreen
|
||||
post={getPostQuery.data}
|
||||
currentAccount={currentAccount}
|
||||
error={error}
|
||||
author={author}
|
||||
fetchPost={_loadPost}
|
||||
isFetchComments
|
||||
isLoggedIn={isLoggedIn}
|
||||
isNewPost={isNewPost}
|
||||
parentPost={getParentPostQuery.data}
|
||||
post={post}
|
||||
isPostUnavailable={isPostUnavailable}
|
||||
orientation={deviceOrientation}
|
||||
isPostUnavailable={_isPostUnavailable}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -49,11 +49,8 @@ export const deepLinkParser = async (url, currentAccount) => {
|
||||
};
|
||||
keey = 'WebBrowser';
|
||||
} else if (permlink) {
|
||||
content = { author, permlink };
|
||||
params = { author, permlink };
|
||||
routeName = ROUTES.SCREENS.POST;
|
||||
params = {
|
||||
content,
|
||||
};
|
||||
keey = `${author}/${permlink}`;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user