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.

76 lines
2.3 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 'flavours/glitch/components/loading_indicator';
  6. import Column from 'flavours/glitch/features/ui/components/column';
  7. import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
  8. import { fetchLists } from 'flavours/glitch/actions/lists';
  9. import { defineMessages, injectIntl } from 'react-intl';
  10. import ImmutablePureComponent from 'react-immutable-pure-component';
  11. import ColumnLink from 'flavours/glitch/features/ui/components/column_link';
  12. import ColumnSubheading from 'flavours/glitch/features/ui/components/column_subheading';
  13. import NewListForm from './components/new_list_form';
  14. import { createSelector } from 'reselect';
  15. const messages = defineMessages({
  16. heading: { id: 'column.lists', defaultMessage: 'Lists' },
  17. subheading: { id: 'lists.subheading', defaultMessage: 'Your lists' },
  18. });
  19. const getOrderedLists = createSelector([state => state.get('lists')], lists => {
  20. if (!lists) {
  21. return lists;
  22. }
  23. return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
  24. });
  25. const mapStateToProps = state => ({
  26. lists: getOrderedLists(state),
  27. });
  28. @connect(mapStateToProps)
  29. @injectIntl
  30. export default 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. };
  37. componentWillMount () {
  38. this.props.dispatch(fetchLists());
  39. }
  40. render () {
  41. const { intl, lists } = this.props;
  42. if (!lists) {
  43. return (
  44. <Column>
  45. <LoadingIndicator />
  46. </Column>
  47. );
  48. }
  49. return (
  50. <Column icon='bars' heading={intl.formatMessage(messages.heading)}>
  51. <ColumnBackButtonSlim />
  52. <NewListForm />
  53. <div className='scrollable'>
  54. <ColumnSubheading text={intl.formatMessage(messages.subheading)} />
  55. {lists.map(list =>
  56. <ColumnLink key={list.get('id')} to={`/timelines/list/${list.get('id')}`} icon='list-ul' text={list.get('title')} />
  57. )}
  58. </div>
  59. </Column>
  60. );
  61. }
  62. }