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