From 3955f1bf177d20753d00fcbc7627bed8be0309ce Mon Sep 17 00:00:00 2001 From: Grant Richmond Date: Sat, 8 Dec 2018 14:04:39 +0100 Subject: [PATCH] add shortcuts for all channel views --- src/components/GallerySlider/index.js | 1 + src/components/Layout/Classic/style.js | 1 + src/components/Layout/Gallery/index.js | 22 +++++++- src/components/Layout/Map/index.js | 74 ++++++++++++++++++++----- src/components/Layout/Shortcuts.js | 1 - src/components/Layout/Timeline/index.js | 27 ++++++--- src/components/Layout/Timeline/style.js | 5 ++ src/components/Layout/index.js | 1 - src/components/Map/Marker/index.js | 12 ++++ 9 files changed, 116 insertions(+), 28 deletions(-) diff --git a/src/components/GallerySlider/index.js b/src/components/GallerySlider/index.js index 375d63e..5015871 100644 --- a/src/components/GallerySlider/index.js +++ b/src/components/GallerySlider/index.js @@ -73,6 +73,7 @@ class Gallery extends Component { medias.find(media => media.postId) && width > alwaysOpenWidth return ( ({ width: '100%', height: '100%', overflow: 'hidden', + outline: 'none', zIndex: 1, }, previewColumn: { diff --git a/src/components/Layout/Gallery/index.js b/src/components/Layout/Gallery/index.js index 28fae1c..93036be 100644 --- a/src/components/Layout/Gallery/index.js +++ b/src/components/Layout/Gallery/index.js @@ -1,4 +1,4 @@ -import React, { Component, Fragment } from 'react' +import React, { Component } from 'react' import PropTypes from 'prop-types' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' @@ -10,6 +10,7 @@ import GridListTile from '@material-ui/core/GridListTile' import GridListTileBar from '@material-ui/core/GridListTileBar' import Button from '@material-ui/core/Button' import ReactList from 'react-list' +import Shortcuts from '../Shortcuts' import AuthorAvatar from '../../AuthorAvatar' import GallerySlider from '../../GallerySlider' import { updatePost, decrementChannelUnread } from '../../../actions' @@ -281,7 +282,22 @@ class Gallery extends Component { } = this.props const { medias, selectedMediaIndex } = this.state return ( - + { + if (selectedMediaIndex === false) { + this.setState({ selectedMediaIndex: 0 }) + } else { + this.setState({ selectedMediaIndex: selectedMediaIndex + 1 }) + } + }} + onPrevious={() => { + if (selectedMediaIndex > 0) { + this.setState({ selectedMediaIndex: selectedMediaIndex - 1 }) + } + }} + onMarkRead={() => {}} + className={classes.shortcuts} + >
)} - + ) } } diff --git a/src/components/Layout/Map/index.js b/src/components/Layout/Map/index.js index 655c154..e03690a 100644 --- a/src/components/Layout/Map/index.js +++ b/src/components/Layout/Map/index.js @@ -4,6 +4,7 @@ import { connect } from 'react-redux' import Map from 'pigeon-maps' import Overlay from 'pigeon-overlay' import WebMercatorViewport from 'viewport-mercator-project' +import Shortcuts from '../Shortcuts' import MapMarker from '../../Map/Marker' class CheckinMap extends Component { @@ -21,7 +22,9 @@ class CheckinMap extends Component { height: document.body.clientHeight - 64, // The toolbar is 64px tall, }), markers: [], + focusedPost: null, } + this.focusPost = this.focusPost.bind(this) this.setMarkers = this.setMarkers.bind(this) this.zoomToPosts = this.zoomToPosts.bind(this) } @@ -99,7 +102,8 @@ class CheckinMap extends Component { const viewport = Object.assign({}, this.state.viewport, { latitude: markers[0].lat, longitude: markers[0].lng, - zoom: this.state.viewport.zoom > 8 ? this.state.viewport.zoom : 11, + // zoom: this.state.viewport.zoom > 8 ? this.state.viewport.zoom : 11, + zoom: 12, }) this.setState({ viewport: new WebMercatorViewport(viewport) }) } @@ -116,8 +120,19 @@ class CheckinMap extends Component { } } + focusPost(postId) { + const { markers } = this.state + const index = markers.findIndex(marker => marker._id === postId) + if (index > -1) { + this.setState({ focusedPost: postId }) + this.zoomToPosts([markers[index]]) + } else { + this.setState({ focusedPost: null }) + } + } + render() { - const { viewport, markers } = this.state + const { viewport, markers, focusedPost } = this.state const { theme } = this.props const mapProps = { center: [viewport.latitude, viewport.longitude], @@ -132,18 +147,49 @@ class CheckinMap extends Component { : `https://a.tile.openstreetmap.se/hydda/full/${z}/${x}/${y}.png`, } return ( - - {markers.map((post, i) => { - return ( - - - - ) - })} - + { + if (focusedPost !== null) { + const index = markers.findIndex( + marker => marker._id === focusedPost + ) + if (index > -1 && markers[index + 1]) { + this.focusPost(markers[index + 1]._id) + } + } else if (focusedPost === null && markers.length) { + this.focusPost(markers[0]._id) + } + }} + onPrevious={() => { + if (focusedPost !== null) { + const index = markers.findIndex( + marker => marker._id === focusedPost + ) + if (index > 0 && markers[index - 1]) { + this.focusPost(markers[index - 1]._id) + } + } + }} + onMarkRead={() => {}} + > + + {markers.map((post, i) => { + return ( + + + + ) + })} + + ) } } diff --git a/src/components/Layout/Shortcuts.js b/src/components/Layout/Shortcuts.js index a271762..da78116 100644 --- a/src/components/Layout/Shortcuts.js +++ b/src/components/Layout/Shortcuts.js @@ -15,7 +15,6 @@ class LayoutShortcuts extends Component { componentWillReceiveProps(newProps) { const el = this.ref.current._domNode if (newProps.isFocused && el !== document.activeElement) { - console.log('Focusing layout on change') el.focus() } } diff --git a/src/components/Layout/Timeline/index.js b/src/components/Layout/Timeline/index.js index d8c8a36..2c64efc 100644 --- a/src/components/Layout/Timeline/index.js +++ b/src/components/Layout/Timeline/index.js @@ -7,6 +7,7 @@ import 'intersection-observer' import Observer from '@researchgate/react-intersection-observer' import Button from '@material-ui/core/Button' import ReactList from 'react-list' +import Shortcuts from '../Shortcuts' import Post from '../../Post' import { updatePost, decrementChannelUnread } from '../../../actions' import getChannelSetting from '../../../modules/get-channel-setting' @@ -17,6 +18,7 @@ class Timeline extends Component { constructor(props) { super(props) this.state = {} + this.ref = React.createRef() this.handleIntersection = this.handleIntersection.bind(this) this.renderItem = this.renderItem.bind(this) this.renderLoadMore = this.renderLoadMore.bind(this) @@ -113,15 +115,22 @@ class Timeline extends Component { render() { const { classes, posts } = this.props return ( -
- - {this.renderLoadMore()} -
+ this.ref.current.scrollBy(0, 50)} + onPrevious={() => this.ref.current.scrollBy(0, -50)} + onMarkRead={() => {}} + className={classes.shortcuts} + > +
+ + {this.renderLoadMore()} +
+
) } } diff --git a/src/components/Layout/Timeline/style.js b/src/components/Layout/Timeline/style.js index d827167..046b80b 100644 --- a/src/components/Layout/Timeline/style.js +++ b/src/components/Layout/Timeline/style.js @@ -1,5 +1,6 @@ export default theme => ({ timeline: { + display: 'block', boxSizing: 'border-box', width: '100%', height: '100%', @@ -7,10 +8,14 @@ export default theme => ({ paddingTop: 0, overflow: 'auto', overscrollBehaviorY: 'contain', + outline: 'none', '& > div': { maxWidth: 600, }, }, + shortcuts: { + outline: 'none', + }, loadMore: { display: 'block', width: '100%', diff --git a/src/components/Layout/index.js b/src/components/Layout/index.js index 4bbfe05..53c5081 100644 --- a/src/components/Layout/index.js +++ b/src/components/Layout/index.js @@ -132,7 +132,6 @@ class MainPosts extends Component { } if (timelineAfter) { query.after = timelineAfter - console.log('getting old posts') } try { const res = await postsService.find({ diff --git a/src/components/Map/Marker/index.js b/src/components/Map/Marker/index.js index a53f338..056b3b1 100644 --- a/src/components/Map/Marker/index.js +++ b/src/components/Map/Marker/index.js @@ -17,6 +17,16 @@ class MapMarker extends Component { this.renderPost = this.renderPost.bind(this) } + componentDidUpdate(prevProps) { + if (prevProps.postOpen !== this.props.postOpen) { + if (this.props.postOpen && !this.state.postOpen) { + this.setState({ postOpen: true }) + } else if (!this.props.postOpen && this.state.postOpen) { + this.setState({ postOpen: false }) + } + } + } + handleClick(e) { e.preventDefault() this.setState({ @@ -31,6 +41,7 @@ class MapMarker extends Component { } return (