2023-05-24 01:15:17 +10:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 18:52:27 +10:00
|
|
|
import { PureComponent } from 'react';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2019-08-30 08:14:36 +10:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import { Helmet } from 'react-helmet';
|
|
|
|
|
|
|
|
import { List as ImmutableList } from 'immutable';
|
2019-08-30 08:14:36 +10:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2024-01-13 07:16:48 +11:00
|
|
|
import PeopleIcon from 'mastodon/../material-icons/400-24px/group.svg?react';
|
2019-08-30 08:14:36 +10:00
|
|
|
import { addColumn, removeColumn, moveColumn, changeColumnParams } from 'mastodon/actions/columns';
|
|
|
|
import { fetchDirectory, expandDirectory } from 'mastodon/actions/directory';
|
2023-05-24 01:15:17 +10:00
|
|
|
import Column from 'mastodon/components/column';
|
|
|
|
import ColumnHeader from 'mastodon/components/column_header';
|
2023-06-06 19:28:50 +10:00
|
|
|
import { LoadMore } from 'mastodon/components/load_more';
|
2023-06-14 03:26:25 +10:00
|
|
|
import { LoadingIndicator } from 'mastodon/components/loading_indicator';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { RadioButton } from 'mastodon/components/radio_button';
|
|
|
|
import ScrollContainer from 'mastodon/containers/scroll_container';
|
|
|
|
|
|
|
|
import AccountCard from './components/account_card';
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
title: { id: 'column.directory', defaultMessage: 'Browse profiles' },
|
|
|
|
recentlyActive: { id: 'directory.recently_active', defaultMessage: 'Recently active' },
|
|
|
|
newArrivals: { id: 'directory.new_arrivals', defaultMessage: 'New arrivals' },
|
|
|
|
local: { id: 'directory.local', defaultMessage: 'From {domain} only' },
|
|
|
|
federated: { id: 'directory.federated', defaultMessage: 'From known fediverse' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
accountIds: state.getIn(['user_lists', 'directory', 'items'], ImmutableList()),
|
|
|
|
isLoading: state.getIn(['user_lists', 'directory', 'isLoading'], true),
|
|
|
|
domain: state.getIn(['meta', 'domain']),
|
|
|
|
});
|
|
|
|
|
2023-05-23 18:52:27 +10:00
|
|
|
class Directory extends PureComponent {
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
accountIds: ImmutablePropTypes.list.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
columnId: PropTypes.string,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
domain: PropTypes.string.isRequired,
|
|
|
|
params: PropTypes.shape({
|
|
|
|
order: PropTypes.string,
|
|
|
|
local: PropTypes.bool,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
order: null,
|
|
|
|
local: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
handlePin = () => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (columnId) {
|
|
|
|
dispatch(removeColumn(columnId));
|
|
|
|
} else {
|
|
|
|
dispatch(addColumn('DIRECTORY', this.getParams(this.props, this.state)));
|
|
|
|
}
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
getParams = (props, state) => ({
|
|
|
|
order: state.order === null ? (props.params.order || 'active') : state.order,
|
|
|
|
local: state.local === null ? (props.params.local || false) : state.local,
|
|
|
|
});
|
|
|
|
|
|
|
|
handleMove = dir => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
dispatch(moveColumn(columnId, dir));
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(fetchDirectory(this.getParams(this.props, this.state)));
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps, prevState) {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
const paramsOld = this.getParams(prevProps, prevState);
|
|
|
|
const paramsNew = this.getParams(this.props, this.state);
|
|
|
|
|
|
|
|
if (paramsOld.order !== paramsNew.order || paramsOld.local !== paramsNew.local) {
|
|
|
|
dispatch(fetchDirectory(paramsNew));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.column = c;
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
handleChangeOrder = e => {
|
|
|
|
const { dispatch, columnId } = this.props;
|
|
|
|
|
|
|
|
if (columnId) {
|
|
|
|
dispatch(changeColumnParams(columnId, ['order'], e.target.value));
|
|
|
|
} else {
|
|
|
|
this.setState({ order: e.target.value });
|
|
|
|
}
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
handleChangeLocal = e => {
|
|
|
|
const { dispatch, columnId } = this.props;
|
|
|
|
|
|
|
|
if (columnId) {
|
|
|
|
dispatch(changeColumnParams(columnId, ['local'], e.target.value === '1'));
|
|
|
|
} else {
|
|
|
|
this.setState({ local: e.target.value === '1' });
|
|
|
|
}
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
handleLoadMore = () => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(expandDirectory(this.getParams(this.props, this.state)));
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-08-30 08:14:36 +10:00
|
|
|
|
|
|
|
render () {
|
2021-07-13 23:45:17 +10:00
|
|
|
const { isLoading, accountIds, intl, columnId, multiColumn, domain } = this.props;
|
2019-08-30 08:14:36 +10:00
|
|
|
const { order, local } = this.getParams(this.props, this.state);
|
|
|
|
const pinned = !!columnId;
|
|
|
|
|
|
|
|
const scrollableArea = (
|
2022-03-07 21:38:52 +11:00
|
|
|
<div className='scrollable'>
|
2019-08-30 08:14:36 +10:00
|
|
|
<div className='filter-form'>
|
|
|
|
<div className='filter-form__column' role='group'>
|
|
|
|
<RadioButton name='order' value='active' label={intl.formatMessage(messages.recentlyActive)} checked={order === 'active'} onChange={this.handleChangeOrder} />
|
|
|
|
<RadioButton name='order' value='new' label={intl.formatMessage(messages.newArrivals)} checked={order === 'new'} onChange={this.handleChangeOrder} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='filter-form__column' role='group'>
|
|
|
|
<RadioButton name='local' value='1' label={intl.formatMessage(messages.local, { domain })} checked={local} onChange={this.handleChangeLocal} />
|
|
|
|
<RadioButton name='local' value='0' label={intl.formatMessage(messages.federated)} checked={!local} onChange={this.handleChangeLocal} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-03-07 21:38:52 +11:00
|
|
|
<div className='directory__list'>
|
|
|
|
{isLoading ? <LoadingIndicator /> : accountIds.map(accountId => (
|
|
|
|
<AccountCard id={accountId} key={accountId} />
|
|
|
|
))}
|
2019-08-30 08:14:36 +10:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<LoadMore onClick={this.handleLoadMore} visible={!isLoading} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.title)}>
|
|
|
|
<ColumnHeader
|
|
|
|
icon='address-book-o'
|
2023-10-25 04:45:08 +11:00
|
|
|
iconComponent={PeopleIcon}
|
2019-08-30 08:14:36 +10:00
|
|
|
title={intl.formatMessage(messages.title)}
|
|
|
|
onPin={this.handlePin}
|
|
|
|
onMove={this.handleMove}
|
|
|
|
onClick={this.handleHeaderClick}
|
|
|
|
pinned={pinned}
|
|
|
|
multiColumn={multiColumn}
|
|
|
|
/>
|
|
|
|
|
2021-07-13 23:45:17 +10:00
|
|
|
{multiColumn && !pinned ? <ScrollContainer scrollKey='directory'>{scrollableArea}</ScrollContainer> : scrollableArea}
|
2022-09-29 12:39:33 +10:00
|
|
|
|
|
|
|
<Helmet>
|
2022-10-09 12:55:09 +11:00
|
|
|
<title>{intl.formatMessage(messages.title)}</title>
|
2022-10-20 23:35:29 +11:00
|
|
|
<meta name='robots' content='noindex' />
|
2022-09-29 12:39:33 +10:00
|
|
|
</Helmet>
|
2019-08-30 08:14:36 +10:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 13:17:53 +11:00
|
|
|
|
|
|
|
export default connect(mapStateToProps)(injectIntl(Directory));
|