Merge pull request #606 from esteemapp/feature/comment-filter

created comment filter
This commit is contained in:
uğur erdal 2019-02-22 13:59:59 +03:00 committed by GitHub
commit 50d908d1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 151 additions and 40 deletions

View File

@ -11,8 +11,6 @@ import { getComments } from '../../../providers/steem/dsteem';
// Constants // Constants
import { default as ROUTES } from '../../../constants/routeNames'; import { default as ROUTES } from '../../../constants/routeNames';
// Utilities
// Component // Component
import { CommentsView } from '..'; import { CommentsView } from '..';
@ -36,14 +34,89 @@ class CommentsContainer extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { commentCount } = this.props; const { commentCount, selectedFilter } = this.props;
if (nextProps.commentCount > commentCount) { if (nextProps.commentCount > commentCount) {
this._getComments(); this._getComments();
} }
if (selectedFilter !== nextProps.selectedFilter && nextProps.selectedFilter) {
const shortedComments = this._shortComments(nextProps.selectedFilter);
this.setState({ comments: shortedComments });
}
} }
// Component Functions // Component Functions
_shortComments = (sortOrder) => {
const { comments: parent } = this.state;
const allPayout = c => parseFloat(c.pending_payout_value.split(' ')[0])
+ parseFloat(c.total_payout_value.split(' ')[0])
+ parseFloat(c.curator_payout_value.split(' ')[0]);
const absNegative = a => a.net_rshares < 0;
const sortOrders = {
TRENDING: (a, b) => {
if (absNegative(a)) {
return 1;
}
if (absNegative(b)) {
return -1;
}
const apayout = allPayout(a);
const bpayout = allPayout(b);
if (apayout !== bpayout) {
return bpayout - apayout;
}
return 0;
},
REPUTATION: (a, b) => {
const keyA = a.author_reputation;
const keyB = b.author_reputation;
if (keyA > keyB) return -1;
if (keyA < keyB) return 1;
return 0;
},
VOTES: (a, b) => {
const keyA = a.net_votes;
const keyB = b.net_votes;
if (keyA > keyB) return -1;
if (keyA < keyB) return 1;
return 0;
},
AGE: (a, b) => {
if (absNegative(a)) {
return 1;
}
if (absNegative(b)) {
return -1;
}
const keyA = Date.parse(a.created);
const keyB = Date.parse(b.created);
if (keyA > keyB) return -1;
if (keyA < keyB) return 1;
return 0;
},
};
parent.sort(sortOrders[sortOrder]);
return parent;
};
_getComments = () => { _getComments = () => {
const { author, permlink } = this.props; const { author, permlink } = this.props;
@ -87,18 +160,19 @@ class CommentsContainer extends Component {
isLoggedIn, isLoggedIn,
commentCount, commentCount,
author, author,
permlink,
currentAccount, currentAccount,
commentNumber, commentNumber,
comments, comments,
fetchPost, fetchPost,
isShowMoreButton, isShowMoreButton,
selectedFilter,
selectedPermlink: _selectedPermlink, selectedPermlink: _selectedPermlink,
} = this.props; } = this.props;
return ( return (
<CommentsView <CommentsView
key={permlink} key={selectedFilter}
selectedFilter={selectedFilter}
selectedPermlink={_selectedPermlink || selectedPermlink} selectedPermlink={_selectedPermlink || selectedPermlink}
author={author} author={author}
isShowMoreButton={isShowMoreButton} isShowMoreButton={isShowMoreButton}
@ -109,7 +183,6 @@ class CommentsContainer extends Component {
handleOnEditPress={this._handleOnEditPress} handleOnEditPress={this._handleOnEditPress}
handleOnReplyPress={this._handleOnReplyPress} handleOnReplyPress={this._handleOnReplyPress}
isLoggedIn={isLoggedIn} isLoggedIn={isLoggedIn}
permlink={permlink}
fetchPost={fetchPost} fetchPost={fetchPost}
{...this.props} {...this.props}
/> />

View File

@ -1,5 +1,5 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { View, FlatList } from 'react-native'; import { FlatList } from 'react-native';
// Components // Components
import { Comment } from '../../comment'; import { Comment } from '../../comment';
@ -21,49 +21,46 @@ class CommentsView extends PureComponent {
// Component Life Cycles // Component Life Cycles
// Component Functions // Component Functions
_handleOnDropdownSelect = () => {};
_keyExtractor = item => item.permlink; _keyExtractor = item => item.permlink;
render() { render() {
const { const {
avatarSize, avatarSize,
commentCount,
commentNumber, commentNumber,
comments, comments,
currentAccountUsername, currentAccountUsername,
fetchPost,
handleOnEditPress, handleOnEditPress,
handleOnReplyPress, handleOnReplyPress,
handleOnUserPress, handleOnUserPress,
isLoggedIn, isLoggedIn,
marginLeft,
isShowSubComments, isShowSubComments,
fetchPost, marginLeft,
commentCount,
} = this.props; } = this.props;
return ( return (
<FlatList <FlatList
data={comments} data={comments}
keyExtractor={this._keyExtractor} keyExtractor={this._keyExtractor}
renderItem={({ item, index }) => ( renderItem={({ item }) => (
<View key={index}>
<Comment <Comment
isShowMoreButton={commentNumber === 1 && item.children > 0}
comment={item}
marginLeft={marginLeft}
commentNumber={commentNumber}
fetchPost={fetchPost}
commentCount={commentCount || item.children}
isShowSubComments={isShowSubComments}
avatarSize={avatarSize} avatarSize={avatarSize}
comment={item}
commentCount={commentCount || item.children}
commentNumber={commentNumber}
currentAccountUsername={currentAccountUsername} currentAccountUsername={currentAccountUsername}
handleOnReplyPress={handleOnReplyPress} fetchPost={fetchPost}
handleOnEditPress={handleOnEditPress} handleOnEditPress={handleOnEditPress}
handleOnReplyPress={handleOnReplyPress}
handleOnUserPress={handleOnUserPress} handleOnUserPress={handleOnUserPress}
isLoggedIn={isLoggedIn} isLoggedIn={isLoggedIn}
showComentsToggle={this._showComentsToggle} isShowMoreButton={commentNumber === 1 && item.children > 0}
isShowSubComments={isShowSubComments}
key={item.permlink}
marginLeft={marginLeft}
/> />
</View>
)} )}
/> />
); );

View File

@ -3,6 +3,5 @@ import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({ export default EStyleSheet.create({
commentWrapper: { commentWrapper: {
padding: 16, padding: 16,
paddingBottom: 50,
}, },
}); });

View File

@ -1,9 +1,11 @@
import React, { PureComponent, Fragment } from 'react'; import React, { PureComponent, Fragment } from 'react';
import { View } from 'react-native'; import { View } from 'react-native';
import { injectIntl } from 'react-intl';
// Components // Components
import { FilterBar } from '../../filterBar'; import { FilterBar } from '../../filterBar';
import { Comments } from '../../comments'; import { Comments } from '../../comments';
import COMMENT_FILTER from '../../../constants/options/comment';
// Styles // Styles
import styles from './commentDisplayStyles'; import styles from './commentDisplayStyles';
@ -16,31 +18,39 @@ class CommentsDisplayView extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = {}; this.state = {
selectedFilter: null,
};
} }
// Component Life Cycles // Component Life Cycles
// Component Functions // Component Functions
_handleOnDropdownSelect = () => {}; _handleOnDropdownSelect = (index, option) => {
this.setState({ selectedFilter: option });
};
render() { render() {
const { const {
author, permlink, commentCount, fetchPost, author, commentCount, fetchPost, intl, permlink,
} = this.props; } = this.props;
// TODO: implement comments filtering const { selectedFilter } = this.state;
return ( return (
<Fragment> <Fragment>
{commentCount > 0 && ( {commentCount > 0 && (
<Fragment> <Fragment>
<FilterBar <FilterBar
dropdownIconName="arrow-drop-down" dropdownIconName="arrow-drop-down"
options={['TRENDING']} options={COMMENT_FILTER.map(item => intl.formatMessage({ id: `comment_filter.${item}` }).toUpperCase())}
defaultText="TRENDING" defaultText={intl
.formatMessage({ id: `comment_filter.${COMMENT_FILTER[0]}` })
.toUpperCase()}
onDropdownSelect={this._handleOnDropdownSelect} onDropdownSelect={this._handleOnDropdownSelect}
/> />
<View style={styles.commentWrapper}> <View style={styles.commentWrapper}>
<Comments <Comments
selectedFilter={selectedFilter}
fetchPost={fetchPost} fetchPost={fetchPost}
commentCount={commentCount} commentCount={commentCount}
author={author} author={author}
@ -54,4 +64,4 @@ class CommentsDisplayView extends PureComponent {
} }
} }
export default CommentsDisplayView; export default injectIntl(CommentsDisplayView);

View File

@ -20,6 +20,7 @@ export default EStyleSheet.create({
scroll: { scroll: {
height: '$deviceHeight / 1.135', height: '$deviceHeight / 1.135',
backgroundColor: '$primaryBackgroundColor', backgroundColor: '$primaryBackgroundColor',
marginBottom: 50,
}, },
footer: { footer: {
flexDirection: 'column', flexDirection: 'column',

View File

@ -115,7 +115,7 @@ class PostDisplayView extends PureComponent {
const { post, fetchPost, parentPost } = this.props; const { post, fetchPost, parentPost } = this.props;
const { postHeight, scrollHeight, isLoadedComments } = this.state; const { postHeight, scrollHeight, isLoadedComments } = this.state;
const isPostEnd = scrollHeight > postHeight; // const isPostEnd = scrollHeight > postHeight;
const isGetComment = scrollHeight + 300 > postHeight; const isGetComment = scrollHeight + 300 > postHeight;
const formatedTime = post && getTimeFromNow(post.created); const formatedTime = post && getTimeFromNow(post.created);
@ -140,7 +140,7 @@ class PostDisplayView extends PureComponent {
size={16} size={16}
/> />
<PostBody body={post.body} /> <PostBody body={post.body} />
<View style={[styles.footer, !isPostEnd && styles.marginFooter]}> <View style={styles.footer}>
<Tags tags={post.json_metadata && post.json_metadata.tags} /> <Tags tags={post.json_metadata && post.json_metadata.tags} />
<Text style={styles.footerText}> <Text style={styles.footerText}>
Posted by Posted by

View File

@ -199,5 +199,11 @@
"deep_link": { "deep_link": {
"no_existing_user": "No existing user", "no_existing_user": "No existing user",
"no_existing_post": "No existing post" "no_existing_post": "No existing post"
},
"comment_filter": {
"trending": "trending",
"reputation": "reputation",
"votes": "votes",
"age": "age"
} }
} }

View File

@ -0,0 +1 @@
export default ['trending', 'reputation', 'votes', 'age'];

View File

@ -0,0 +1,24 @@
export default (input) => {
if (input === 0) {
return 25;
}
if (!input) {
return input;
}
let neg = false;
if (input < 0) neg = true;
let reputationLevel = Math.log10(Math.abs(input));
reputationLevel = Math.max(reputationLevel - 9, 0);
if (reputationLevel < 0) reputationLevel = 0;
if (neg) reputationLevel *= -1;
reputationLevel = reputationLevel * 9 + 25;
return Math.floor(reputationLevel);
};