index.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 'mastodon/actions/lists';
  10. import ColumnBackButtonSlim from 'mastodon/components/column_back_button_slim';
  11. import LoadingIndicator from 'mastodon/components/loading_indicator';
  12. import ScrollableList from 'mastodon/components/scrollable_list';
  13. import Column from 'mastodon/features/ui/components/column';
  14. import ColumnLink from 'mastodon/features/ui/components/column_link';
  15. import ColumnSubheading from 'mastodon/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. export default @connect(mapStateToProps)
  31. @injectIntl
  32. class Lists extends ImmutablePureComponent {
  33. static propTypes = {
  34. params: PropTypes.object.isRequired,
  35. dispatch: PropTypes.func.isRequired,
  36. lists: ImmutablePropTypes.list,
  37. intl: PropTypes.object.isRequired,
  38. multiColumn: PropTypes.bool,
  39. };
  40. componentWillMount () {
  41. this.props.dispatch(fetchLists());
  42. }
  43. render () {
  44. const { intl, lists, multiColumn } = this.props;
  45. if (!lists) {
  46. return (
  47. <Column>
  48. <LoadingIndicator />
  49. </Column>
  50. );
  51. }
  52. const emptyMessage = <FormattedMessage id='empty_column.lists' defaultMessage="You don't have any lists yet. When you create one, it will show up here." />;
  53. return (
  54. <Column bindToDocument={!multiColumn} icon='list-ul' heading={intl.formatMessage(messages.heading)}>
  55. <ColumnBackButtonSlim />
  56. <NewListForm />
  57. <ScrollableList
  58. scrollKey='lists'
  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={`/lists/${list.get('id')}`} icon='list-ul' text={list.get('title')} />,
  65. )}
  66. </ScrollableList>
  67. <Helmet>
  68. <title>{intl.formatMessage(messages.heading)}</title>
  69. <meta name='robots' content='noindex' />
  70. </Helmet>
  71. </Column>
  72. );
  73. }
  74. }