2017-12-06 09:02:27 +11:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import LoadingIndicator from '../../components/loading_indicator';
|
|
|
|
import Column from '../ui/components/column';
|
|
|
|
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
|
|
|
|
import { fetchLists } from '../../actions/lists';
|
2018-08-27 00:39:37 +10:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
2017-12-06 09:02:27 +11:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import ColumnLink from '../ui/components/column_link';
|
|
|
|
import ColumnSubheading from '../ui/components/column_subheading';
|
|
|
|
import NewListForm from './components/new_list_form';
|
|
|
|
import { createSelector } from 'reselect';
|
2018-08-27 00:39:37 +10:00
|
|
|
import ScrollableList from '../../components/scrollable_list';
|
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),
|
|
|
|
});
|
|
|
|
|
|
|
|
@connect(mapStateToProps)
|
|
|
|
@injectIntl
|
|
|
|
export default class Lists extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
lists: ImmutablePropTypes.list,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
this.props.dispatch(fetchLists());
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-08-27 00:39:37 +10:00
|
|
|
const { intl, shouldUpdateScroll, lists } = 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 (
|
2018-06-18 23:33:11 +10:00
|
|
|
<Column icon='list-ul' heading={intl.formatMessage(messages.heading)}>
|
2017-12-06 09:02:27 +11:00
|
|
|
<ColumnBackButtonSlim />
|
|
|
|
|
|
|
|
<NewListForm />
|
|
|
|
|
2018-08-27 00:39:37 +10:00
|
|
|
<ColumnSubheading text={intl.formatMessage(messages.subheading)} />
|
|
|
|
<ScrollableList
|
|
|
|
scrollKey='lists'
|
|
|
|
shouldUpdateScroll={shouldUpdateScroll}
|
|
|
|
emptyMessage={emptyMessage}
|
|
|
|
>
|
2017-12-06 09:02:27 +11:00
|
|
|
{lists.map(list =>
|
2018-06-18 23:33:11 +10:00
|
|
|
<ColumnLink key={list.get('id')} to={`/timelines/list/${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>
|
2017-12-06 09:02:27 +11:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|