import classNames from 'classnames'; import { List as ImmutableList } from 'immutable'; import PropTypes from 'prop-types'; import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { defineMessages, injectIntl } from 'react-intl'; import { connect } from 'react-redux'; import { fetchDirectory, expandDirectory } from 'soapbox/actions/directory'; import LoadMore from 'soapbox/components/load_more'; import RadioButton from 'soapbox/components/radio_button'; import Column from 'soapbox/features/ui/components/column'; import { getFeatures } from 'soapbox/utils/features'; import AccountCard from './components/account_card'; 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), title: state.getIn(['instance', 'title']), features: getFeatures(state.get('instance')), }); export default @connect(mapStateToProps) @injectIntl class Directory extends React.PureComponent { static propTypes = { isLoading: PropTypes.bool, accountIds: ImmutablePropTypes.list.isRequired, dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, title: PropTypes.string.isRequired, params: PropTypes.shape({ order: PropTypes.string, local: PropTypes.bool, }), features: PropTypes.object.isRequired, }; state = { order: null, local: null, }; getParams = (props, state) => ({ order: state.order === null ? (props.params.order || 'active') : state.order, local: state.local === null ? (props.params.local || false) : state.local, }); 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)); } } handleChangeOrder = e => { this.setState({ order: e.target.value }); } handleChangeLocal = e => { this.setState({ local: e.target.value === '1' }); } handleLoadMore = () => { const { dispatch } = this.props; dispatch(expandDirectory(this.getParams(this.props, this.state))); } render() { const { isLoading, accountIds, intl, title, features } = this.props; const { order, local } = this.getParams(this.props, this.state); return (
{features.federating && (
)}
{accountIds.map(accountId => )}
); } }