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.

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