You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
5.4 KiB
171 lines
5.4 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import { connect } from 'react-redux';
|
||
6 years ago
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
6 years ago
|
import { debounce } from 'lodash';
|
||
8 years ago
|
import LoadingIndicator from '../../components/loading_indicator';
|
||
|
import {
|
||
3 years ago
|
lookupAccount,
|
||
3 years ago
|
fetchAccount,
|
||
8 years ago
|
fetchFollowers,
|
||
8 years ago
|
expandFollowers,
|
||
8 years ago
|
} from '../../actions/accounts';
|
||
6 years ago
|
import { FormattedMessage } from 'react-intl';
|
||
8 years ago
|
import AccountContainer from '../../containers/account_container';
|
||
8 years ago
|
import Column from '../ui/components/column';
|
||
|
import HeaderContainer from '../account_timeline/containers/header_container';
|
||
|
import ColumnBackButton from '../../components/column_back_button';
|
||
6 years ago
|
import ScrollableList from '../../components/scrollable_list';
|
||
6 years ago
|
import MissingIndicator from 'mastodon/components/missing_indicator';
|
||
4 years ago
|
import TimelineHint from 'mastodon/components/timeline_hint';
|
||
3 years ago
|
import LimitedAccountHint from '../account_timeline/components/limited_account_hint';
|
||
|
import { getAccountHidden } from 'mastodon/selectors';
|
||
2 years ago
|
import { normalizeForLookup } from 'mastodon/reducers/accounts_map';
|
||
8 years ago
|
|
||
3 years ago
|
const mapStateToProps = (state, { params: { acct, id } }) => {
|
||
2 years ago
|
const accountId = id || state.getIn(['accounts_map', normalizeForLookup(acct)]);
|
||
3 years ago
|
|
||
|
if (!accountId) {
|
||
|
return {
|
||
|
isLoading: true,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
accountId,
|
||
|
remote: !!(state.getIn(['accounts', accountId, 'acct']) !== state.getIn(['accounts', accountId, 'username'])),
|
||
|
remoteUrl: state.getIn(['accounts', accountId, 'url']),
|
||
|
isAccount: !!state.getIn(['accounts', accountId]),
|
||
|
accountIds: state.getIn(['user_lists', 'followers', accountId, 'items']),
|
||
|
hasMore: !!state.getIn(['user_lists', 'followers', accountId, 'next']),
|
||
|
isLoading: state.getIn(['user_lists', 'followers', accountId, 'isLoading'], true),
|
||
3 years ago
|
suspended: state.getIn(['accounts', accountId, 'suspended'], false),
|
||
|
hidden: getAccountHidden(state, accountId),
|
||
3 years ago
|
blockedBy: state.getIn(['relationships', accountId, 'blocked_by'], false),
|
||
|
};
|
||
|
};
|
||
8 years ago
|
|
||
4 years ago
|
const RemoteHint = ({ url }) => (
|
||
|
<TimelineHint url={url} resource={<FormattedMessage id='timeline_hint.resources.followers' defaultMessage='Followers' />} />
|
||
|
);
|
||
|
|
||
|
RemoteHint.propTypes = {
|
||
|
url: PropTypes.string.isRequired,
|
||
|
};
|
||
|
|
||
6 years ago
|
export default @connect(mapStateToProps)
|
||
|
class Followers extends ImmutablePureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
3 years ago
|
params: PropTypes.shape({
|
||
3 years ago
|
acct: PropTypes.string,
|
||
|
id: PropTypes.string,
|
||
3 years ago
|
}).isRequired,
|
||
|
accountId: PropTypes.string,
|
||
8 years ago
|
dispatch: PropTypes.func.isRequired,
|
||
8 years ago
|
accountIds: ImmutablePropTypes.list,
|
||
8 years ago
|
hasMore: PropTypes.bool,
|
||
5 years ago
|
isLoading: PropTypes.bool,
|
||
6 years ago
|
blockedBy: PropTypes.bool,
|
||
6 years ago
|
isAccount: PropTypes.bool,
|
||
3 years ago
|
suspended: PropTypes.bool,
|
||
|
hidden: PropTypes.bool,
|
||
4 years ago
|
remote: PropTypes.bool,
|
||
|
remoteUrl: PropTypes.string,
|
||
5 years ago
|
multiColumn: PropTypes.bool,
|
||
8 years ago
|
};
|
||
8 years ago
|
|
||
3 years ago
|
_load () {
|
||
3 years ago
|
const { accountId, isAccount, dispatch } = this.props;
|
||
3 years ago
|
|
||
3 years ago
|
if (!isAccount) dispatch(fetchAccount(accountId));
|
||
3 years ago
|
dispatch(fetchFollowers(accountId));
|
||
|
}
|
||
|
|
||
|
componentDidMount () {
|
||
|
const { params: { acct }, accountId, dispatch } = this.props;
|
||
|
|
||
|
if (accountId) {
|
||
|
this._load();
|
||
|
} else {
|
||
|
dispatch(lookupAccount(acct));
|
||
5 years ago
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
3 years ago
|
componentDidUpdate (prevProps) {
|
||
|
const { params: { acct }, accountId, dispatch } = this.props;
|
||
|
|
||
|
if (prevProps.accountId !== accountId && accountId) {
|
||
|
this._load();
|
||
|
} else if (prevProps.params.acct !== acct) {
|
||
|
dispatch(lookupAccount(acct));
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
6 years ago
|
handleLoadMore = debounce(() => {
|
||
3 years ago
|
this.props.dispatch(expandFollowers(this.props.accountId));
|
||
6 years ago
|
}, 300, { leading: true });
|
||
8 years ago
|
|
||
8 years ago
|
render () {
|
||
3 years ago
|
const { accountId, accountIds, hasMore, blockedBy, isAccount, multiColumn, isLoading, suspended, hidden, remote, remoteUrl } = this.props;
|
||
6 years ago
|
|
||
|
if (!isAccount) {
|
||
|
return (
|
||
|
<Column>
|
||
|
<MissingIndicator />
|
||
|
</Column>
|
||
|
);
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
if (!accountIds) {
|
||
8 years ago
|
return (
|
||
|
<Column>
|
||
|
<LoadingIndicator />
|
||
|
</Column>
|
||
|
);
|
||
8 years ago
|
}
|
||
|
|
||
4 years ago
|
let emptyMessage;
|
||
|
|
||
3 years ago
|
const forceEmptyState = blockedBy || suspended || hidden;
|
||
|
|
||
|
if (suspended) {
|
||
|
emptyMessage = <FormattedMessage id='empty_column.account_suspended' defaultMessage='Account suspended' />;
|
||
|
} else if (hidden) {
|
||
|
emptyMessage = <LimitedAccountHint accountId={accountId} />;
|
||
|
} else if (blockedBy) {
|
||
4 years ago
|
emptyMessage = <FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' />;
|
||
|
} else if (remote && accountIds.isEmpty()) {
|
||
|
emptyMessage = <RemoteHint url={remoteUrl} />;
|
||
|
} else {
|
||
|
emptyMessage = <FormattedMessage id='account.followers.empty' defaultMessage='No one follows this user yet.' />;
|
||
|
}
|
||
|
|
||
|
const remoteMessage = remote ? <RemoteHint url={remoteUrl} /> : null;
|
||
8 years ago
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<Column>
|
||
5 years ago
|
<ColumnBackButton multiColumn={multiColumn} />
|
||
8 years ago
|
|
||
6 years ago
|
<ScrollableList
|
||
|
scrollKey='followers'
|
||
3 years ago
|
hasMore={!forceEmptyState && hasMore}
|
||
5 years ago
|
isLoading={isLoading}
|
||
6 years ago
|
onLoadMore={this.handleLoadMore}
|
||
3 years ago
|
prepend={<HeaderContainer accountId={this.props.accountId} hideTabs />}
|
||
6 years ago
|
alwaysPrepend
|
||
4 years ago
|
append={remoteMessage}
|
||
6 years ago
|
emptyMessage={emptyMessage}
|
||
5 years ago
|
bindToDocument={!multiColumn}
|
||
6 years ago
|
>
|
||
3 years ago
|
{forceEmptyState ? [] : accountIds.map(id =>
|
||
5 years ago
|
<AccountContainer key={id} id={id} withNote={false} />,
|
||
6 years ago
|
)}
|
||
|
</ScrollableList>
|
||
8 years ago
|
</Column>
|
||
8 years ago
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|