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