Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Collapse sidebar when in mobile #1806

Benjamin Kinge21236faf9e5
diff --git a/web/js/components/animation-widget/play-queue.js b/web/js/components/animation-widget/play-queue.js
index d9195116a..fc79d0778 100644
--- a/web/js/components/animation-widget/play-queue.js
+++ b/web/js/components/animation-widget/play-queue.js
@@ -493,7 +493,6 @@ class PlayAnimation extends React.Component {
if (!this.mounted) return clearInterval(this.interval);
this.shiftCache();
this.checkQueue(queueLength, currentPlayingDate);
-
if (this.props.isPlaying) {
selectDate(util.parseDateUTC(currentPlayingDate));
}
diff --git a/web/js/containers/sidebar/sidebar.js b/web/js/containers/sidebar/sidebar.js
index 3c48b533a..ef0c062b0 100644
--- a/web/js/containers/sidebar/sidebar.js
+++ b/web/js/containers/sidebar/sidebar.js
@@ -10,7 +10,10 @@ import { TabContent, TabPane } from 'reactstrap';
import CollapsedButton from '../../components/sidebar/collapsed-button';
import NavCase from '../../components/sidebar/nav/nav-case';
import googleTagManager from 'googleTagManager';
-import { getCheckerboard, loadCustom as loadCustomPalette } from '../../modules/palettes/util';
+import {
+ getCheckerboard,
+ loadCustom as loadCustomPalette
+} from '../../modules/palettes/util';
import { loadedCustomPalettes } from '../../modules/palettes/actions';
import { getLayers } from '../../modules/layers/selectors';
import ErrorBoundary from '../error-boundary';
@@ -102,8 +105,16 @@ class Sidebar extends React.Component {
}
}
toggleSidebar() {
- const { isCollapsed, collapseExpandToggle, hasLocalStorage } = this.props;
+ const {
+ isCollapsed,
+ collapseExpandToggle,
+ hasLocalStorage,
+ isMobile
+ } = this.props;
var isNowCollapsed = !isCollapsed;
+ if (isMobile) {
+ return collapseExpandToggle();
+ }
googleTagManager.pushEvent({
event: 'sidebar_chevron'
});
@@ -219,23 +230,24 @@ class Sidebar extends React.Component {
function mapStateToProps(state) {
const { browser, sidebar, compare, layers, config, modal, animation } = state;
const { screenHeight } = browser;
- const { activeTab, isCollapsed } = sidebar;
+ const { activeTab, isCollapsed, mobileCollapsed } = sidebar;
const { activeString } = compare;
const numberOfLayers = getLayers(layers[activeString], {}, state).length;
const tabTypes = getActiveTabs(config);
-
+ const isMobile = browser.lessThan.medium;
return {
activeTab,
- isMobile: browser.lessThan.medium,
+ isMobile,
hasLocalStorage: util.browser.localStorage,
screenHeight: screenHeight,
isCompareMode: compare.active,
activeString,
numberOfLayers,
- isCollapsed:
- isCollapsed ||
- (modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT') ||
- animation.gifActive, // Collapse when Image download / GIF is open,
+ isCollapsed: isMobile
+ ? mobileCollapsed
+ : isCollapsed ||
+ (modal.isOpen && modal.id === 'TOOLBAR_SNAPSHOT') ||
+ animation.gifActive, // Collapse when Image download / GIF is open,
tabTypes,
config
};
diff --git a/web/js/modules/sidebar/actions.js b/web/js/modules/sidebar/actions.js
index 2b82d21fb..6fe70824a 100644
--- a/web/js/modules/sidebar/actions.js
+++ b/web/js/modules/sidebar/actions.js
@@ -2,7 +2,10 @@ import {
CHANGE_TAB,
TOGGLE_COLLAPSE,
COLLAPSE_SIDEBAR,
- EXPAND_SIDEBAR
+ EXPAND_SIDEBAR,
+ TOGGLE_MOBILE_COLLAPSE,
+ MOBILE_COLLAPSE_SIDEBAR,
+ MOBILE_EXPAND_SIDEBAR
} from './constants';
export function changeTab(str) {
@@ -12,19 +15,34 @@ export function changeTab(str) {
};
}
export function toggleSidebarCollapse(str) {
- return {
- type: TOGGLE_COLLAPSE
+ return (dispatch, getState) => {
+ const isMobile = getState().browser.lessThan.medium;
+ if (isMobile) {
+ dispatch({ type: TOGGLE_MOBILE_COLLAPSE });
+ } else {
+ dispatch({ type: TOGGLE_COLLAPSE });
+ }
};
}
export function collapseSidebar(str) {
- return {
- type: COLLAPSE_SIDEBAR
+ return (dispatch, getState) => {
+ const isMobile = getState().browser.lessThan.medium;
+ if (isMobile) {
+ dispatch({ type: MOBILE_COLLAPSE_SIDEBAR });
+ } else {
+ dispatch({ type: COLLAPSE_SIDEBAR });
+ }
};
}
export function expandSidebar(str) {
- return {
- type: EXPAND_SIDEBAR
+ return (dispatch, getState) => {
+ const isMobile = getState().browser.lessThan.medium;
+ if (isMobile) {
+ dispatch({ type: MOBILE_EXPAND_SIDEBAR });
+ } else {
+ dispatch({ type: EXPAND_SIDEBAR });
+ }
};
}
diff --git a/web/js/modules/sidebar/constants.js b/web/js/modules/sidebar/constants.js
index 7a9c482f5..1e65b5faf 100644
--- a/web/js/modules/sidebar/constants.js
+++ b/web/js/modules/sidebar/constants.js
@@ -1,5 +1,7 @@
-export const CHANGE_TAB = 'CHANGE_ACTIVE_SIDEBAR_TAB';
-
-export const TOGGLE_COLLAPSE = 'TOGGLE_SIDEBAR_COLLAPSE_EXAPND';
-export const COLLAPSE_SIDEBAR = 'SIDEBAR_COLLAPSE_NOW';
-export const EXPAND_SIDEBAR = 'SIDEBAR_EXPAND_NOW';
+export const CHANGE_TAB = 'SIDEBAR/CHANGE_ACTIVE_TAB';
+export const TOGGLE_COLLAPSE = 'SIDEBAR/TOGGLE_COLLAPSE_EXAPND';
+export const COLLAPSE_SIDEBAR = 'SIDEBAR/COLLAPSE_NOW';
+export const EXPAND_SIDEBAR = 'SIDEBAR/EXPAND_NOW';
+export const TOGGLE_MOBILE_COLLAPSE = 'SIDEBAR/TOGGLE_MOBILE_COLLAPSE';
+export const MOBILE_COLLAPSE_SIDEBAR = 'SIDEBAR/MOBILE_COLLAPSE_SIDEBAR';
+export const MOBILE_EXPAND_SIDEBAR = 'SIDEBAR/MOBILE_EXPAND_SIDEBAR';
diff --git a/web/js/modules/sidebar/reducers.js b/web/js/modules/sidebar/reducers.js
index ec0c4c378..c6006c988 100644
--- a/web/js/modules/sidebar/reducers.js
+++ b/web/js/modules/sidebar/reducers.js
@@ -2,7 +2,10 @@ import {
CHANGE_TAB,
TOGGLE_COLLAPSE,
COLLAPSE_SIDEBAR,
- EXPAND_SIDEBAR
+ EXPAND_SIDEBAR,
+ TOGGLE_MOBILE_COLLAPSE,
+ MOBILE_COLLAPSE_SIDEBAR,
+ MOBILE_EXPAND_SIDEBAR
} from './constants';
import { assign as lodashAssign } from 'lodash';
import util from '../../util/util';
@@ -11,9 +14,10 @@ const wasCallapseRequested = util.browser.localStorage
? localStorage.getItem('sidebarState') === 'collapsed'
: false;
export const sidebarState = {
- isCollapsed: util.browser.small ? true : wasCallapseRequested || false,
+ isCollapsed: wasCallapseRequested || false,
wasCallapseRequested: wasCallapseRequested,
- activeTab: 'layers'
+ activeTab: 'layers',
+ mobileCollapsed: true
};
export default function sidebarReducer(state = sidebarState, action) {
@@ -30,6 +34,18 @@ export default function sidebarReducer(state = sidebarState, action) {
return lodashAssign({}, state, {
isCollapsed: true
});
+ case TOGGLE_MOBILE_COLLAPSE:
+ return lodashAssign({}, state, {
+ mobileCollapsed: !state.mobileCollapsed
+ });
+ case MOBILE_COLLAPSE_SIDEBAR:
+ return lodashAssign({}, state, {
+ mobileCollapsed: true
+ });
+ case MOBILE_EXPAND_SIDEBAR:
+ return lodashAssign({}, state, {
+ mobileCollapsed: false
+ });
case EXPAND_SIDEBAR:
return lodashAssign({}, state, {
isCollapsed: false