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