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.

87 lines
2.5 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 ReactSwipeable from 'react-swipeable';
  6. import { getPreviousLink, getNextLink } from './tabs_bar';
  7. import BundleContainer from '../containers/bundle_container';
  8. import ColumnLoading from './column_loading';
  9. import BundleColumnError from './bundle_column_error';
  10. import { Compose, Notifications, HomeTimeline, CommunityTimeline, PublicTimeline, HashtagTimeline } from '../../ui/util/async-components';
  11. const componentMap = {
  12. 'COMPOSE': Compose,
  13. 'HOME': HomeTimeline,
  14. 'NOTIFICATIONS': Notifications,
  15. 'PUBLIC': PublicTimeline,
  16. 'COMMUNITY': CommunityTimeline,
  17. 'HASHTAG': HashtagTimeline,
  18. };
  19. export default class ColumnsArea extends ImmutablePureComponent {
  20. static contextTypes = {
  21. router: PropTypes.object.isRequired,
  22. };
  23. static propTypes = {
  24. columns: ImmutablePropTypes.list.isRequired,
  25. singleColumn: PropTypes.bool,
  26. children: PropTypes.node,
  27. };
  28. handleRightSwipe = () => {
  29. const previousLink = getPreviousLink(this.context.router.history.location.pathname);
  30. if (previousLink) {
  31. this.context.router.history.push(previousLink);
  32. }
  33. }
  34. handleLeftSwipe = () => {
  35. const previousLink = getNextLink(this.context.router.history.location.pathname);
  36. if (previousLink) {
  37. this.context.router.history.push(previousLink);
  38. }
  39. };
  40. renderLoading = () => {
  41. return <ColumnLoading />;
  42. }
  43. renderError = (props) => {
  44. return <BundleColumnError {...props} />;
  45. }
  46. render () {
  47. const { columns, children, singleColumn } = this.props;
  48. if (singleColumn) {
  49. return (
  50. <ReactSwipeable onSwipedLeft={this.handleLeftSwipe} onSwipedRight={this.handleRightSwipe} delta={30} className='columns-area'>
  51. {children}
  52. </ReactSwipeable>
  53. );
  54. }
  55. return (
  56. <div className='columns-area'>
  57. {columns.map(column => {
  58. const params = column.get('params', null) === null ? null : column.get('params').toJS();
  59. return (
  60. <BundleContainer key={column.get('uuid')} fetchComponent={componentMap[column.get('id')]} loading={this.renderLoading} error={this.renderError}>
  61. {SpecificComponent => <SpecificComponent columnId={column.get('uuid')} params={params} multiColumn />}
  62. </BundleContainer>
  63. );
  64. })}
  65. {React.Children.map(children, child => React.cloneElement(child, { multiColumn: true }))}
  66. </div>
  67. );
  68. }
  69. }