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.

89 lines
2.9 KiB

  1. import PropTypes from 'prop-types';
  2. import React from 'react';
  3. import { Helmet } from 'react-helmet';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  7. import { connect } from 'react-redux';
  8. import { createSelector } from 'reselect';
  9. import { fetchLists } from 'flavours/glitch/actions/lists';
  10. import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
  11. import LoadingIndicator from 'flavours/glitch/components/loading_indicator';
  12. import ScrollableList from 'flavours/glitch/components/scrollable_list';
  13. import Column from 'flavours/glitch/features/ui/components/column';
  14. import ColumnLink from 'flavours/glitch/features/ui/components/column_link';
  15. import ColumnSubheading from 'flavours/glitch/features/ui/components/column_subheading';
  16. import NewListForm from './components/new_list_form';
  17. const messages = defineMessages({
  18. heading: { id: 'column.lists', defaultMessage: 'Lists' },
  19. subheading: { id: 'lists.subheading', defaultMessage: 'Your lists' },
  20. });
  21. const getOrderedLists = createSelector([state => state.get('lists')], lists => {
  22. if (!lists) {
  23. return lists;
  24. }
  25. return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
  26. });
  27. const mapStateToProps = state => ({
  28. lists: getOrderedLists(state),
  29. });
  30. class Lists extends ImmutablePureComponent {
  31. static propTypes = {
  32. params: PropTypes.object.isRequired,
  33. dispatch: PropTypes.func.isRequired,
  34. lists: ImmutablePropTypes.list,
  35. intl: PropTypes.object.isRequired,
  36. multiColumn: PropTypes.bool,
  37. };
  38. componentWillMount () {
  39. this.props.dispatch(fetchLists());
  40. }
  41. render () {
  42. const { intl, lists, multiColumn } = 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 bindToDocument={!multiColumn} icon='bars' heading={intl.formatMessage(messages.heading)}>
  53. <ColumnBackButtonSlim />
  54. <NewListForm />
  55. <ColumnSubheading text={intl.formatMessage(messages.subheading)} />
  56. <ScrollableList
  57. scrollKey='lists'
  58. emptyMessage={emptyMessage}
  59. bindToDocument={!multiColumn}
  60. >
  61. {lists.map(list =>
  62. <ColumnLink key={list.get('id')} to={`/lists/${list.get('id')}`} icon='list-ul' text={list.get('title')} />,
  63. )}
  64. </ScrollableList>
  65. <Helmet>
  66. <title>{intl.formatMessage(messages.heading)}</title>
  67. <meta name='robots' content='noindex' />
  68. </Helmet>
  69. </Column>
  70. );
  71. }
  72. }
  73. export default connect(mapStateToProps)(injectIntl(Lists));