2017-05-03 01:04:16 +01:00
|
|
|
import React from 'react';
|
2016-11-13 19:42:54 +00:00
|
|
|
import { connect } from 'react-redux';
|
2018-07-29 15:52:06 +01:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-04-21 19:05:35 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-13 19:42:54 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2018-08-26 15:39:37 +01:00
|
|
|
import { debounce } from 'lodash';
|
2016-11-13 19:42:54 +00:00
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
|
|
|
import {
|
2021-09-26 04:46:13 +01:00
|
|
|
lookupAccount,
|
2021-09-27 06:23:48 +01:00
|
|
|
fetchAccount,
|
2016-11-13 19:42:54 +00:00
|
|
|
fetchFollowing,
|
2017-05-20 16:31:47 +01:00
|
|
|
expandFollowing,
|
2016-11-13 19:42:54 +00:00
|
|
|
} from '../../actions/accounts';
|
2018-08-26 15:39:37 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-11-20 18:39:18 +00:00
|
|
|
import AccountContainer from '../../containers/account_container';
|
2017-01-30 20:40:55 +00:00
|
|
|
import Column from '../ui/components/column';
|
|
|
|
import HeaderContainer from '../account_timeline/containers/header_container';
|
|
|
|
import ColumnBackButton from '../../components/column_back_button';
|
2018-08-26 15:39:37 +01:00
|
|
|
import ScrollableList from '../../components/scrollable_list';
|
2020-06-14 21:29:40 +01:00
|
|
|
import TimelineHint from 'mastodon/components/timeline_hint';
|
2022-05-10 08:44:35 +01:00
|
|
|
import LimitedAccountHint from '../account_timeline/components/limited_account_hint';
|
|
|
|
import { getAccountHidden } from 'mastodon/selectors';
|
2022-10-23 22:38:08 +01:00
|
|
|
import { normalizeForLookup } from 'mastodon/reducers/accounts_map';
|
2023-04-12 11:44:58 +01:00
|
|
|
import BundleColumnError from 'mastodon/features/ui/components/bundle_column_error';
|
2016-10-27 20:59:56 +01:00
|
|
|
|
2021-09-27 06:23:48 +01:00
|
|
|
const mapStateToProps = (state, { params: { acct, id } }) => {
|
2022-10-23 22:38:08 +01:00
|
|
|
const accountId = id || state.getIn(['accounts_map', normalizeForLookup(acct)]);
|
2021-09-26 04:46:13 +01:00
|
|
|
|
|
|
|
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', 'following', accountId, 'items']),
|
|
|
|
hasMore: !!state.getIn(['user_lists', 'following', accountId, 'next']),
|
|
|
|
isLoading: state.getIn(['user_lists', 'following', accountId, 'isLoading'], true),
|
2022-05-10 08:44:35 +01:00
|
|
|
suspended: state.getIn(['accounts', accountId, 'suspended'], false),
|
|
|
|
hidden: getAccountHidden(state, accountId),
|
2021-09-26 04:46:13 +01:00
|
|
|
blockedBy: state.getIn(['relationships', accountId, 'blocked_by'], false),
|
|
|
|
};
|
|
|
|
};
|
2016-10-27 20:59:56 +01:00
|
|
|
|
2020-06-14 21:29:40 +01:00
|
|
|
const RemoteHint = ({ url }) => (
|
|
|
|
<TimelineHint url={url} resource={<FormattedMessage id='timeline_hint.resources.follows' defaultMessage='Follows' />} />
|
|
|
|
);
|
|
|
|
|
|
|
|
RemoteHint.propTypes = {
|
|
|
|
url: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-09-14 16:59:48 +01:00
|
|
|
class Following extends ImmutablePureComponent {
|
2016-10-27 20:59:56 +01:00
|
|
|
|
2017-05-12 13:44:10 +01:00
|
|
|
static propTypes = {
|
2021-09-26 04:46:13 +01:00
|
|
|
params: PropTypes.shape({
|
2021-09-27 06:23:48 +01:00
|
|
|
acct: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
2021-09-26 04:46:13 +01:00
|
|
|
}).isRequired,
|
|
|
|
accountId: PropTypes.string,
|
2017-05-12 13:44:10 +01:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-05-20 16:31:47 +01:00
|
|
|
accountIds: ImmutablePropTypes.list,
|
2017-06-05 17:18:56 +01:00
|
|
|
hasMore: PropTypes.bool,
|
2020-04-12 12:38:00 +01:00
|
|
|
isLoading: PropTypes.bool,
|
2019-04-07 03:59:13 +01:00
|
|
|
blockedBy: PropTypes.bool,
|
2019-04-09 04:02:48 +01:00
|
|
|
isAccount: PropTypes.bool,
|
2022-05-10 08:44:35 +01:00
|
|
|
suspended: PropTypes.bool,
|
|
|
|
hidden: PropTypes.bool,
|
2020-06-14 21:29:40 +01:00
|
|
|
remote: PropTypes.bool,
|
|
|
|
remoteUrl: PropTypes.string,
|
2019-07-19 08:25:22 +01:00
|
|
|
multiColumn: PropTypes.bool,
|
2017-05-12 13:44:10 +01:00
|
|
|
};
|
2016-10-27 20:59:56 +01:00
|
|
|
|
2021-09-26 04:46:13 +01:00
|
|
|
_load () {
|
2021-09-27 06:23:48 +01:00
|
|
|
const { accountId, isAccount, dispatch } = this.props;
|
2021-09-26 04:46:13 +01:00
|
|
|
|
2021-09-27 06:23:48 +01:00
|
|
|
if (!isAccount) dispatch(fetchAccount(accountId));
|
2021-09-26 04:46:13 +01:00
|
|
|
dispatch(fetchFollowing(accountId));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (accountId) {
|
|
|
|
this._load();
|
|
|
|
} else {
|
|
|
|
dispatch(lookupAccount(acct));
|
2019-09-29 15:27:00 +01:00
|
|
|
}
|
2017-04-21 19:05:35 +01:00
|
|
|
}
|
2016-10-27 20:59:56 +01:00
|
|
|
|
2021-09-26 04:46:13 +01:00
|
|
|
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));
|
2016-10-27 20:59:56 +01:00
|
|
|
}
|
2017-04-21 19:05:35 +01:00
|
|
|
}
|
2016-10-27 20:59:56 +01:00
|
|
|
|
2018-08-26 15:39:37 +01:00
|
|
|
handleLoadMore = debounce(() => {
|
2021-09-26 04:46:13 +01:00
|
|
|
this.props.dispatch(expandFollowing(this.props.accountId));
|
2018-08-26 15:39:37 +01:00
|
|
|
}, 300, { leading: true });
|
2017-01-30 20:40:55 +00:00
|
|
|
|
2016-10-27 20:59:56 +01:00
|
|
|
render () {
|
2022-05-10 08:44:35 +01:00
|
|
|
const { accountId, accountIds, hasMore, blockedBy, isAccount, multiColumn, isLoading, suspended, hidden, remote, remoteUrl } = this.props;
|
2019-04-09 04:02:48 +01:00
|
|
|
|
|
|
|
if (!isAccount) {
|
|
|
|
return (
|
2023-04-12 11:44:58 +01:00
|
|
|
<BundleColumnError multiColumn={multiColumn} errorType='routing' />
|
2019-04-09 04:02:48 +01:00
|
|
|
);
|
|
|
|
}
|
2017-06-05 13:13:20 +01:00
|
|
|
|
2016-10-27 20:59:56 +01:00
|
|
|
if (!accountIds) {
|
2017-01-30 20:40:55 +00:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-27 20:59:56 +01:00
|
|
|
}
|
|
|
|
|
2020-06-14 21:29:40 +01:00
|
|
|
let emptyMessage;
|
|
|
|
|
2022-05-10 08:44:35 +01:00
|
|
|
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) {
|
2020-06-14 21:29:40 +01:00
|
|
|
emptyMessage = <FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' />;
|
|
|
|
} else if (remote && accountIds.isEmpty()) {
|
|
|
|
emptyMessage = <RemoteHint url={remoteUrl} />;
|
|
|
|
} else {
|
|
|
|
emptyMessage = <FormattedMessage id='account.follows.empty' defaultMessage="This user doesn't follow anyone yet." />;
|
|
|
|
}
|
|
|
|
|
|
|
|
const remoteMessage = remote ? <RemoteHint url={remoteUrl} /> : null;
|
2017-06-05 13:13:20 +01:00
|
|
|
|
2016-10-27 20:59:56 +01:00
|
|
|
return (
|
2017-01-30 20:40:55 +00:00
|
|
|
<Column>
|
2019-08-01 18:17:17 +01:00
|
|
|
<ColumnBackButton multiColumn={multiColumn} />
|
2017-01-31 21:34:33 +00:00
|
|
|
|
2018-08-26 15:39:37 +01:00
|
|
|
<ScrollableList
|
|
|
|
scrollKey='following'
|
2022-05-10 08:44:35 +01:00
|
|
|
hasMore={!forceEmptyState && hasMore}
|
2020-04-12 12:38:00 +01:00
|
|
|
isLoading={isLoading}
|
2018-08-26 15:39:37 +01:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2021-09-26 04:46:13 +01:00
|
|
|
prepend={<HeaderContainer accountId={this.props.accountId} hideTabs />}
|
2018-08-29 00:19:58 +01:00
|
|
|
alwaysPrepend
|
2020-06-14 21:29:40 +01:00
|
|
|
append={remoteMessage}
|
2018-08-26 15:39:37 +01:00
|
|
|
emptyMessage={emptyMessage}
|
2019-07-19 08:25:22 +01:00
|
|
|
bindToDocument={!multiColumn}
|
2018-08-26 15:39:37 +01:00
|
|
|
>
|
2022-05-10 08:44:35 +01:00
|
|
|
{forceEmptyState ? [] : accountIds.map(id =>
|
2020-03-08 15:02:36 +00:00
|
|
|
<AccountContainer key={id} id={id} withNote={false} />,
|
2018-08-26 15:39:37 +01:00
|
|
|
)}
|
|
|
|
</ScrollableList>
|
2017-01-30 20:40:55 +00:00
|
|
|
</Column>
|
2016-10-27 20:59:56 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 19:05:35 +01:00
|
|
|
}
|
2023-03-24 02:17:53 +00:00
|
|
|
|
|
|
|
export default connect(mapStateToProps)(Following);
|