2017-05-03 09:04:16 +09:00
|
|
|
import React from 'react';
|
2016-11-14 04:42:54 +09:00
|
|
|
import { connect } from 'react-redux';
|
2018-07-29 23:52:06 +09:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-14 04:42:54 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2018-08-26 23:39:37 +09:00
|
|
|
import { debounce } from 'lodash';
|
2016-11-14 04:42:54 +09:00
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
|
|
|
import {
|
2021-09-26 12:46:13 +09:00
|
|
|
lookupAccount,
|
2016-11-14 04:42:54 +09:00
|
|
|
fetchFollowing,
|
2017-05-21 00:31:47 +09:00
|
|
|
expandFollowing,
|
2016-11-14 04:42:54 +09:00
|
|
|
} from '../../actions/accounts';
|
2018-08-26 23:39:37 +09:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-11-21 03:39:18 +09:00
|
|
|
import AccountContainer from '../../containers/account_container';
|
2017-01-31 05:40:55 +09: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 23:39:37 +09:00
|
|
|
import ScrollableList from '../../components/scrollable_list';
|
2019-04-09 12:02:48 +09:00
|
|
|
import MissingIndicator from 'mastodon/components/missing_indicator';
|
2020-06-15 05:29:40 +09:00
|
|
|
import TimelineHint from 'mastodon/components/timeline_hint';
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2021-09-26 12:46:13 +09:00
|
|
|
const mapStateToProps = (state, { params: { acct } }) => {
|
|
|
|
const accountId = state.getIn(['accounts_map', acct]);
|
|
|
|
|
|
|
|
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),
|
|
|
|
blockedBy: state.getIn(['relationships', accountId, 'blocked_by'], false),
|
|
|
|
};
|
|
|
|
};
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2020-06-15 05:29:40 +09:00
|
|
|
const RemoteHint = ({ url }) => (
|
|
|
|
<TimelineHint url={url} resource={<FormattedMessage id='timeline_hint.resources.follows' defaultMessage='Follows' />} />
|
|
|
|
);
|
|
|
|
|
|
|
|
RemoteHint.propTypes = {
|
|
|
|
url: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-09-15 00:59:48 +09:00
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
class Following extends ImmutablePureComponent {
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
2021-09-26 12:46:13 +09:00
|
|
|
params: PropTypes.shape({
|
|
|
|
acct: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
accountId: PropTypes.string,
|
2017-05-12 21:44:10 +09:00
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-05-21 00:31:47 +09:00
|
|
|
accountIds: ImmutablePropTypes.list,
|
2017-06-06 01:18:56 +09:00
|
|
|
hasMore: PropTypes.bool,
|
2020-04-12 20:38:00 +09:00
|
|
|
isLoading: PropTypes.bool,
|
2019-04-07 11:59:13 +09:00
|
|
|
blockedBy: PropTypes.bool,
|
2019-04-09 12:02:48 +09:00
|
|
|
isAccount: PropTypes.bool,
|
2020-06-15 05:29:40 +09:00
|
|
|
remote: PropTypes.bool,
|
|
|
|
remoteUrl: PropTypes.string,
|
2019-07-19 16:25:22 +09:00
|
|
|
multiColumn: PropTypes.bool,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2021-09-26 12:46:13 +09:00
|
|
|
_load () {
|
|
|
|
const { accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(fetchFollowing(accountId));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { params: { acct }, accountId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (accountId) {
|
|
|
|
this._load();
|
|
|
|
} else {
|
|
|
|
dispatch(lookupAccount(acct));
|
2019-09-29 23:27:00 +09:00
|
|
|
}
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2021-09-26 12:46:13 +09: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-28 04:59:56 +09:00
|
|
|
}
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2018-08-26 23:39:37 +09:00
|
|
|
handleLoadMore = debounce(() => {
|
2021-09-26 12:46:13 +09:00
|
|
|
this.props.dispatch(expandFollowing(this.props.accountId));
|
2018-08-26 23:39:37 +09:00
|
|
|
}, 300, { leading: true });
|
2017-01-31 05:40:55 +09:00
|
|
|
|
2016-10-28 04:59:56 +09:00
|
|
|
render () {
|
2021-07-13 22:45:17 +09:00
|
|
|
const { accountIds, hasMore, blockedBy, isAccount, multiColumn, isLoading, remote, remoteUrl } = this.props;
|
2019-04-09 12:02:48 +09:00
|
|
|
|
|
|
|
if (!isAccount) {
|
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<MissingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
2017-06-05 21:13:20 +09:00
|
|
|
|
2016-10-28 04:59:56 +09:00
|
|
|
if (!accountIds) {
|
2017-01-31 05:40:55 +09:00
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
2016-10-28 04:59:56 +09:00
|
|
|
}
|
|
|
|
|
2020-06-15 05:29:40 +09:00
|
|
|
let emptyMessage;
|
|
|
|
|
|
|
|
if (blockedBy) {
|
|
|
|
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 21:13:20 +09:00
|
|
|
|
2016-10-28 04:59:56 +09:00
|
|
|
return (
|
2017-01-31 05:40:55 +09:00
|
|
|
<Column>
|
2019-08-02 02:17:17 +09:00
|
|
|
<ColumnBackButton multiColumn={multiColumn} />
|
2017-02-01 06:34:33 +09:00
|
|
|
|
2018-08-26 23:39:37 +09:00
|
|
|
<ScrollableList
|
|
|
|
scrollKey='following'
|
|
|
|
hasMore={hasMore}
|
2020-04-12 20:38:00 +09:00
|
|
|
isLoading={isLoading}
|
2018-08-26 23:39:37 +09:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2021-09-26 12:46:13 +09:00
|
|
|
prepend={<HeaderContainer accountId={this.props.accountId} hideTabs />}
|
2018-08-29 08:19:58 +09:00
|
|
|
alwaysPrepend
|
2020-06-15 05:29:40 +09:00
|
|
|
append={remoteMessage}
|
2018-08-26 23:39:37 +09:00
|
|
|
emptyMessage={emptyMessage}
|
2019-07-19 16:25:22 +09:00
|
|
|
bindToDocument={!multiColumn}
|
2018-08-26 23:39:37 +09:00
|
|
|
>
|
2019-04-07 11:59:13 +09:00
|
|
|
{blockedBy ? [] : accountIds.map(id =>
|
2020-03-09 00:02:36 +09:00
|
|
|
<AccountContainer key={id} id={id} withNote={false} />,
|
2018-08-26 23:39:37 +09:00
|
|
|
)}
|
|
|
|
</ScrollableList>
|
2017-01-31 05:40:55 +09:00
|
|
|
</Column>
|
2016-10-28 04:59:56 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|