2017-12-05 23:02:27 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 17:15:17 +02:00
|
|
|
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
|
2022-10-09 03:55:09 +02:00
|
|
|
import { Helmet } from 'react-helmet';
|
2023-05-23 17:15:17 +02:00
|
|
|
|
2017-12-05 23:02:27 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2022-10-09 03:55:09 +02:00
|
|
|
import { connect } from 'react-redux';
|
2017-12-05 23:02:27 +01:00
|
|
|
import { createSelector } from 'reselect';
|
2023-05-23 17:15:17 +02:00
|
|
|
|
2022-10-09 03:55:09 +02:00
|
|
|
import { fetchLists } from 'mastodon/actions/lists';
|
2022-11-05 23:06:32 +01:00
|
|
|
import Column from 'mastodon/components/column';
|
|
|
|
import ColumnHeader from 'mastodon/components/column_header';
|
2023-06-13 19:26:25 +02:00
|
|
|
import { LoadingIndicator } from 'mastodon/components/loading_indicator';
|
2023-05-23 17:15:17 +02:00
|
|
|
import ScrollableList from 'mastodon/components/scrollable_list';
|
2022-10-09 03:55:09 +02:00
|
|
|
import ColumnLink from 'mastodon/features/ui/components/column_link';
|
|
|
|
import ColumnSubheading from 'mastodon/features/ui/components/column_subheading';
|
2023-05-23 17:15:17 +02:00
|
|
|
|
2022-10-09 03:55:09 +02:00
|
|
|
import NewListForm from './components/new_list_form';
|
2017-12-05 23:02:27 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
heading: { id: 'column.lists', defaultMessage: 'Lists' },
|
|
|
|
subheading: { id: 'lists.subheading', defaultMessage: 'Your lists' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const getOrderedLists = createSelector([state => state.get('lists')], lists => {
|
|
|
|
if (!lists) {
|
|
|
|
return lists;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
lists: getOrderedLists(state),
|
|
|
|
});
|
|
|
|
|
2018-09-14 17:59:48 +02:00
|
|
|
class Lists extends ImmutablePureComponent {
|
2017-12-05 23:02:27 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
lists: ImmutablePropTypes.list,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2019-07-19 09:25:22 +02:00
|
|
|
multiColumn: PropTypes.bool,
|
2017-12-05 23:02:27 +01:00
|
|
|
};
|
|
|
|
|
2023-05-10 09:05:32 +02:00
|
|
|
UNSAFE_componentWillMount () {
|
2017-12-05 23:02:27 +01:00
|
|
|
this.props.dispatch(fetchLists());
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2021-07-13 15:45:17 +02:00
|
|
|
const { intl, lists, multiColumn } = this.props;
|
2017-12-05 23:02:27 +01:00
|
|
|
|
|
|
|
if (!lists) {
|
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<LoadingIndicator />
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-08-26 16:39:37 +02:00
|
|
|
const emptyMessage = <FormattedMessage id='empty_column.lists' defaultMessage="You don't have any lists yet. When you create one, it will show up here." />;
|
|
|
|
|
2017-12-05 23:02:27 +01:00
|
|
|
return (
|
2022-11-05 23:06:32 +01:00
|
|
|
<Column bindToDocument={!multiColumn} label={intl.formatMessage(messages.heading)}>
|
2023-07-23 17:55:20 +02:00
|
|
|
<ColumnHeader title={intl.formatMessage(messages.heading)} icon='list-ul' multiColumn={multiColumn} />
|
2017-12-05 23:02:27 +01:00
|
|
|
|
|
|
|
<NewListForm />
|
|
|
|
|
2018-08-26 16:39:37 +02:00
|
|
|
<ScrollableList
|
|
|
|
scrollKey='lists'
|
|
|
|
emptyMessage={emptyMessage}
|
2019-06-08 10:23:41 +02:00
|
|
|
prepend={<ColumnSubheading text={intl.formatMessage(messages.subheading)} />}
|
2019-07-19 09:25:22 +02:00
|
|
|
bindToDocument={!multiColumn}
|
2018-08-26 16:39:37 +02:00
|
|
|
>
|
2017-12-05 23:02:27 +01:00
|
|
|
{lists.map(list =>
|
2021-09-26 05:46:13 +02:00
|
|
|
<ColumnLink key={list.get('id')} to={`/lists/${list.get('id')}`} icon='list-ul' text={list.get('title')} />,
|
2017-12-05 23:02:27 +01:00
|
|
|
)}
|
2018-08-26 16:39:37 +02:00
|
|
|
</ScrollableList>
|
2022-10-09 03:55:09 +02:00
|
|
|
|
|
|
|
<Helmet>
|
|
|
|
<title>{intl.formatMessage(messages.heading)}</title>
|
2022-10-20 14:35:29 +02:00
|
|
|
<meta name='robots' content='noindex' />
|
2022-10-09 03:55:09 +02:00
|
|
|
</Helmet>
|
2017-12-05 23:02:27 +01:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 03:17:53 +01:00
|
|
|
|
|
|
|
export default connect(mapStateToProps)(injectIntl(Lists));
|