postDisplayContainer hooks

This commit is contained in:
feruz 2019-12-20 06:23:14 +02:00
parent edda6c152b
commit c9f4135046

View File

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { useEffect } from 'react';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
@ -17,22 +17,23 @@ import { default as ROUTES } from '../../../constants/routeNames';
// Component // Component
import PostDisplayView from '../view/postDisplayView'; import PostDisplayView from '../view/postDisplayView';
/* const PostDisplayContainer = ({
* Props Name Description Value navigation,
*@props --> props name here description here Value Type Here post,
* fetchPost,
*/ isFetchPost,
currentAccount,
class PostDisplayContainer extends Component { pinCode,
constructor(props) { dispatch,
super(props); intl,
this.state = {}; isLoggedIn,
} isNewPost,
parentPost,
isPostUnavailable,
author,
}) => {
// Component Functions // Component Functions
_handleOnVotersPress = activeVotes => { const _handleOnVotersPress = activeVotes => {
const { navigation, post } = this.props;
navigation.navigate({ navigation.navigate({
routeName: ROUTES.SCREENS.VOTERS, routeName: ROUTES.SCREENS.VOTERS,
params: { params: {
@ -43,9 +44,7 @@ class PostDisplayContainer extends Component {
}); });
}; };
_handleOnReblogsPress = reblogs => { const _handleOnReblogsPress = reblogs => {
const { navigation, post } = this.props;
if (reblogs.length > 0) { if (reblogs.length > 0) {
navigation.navigate({ navigation.navigate({
routeName: ROUTES.SCREENS.REBLOGS, routeName: ROUTES.SCREENS.REBLOGS,
@ -57,22 +56,18 @@ class PostDisplayContainer extends Component {
} }
}; };
_handleOnReplyPress = () => { const _handleOnReplyPress = () => {
const { post, navigation } = this.props;
navigation.navigate({ navigation.navigate({
routeName: ROUTES.SCREENS.EDITOR, routeName: ROUTES.SCREENS.EDITOR,
params: { params: {
isReply: true, isReply: true,
post, post,
fetchPost: this._fetchPost, fetchPost: _fetchPost,
}, },
}); });
}; };
_handleOnEditPress = () => { const _handleOnEditPress = () => {
const { post, navigation } = this.props;
if (post) { if (post) {
const isReply = post.parent_author; const isReply = post.parent_author;
@ -82,15 +77,13 @@ class PostDisplayContainer extends Component {
isEdit: true, isEdit: true,
isReply, isReply,
post, post,
fetchPost: this._fetchPost, fetchPost: _fetchPost,
}, },
}); });
} }
}; };
_handleDeleteComment = permlink => { const _handleDeleteComment = permlink => {
const { currentAccount, pinCode, navigation, dispatch, intl } = this.props;
deleteComment(currentAccount, pinCode, permlink).then(() => { deleteComment(currentAccount, pinCode, permlink).then(() => {
navigation.goBack(); navigation.goBack();
dispatch( dispatch(
@ -103,52 +96,34 @@ class PostDisplayContainer extends Component {
}); });
}; };
_fetchPost = async () => { const _fetchPost = async () => {
const { post, fetchPost } = this.props;
if (post) { if (post) {
fetchPost(post.author, post.permlink); fetchPost(post.author, post.permlink);
} }
}; };
// Component Life Cycle Functions useEffect(() => {
UNSAFE_componentWillReceiveProps(nextProps) { _fetchPost();
const { isFetchPost } = this.props; }, [isFetchPost]);
if (isFetchPost !== nextProps.isFetchPost && nextProps.isFetchPost) {
this._fetchPost();
}
}
render() { return (
const { <PostDisplayView
currentAccount, author={author}
isLoggedIn, currentAccount={currentAccount}
isNewPost, fetchPost={_fetchPost}
parentPost, handleOnEditPress={_handleOnEditPress}
post, handleOnRemovePress={_handleDeleteComment}
isPostUnavailable, handleOnReplyPress={_handleOnReplyPress}
author, handleOnVotersPress={_handleOnVotersPress}
} = this.props; handleOnReblogsPress={_handleOnReblogsPress}
isLoggedIn={isLoggedIn}
return ( isNewPost={isNewPost}
<PostDisplayView isPostUnavailable={isPostUnavailable}
author={author} parentPost={parentPost}
currentAccount={currentAccount} post={post}
fetchPost={this._fetchPost} />
handleOnEditPress={this._handleOnEditPress} );
handleOnRemovePress={this._handleDeleteComment} };
handleOnReplyPress={this._handleOnReplyPress}
handleOnVotersPress={this._handleOnVotersPress}
handleOnReblogsPress={this._handleOnReblogsPress}
isLoggedIn={isLoggedIn}
isNewPost={isNewPost}
isPostUnavailable={isPostUnavailable}
parentPost={parentPost}
post={post}
/>
);
}
}
const mapStateToProps = state => ({ const mapStateToProps = state => ({
currentAccount: state.account.currentAccount, currentAccount: state.account.currentAccount,