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.

55 lines
1.4 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import { fetchLists } from 'mastodon/actions/lists';
  6. import { connect } from 'react-redux';
  7. import { createSelector } from 'reselect';
  8. import { NavLink, withRouter } from 'react-router-dom';
  9. import Icon from 'mastodon/components/icon';
  10. const getOrderedLists = createSelector([state => state.get('lists')], lists => {
  11. if (!lists) {
  12. return lists;
  13. }
  14. return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
  15. });
  16. const mapStateToProps = state => ({
  17. lists: getOrderedLists(state),
  18. });
  19. export default @withRouter
  20. @connect(mapStateToProps)
  21. class ListPanel extends ImmutablePureComponent {
  22. static propTypes = {
  23. dispatch: PropTypes.func.isRequired,
  24. lists: ImmutablePropTypes.list,
  25. };
  26. componentDidMount () {
  27. const { dispatch } = this.props;
  28. dispatch(fetchLists());
  29. }
  30. render () {
  31. const { lists } = this.props;
  32. if (!lists) {
  33. return null;
  34. }
  35. return (
  36. <div>
  37. <hr />
  38. {lists.map(list => (
  39. <NavLink key={list.get('id')} className='column-link column-link--transparent' strict to={`/timelines/list/${list.get('id')}`}><Icon className='column-link__icon' id='list-ul' fixedWidth />{list.get('title')}</NavLink>
  40. ))}
  41. </div>
  42. );
  43. }
  44. }