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