You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import LoadingIndicator from '../../components/loading_indicator';
  6. import Column from '../ui/components/column';
  7. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  8. import { fetchLists } from '../../actions/lists';
  9. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  10. import ImmutablePureComponent from 'react-immutable-pure-component';
  11. import ColumnLink from '../ui/components/column_link';
  12. import ColumnSubheading from '../ui/components/column_subheading';
  13. import NewListForm from './components/new_list_form';
  14. import { createSelector } from 'reselect';
  15. import ScrollableList from '../../components/scrollable_list';
  16. const messages = defineMessages({
  17. heading: { id: 'column.lists', defaultMessage: 'Lists' },
  18. subheading: { id: 'lists.subheading', defaultMessage: 'Your lists' },
  19. });
  20. const getOrderedLists = createSelector([state => state.get('lists')], lists => {
  21. if (!lists) {
  22. return lists;
  23. }
  24. return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
  25. });
  26. const mapStateToProps = state => ({
  27. lists: getOrderedLists(state),
  28. });
  29. export default @connect(mapStateToProps)
  30. @injectIntl
  31. class Lists extends ImmutablePureComponent {
  32. static propTypes = {
  33. params: PropTypes.object.isRequired,
  34. dispatch: PropTypes.func.isRequired,
  35. lists: ImmutablePropTypes.list,
  36. intl: PropTypes.object.isRequired,
  37. };
  38. componentWillMount () {
  39. this.props.dispatch(fetchLists());
  40. }
  41. render () {
  42. const { intl, shouldUpdateScroll, lists } = this.props;
  43. if (!lists) {
  44. return (
  45. <Column>
  46. <LoadingIndicator />
  47. </Column>
  48. );
  49. }
  50. const emptyMessage = <FormattedMessage id='empty_column.lists' defaultMessage="You don't have any lists yet. When you create one, it will show up here." />;
  51. return (
  52. <Column icon='list-ul' heading={intl.formatMessage(messages.heading)}>
  53. <ColumnBackButtonSlim />
  54. <NewListForm />
  55. <ScrollableList
  56. scrollKey='lists'
  57. shouldUpdateScroll={shouldUpdateScroll}
  58. emptyMessage={emptyMessage}
  59. prepend={<ColumnSubheading text={intl.formatMessage(messages.subheading)} />}
  60. >
  61. {lists.map(list =>
  62. <ColumnLink key={list.get('id')} to={`/timelines/list/${list.get('id')}`} icon='list-ul' text={list.get('title')} />
  63. )}
  64. </ScrollableList>
  65. </Column>
  66. );
  67. }
  68. }