index.jsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import PropTypes from 'prop-types';
  2. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  3. import { Helmet } from 'react-helmet';
  4. import { createSelector } from '@reduxjs/toolkit';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import ImmutablePureComponent from 'react-immutable-pure-component';
  7. import { connect } from 'react-redux';
  8. import ListAltIcon from '@/material-icons/400-24px/list_alt.svg?react';
  9. import { fetchLists } from 'mastodon/actions/lists';
  10. import Column from 'mastodon/components/column';
  11. import ColumnHeader from 'mastodon/components/column_header';
  12. import { LoadingIndicator } from 'mastodon/components/loading_indicator';
  13. import ScrollableList from 'mastodon/components/scrollable_list';
  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. 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. UNSAFE_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} label={intl.formatMessage(messages.heading)}>
  53. <ColumnHeader title={intl.formatMessage(messages.heading)} icon='list-ul' iconComponent={ListAltIcon} multiColumn={multiColumn} />
  54. <NewListForm />
  55. <ScrollableList
  56. scrollKey='lists'
  57. emptyMessage={emptyMessage}
  58. prepend={<ColumnSubheading text={intl.formatMessage(messages.subheading)} />}
  59. bindToDocument={!multiColumn}
  60. >
  61. {lists.map(list =>
  62. <ColumnLink key={list.get('id')} to={`/lists/${list.get('id')}`} icon='list-ul' iconComponent={ListAltIcon} 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));