New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Community - Filter Resteemed Posts from Individual User Profile Feed #2897

Closed
wants to merge 9 commits into
base: master
from
@@ -27,6 +27,7 @@ class PostsList extends React.Component {
category: PropTypes.string,
loadMore: PropTypes.func,
showSpam: PropTypes.bool,
showResteem: PropTypes.bool,
fetchState: PropTypes.func.isRequired,
pathname: PropTypes.string,
nsfwPref: PropTypes.string.isRequired,
@@ -113,9 +114,9 @@ class PostsList extends React.Component {
topPosition(el) + el.offsetHeight - scrollTop - window.innerHeight <
10
) {
const { loadMore, posts, category } = this.props;
const { loadMore, posts, category, showResteem } = this.props;
if (loadMore && posts && posts.size)
loadMore(posts.last(), category);
loadMore(posts.last(), category, showResteem);
}
// Detect if we're in mobile mode (renders larger preview imgs)
const mq = window.matchMedia('screen and (max-width: 39.9375em)');
@@ -146,6 +147,7 @@ class PostsList extends React.Component {
render() {
const {
posts,
showResteem,
showSpam,
loading,
category,
@@ -164,8 +166,10 @@ class PostsList extends React.Component {
}
const ignore =
ignore_result && ignore_result.has(cont.get('author'));
const hideResteem =
!showResteem && account && cont.get('author') != account;
const hide = cont.getIn(['stats', 'hide']);
if (!(ignore || hide) || showSpam)
if (!hideResteem && (!(ignore || hide) || showSpam))
// rephide
postsInfo.push({ item, ignore });
});
@@ -4,6 +4,7 @@ import { Link } from 'react-router';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import classnames from 'classnames';
import * as globalActions from 'app/redux/GlobalReducer';
import * as transactionActions from 'app/redux/TransactionReducer';
import * as userActions from 'app/redux/UserReducer';
import { actions as fetchDataSagaActions } from 'app/redux/FetchDataSaga';
@@ -23,6 +24,7 @@ import { repLog10 } from 'app/utils/ParsersAndFormatters.js';
import Tooltip from 'app/components/elements/Tooltip';
import DateJoinWrapper from 'app/components/elements/DateJoinWrapper';
import tt from 'counterpart';
import { List } from 'immutable';
import WalletSubMenu from 'app/components/elements/WalletSubMenu';
import Userpic from 'app/components/elements/Userpic';
import Callout from 'app/components/elements/Callout';
@@ -36,14 +38,14 @@ import DropdownMenu from 'app/components/elements/DropdownMenu';
export default class UserProfile extends React.Component {
constructor() {
super();
this.state = {};
this.state = { showResteem: true };
this.onPrint = () => {
window.print();
};
this.loadMore = this.loadMore.bind(this);
}
shouldComponentUpdate(np) {
shouldComponentUpdate(np, ns) {
const { follow } = this.props;
const { follow_count } = this.props;
@@ -85,7 +87,8 @@ export default class UserProfile extends React.Component {
np.location.pathname !== this.props.location.pathname ||
np.routeParams.accountname !== this.props.routeParams.accountname ||
np.follow_count !== this.props.follow_count ||
np.blogmode !== this.props.blogmode
np.blogmode !== this.props.blogmode ||
ns.showResteem !== this.state.showResteem
);
}
@@ -94,8 +97,9 @@ export default class UserProfile extends React.Component {
this.props.clearPowerdownDefaults();
}
loadMore(last_post, category) {
loadMore(last_post, category, showResteem) {
const { accountname } = this.props.routeParams;
if (!last_post) return;
let order;
@@ -122,20 +126,33 @@ export default class UserProfile extends React.Component {
order,
category
)
)
) {
return;
}
const postFilter = showResteem
? null
: value => value.author === accountname;
const [author, permlink] = last_post.split('/');
this.props.requestData({
author,
permlink,
order,
category,
accountname,
postFilter,
});
}
toggleShowResteem = e => {
e.preventDefault();
const newShowResteem = !this.state.showResteem;
this.setState({ showResteem: newShowResteem });
};
render() {
const {
state: { showResteem },
props: { current_user, wifShown, global_status, follow },
onPrint,
} = this;
@@ -326,14 +343,20 @@ export default class UserProfile extends React.Component {
tab_content = <Callout>{emptyText}</Callout>;
} else {
tab_content = (
<PostsList
account={account.name}
posts={posts}
loading={fetching}
category="blog"
loadMore={this.loadMore}
showSpam
/>
<div>
<a href="#" onClick={this.toggleShowResteem}>
{showResteem ? 'Hide resteems' : 'Show all'}
</a>
<PostsList
account={account.name}
posts={posts}
loading={fetching}
category="blog"
loadMore={this.loadMore}
showResteem={showResteem}
showSpam
/>
</div>
);
}
} else {
@@ -120,7 +120,7 @@ function* getAccounts(usernames) {
}
export function* fetchData(action) {
const { order, author, permlink, accountname } = action.payload;
const { order, author, permlink, accountname, postFilter } = action.payload;
let { category } = action.payload;
if (!category) category = '';
category = category.toLowerCase();
@@ -293,17 +293,51 @@ export function* fetchData(action) {
}
yield put(appActions.fetchDataBegin());
try {
const data = yield call([api, api[call_name]], ...args);
yield put(
globalActions.receiveData({
data,
order,
category,
author,
permlink,
accountname,
})
);
const firstPermlink = permlink;
var fetched = 0;
var endOfData = false;
var fetchLimitReached = false;
var fetchDone = false;
var batch = 0;
while (!fetchDone) {
var data = yield call([api, api[call_name]], ...args);
endOfData = data.length < constants.FETCH_DATA_BATCH_SIZE;
batch++;
fetchLimitReached = batch >= constants.MAX_BATCHES;
// next arg. Note 'by_replies' does not use same structure.
const lastValue = data.length > 0 ? data[data.length - 1] : null;
if (lastValue && order !== 'by_replies') {
args[0].start_author = lastValue.author;
args[0].start_permlink = lastValue.permlink;
}
// Still return all data but only count ones matching the filter.
// Rely on UI to actually hide the posts.
fetched += postFilter
? data.filter(postFilter).length
: data.length;
fetchDone =
endOfData ||
fetchLimitReached ||
fetched >= constants.FETCH_DATA_BATCH_SIZE;
yield put(
globalActions.receiveData({
data,
order,
category,
author,
firstPermlink,
accountname,
fetching: !fetchDone,
endOfData,
})
);
}
} catch (error) {
console.error('~~ Saga fetchData error ~~>', call_name, args, error);
yield put(appActions.steemApiError(error.message));
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.