working on comments

This commit is contained in:
u-e 2019-01-16 17:27:30 +03:00
parent 2b0dbfb05b
commit 3e0455da73
2 changed files with 85 additions and 31 deletions

View File

@ -27,6 +27,8 @@ class CommentsContainer extends Component {
super(props); super(props);
this.state = { this.state = {
comments: [], comments: [],
isShowComments: false,
isRenderRequire: true,
}; };
} }
@ -81,14 +83,42 @@ class CommentsContainer extends Component {
}); });
}; };
_showComentsToggle = (permlink) => {
const { isShowComments, selectedPermlink } = this.state;
const { selectedPermlink: _selectedPermlink } = this.props;
if (_selectedPermlink !== selectedPermlink) {
this.setState({ isShowComments: !!isShowComments, selectedPermlink: permlink });
} else {
this.setState({ isShowComments: !isShowComments, selectedPermlink: permlink });
}
this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true }));
};
render() { render() {
const { comments } = this.state;
const { const {
isLoggedIn, commentCount, author, permlink, currentAccount, fetchPost, comments, isShowComments, isRenderRequire, selectedPermlink,
} = this.state;
const {
isLoggedIn,
commentCount,
author,
permlink,
currentAccount,
commentNumber,
fetchPost,
selectedPermlink: _selectedPermlink,
} = this.props; } = this.props;
if (isRenderRequire) {
return ( return (
<CommentsView <CommentsView
key={permlink}
selectedPermlink={_selectedPermlink || selectedPermlink}
isShowComments={isShowComments}
showComentsToggle={this._showComentsToggle}
author={author} author={author}
commentNumber={commentNumber || 1}
commentCount={commentCount} commentCount={commentCount}
comments={comments} comments={comments}
currentAccountUsername={currentAccount.name} currentAccountUsername={currentAccount.name}
@ -101,6 +131,8 @@ class CommentsContainer extends Component {
/> />
); );
} }
return null;
}
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({

View File

@ -46,8 +46,14 @@ class CommentsView extends PureComponent {
marginLeft, marginLeft,
fetchPost, fetchPost,
intl, intl,
showComentsToggle,
isShowComments,
parentPermlink,
selectedPermlink,
} = this.props; } = this.props;
// if (isShowComments) alert(isShowComments);
return ( return (
<View> <View>
{!!comments && ( {!!comments && (
@ -94,15 +100,32 @@ class CommentsView extends PureComponent {
iconType="MaterialIcons" iconType="MaterialIcons"
/> />
)} )}
{item.children > 0 && commentNumber === 1 && (
<IconButton
size={18}
iconStyle={{ color: '#c1c5c7' }}
style={{ marginLeft: 10 }}
name="star"
onPress={() => showComentsToggle(item.permlink)}
iconType="MaterialIcons"
/>
)}
</Fragment> </Fragment>
)} )}
</View> </View>
</View> </View>
{!isProfilePreview && ( {!isProfilePreview
&& item.children > 0
&& (isShowComments
&& (selectedPermlink === item.permlink
|| selectedPermlink === item.parent_permlink) && (
<View style={{ marginLeft: marginLeft || 29 }}> <View style={{ marginLeft: marginLeft || 29 }}>
{commentNumber !== 8 && (
<Comments <Comments
commentNumber={commentNumber ? commentNumber * 2 : 1} key={item.permlink}
selectedPermlink={selectedPermlink}
parentPermlink={item.parent_permlink}
isShowComments={isShowComments}
commentNumber={commentNumber && commentNumber * 2}
marginLeft={20} marginLeft={20}
avatarSize={avatarSize || 16} avatarSize={avatarSize || 16}
author={item.author} author={item.author}
@ -110,9 +133,8 @@ class CommentsView extends PureComponent {
commentCount={item.children} commentCount={item.children}
fetchPost={fetchPost} fetchPost={fetchPost}
/> />
)}
</View> </View>
)} ))}
</View> </View>
)} )}
/> />