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.

84 lines
2.7 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. multiColumn: PropTypes.bool,
  38. };
  39. componentWillMount () {
  40. this.props.dispatch(fetchLists());
  41. }
  42. render () {
  43. const { intl, shouldUpdateScroll, lists, multiColumn } = this.props;
  44. if (!lists) {
  45. return (
  46. <Column>
  47. <LoadingIndicator />
  48. </Column>
  49. );
  50. }
  51. const emptyMessage = <FormattedMessage id='empty_column.lists' defaultMessage="You don't have any lists yet. When you create one, it will show up here." />;
  52. return (
  53. <Column icon='list-ul' heading={intl.formatMessage(messages.heading)}>
  54. <ColumnBackButtonSlim />
  55. <NewListForm />
  56. <ScrollableList
  57. scrollKey='lists'
  58. shouldUpdateScroll={shouldUpdateScroll}
  59. emptyMessage={emptyMessage}
  60. prepend={<ColumnSubheading text={intl.formatMessage(messages.subheading)} />}
  61. bindToDocument={!multiColumn}
  62. >
  63. {lists.map(list =>
  64. <ColumnLink key={list.get('id')} to={`/timelines/list/${list.get('id')}`} icon='list-ul' text={list.get('title')} />
  65. )}
  66. </ScrollableList>
  67. </Column>
  68. );
  69. }
  70. }