diff options
author | Sorin Davidoi <sorin.davidoi@gmail.com> | 2017-06-08 17:41:32 +0200 |
---|---|---|
committer | Sorin Davidoi <sorin.davidoi@gmail.com> | 2017-06-23 13:48:46 +0200 |
commit | a6d8d1036a1a4336cb8fde6e3c318685cf6a7226 (patch) | |
tree | c4f9e07f94dd3183c25881008e8a8aa959957a4c /app/javascript/mastodon/features/ui/components/columns_area.js | |
parent | 3d403a013d3ad4878d47b8dbd24ce371efecdfbf (diff) |
feat: Swipeable columns
Diffstat (limited to 'app/javascript/mastodon/features/ui/components/columns_area.js')
-rw-r--r-- | app/javascript/mastodon/features/ui/components/columns_area.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/app/javascript/mastodon/features/ui/components/columns_area.js b/app/javascript/mastodon/features/ui/components/columns_area.js index 6ed8bc20d..43be34840 100644 --- a/app/javascript/mastodon/features/ui/components/columns_area.js +++ b/app/javascript/mastodon/features/ui/components/columns_area.js @@ -2,12 +2,14 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; +import ReactSwipeable from 'react-swipeable'; import HomeTimeline from '../../home_timeline'; import Notifications from '../../notifications'; import PublicTimeline from '../../public_timeline'; import CommunityTimeline from '../../community_timeline'; import HashtagTimeline from '../../hashtag_timeline'; import Compose from '../../compose'; +import { getPreviousLink, getNextLink } from './tabs_bar'; const componentMap = { 'COMPOSE': Compose, @@ -20,20 +22,40 @@ const componentMap = { class ColumnsArea extends ImmutablePureComponent { + static contextTypes = { + router: PropTypes.object.isRequired, + }; + static propTypes = { columns: ImmutablePropTypes.list.isRequired, singleColumn: PropTypes.bool, children: PropTypes.node, }; + handleRightSwipe = () => { + const previousLink = getPreviousLink(this.context.router.history.location.pathname); + + if (previousLink) { + this.context.router.history.push(previousLink); + } + } + + handleLeftSwipe = () => { + const previousLink = getNextLink(this.context.router.history.location.pathname); + + if (previousLink) { + this.context.router.history.push(previousLink); + } + }; + render () { const { columns, children, singleColumn } = this.props; if (singleColumn) { return ( - <div className='columns-area'> + <ReactSwipeable onSwipedLeft={this.handleLeftSwipe} onSwipedRight={this.handleRightSwipe} className='columns-area'> {children} - </div> + </ReactSwipeable> ); } |