Interactive interface for browsing global, full-resolution satellite imagery
Anim startDate should be currentDate #1869
Benjamin King62b044381326
diff --git a/web/js/fixtures.js b/web/js/fixtures.jsindex 78b1a7a79..e2ccf7a4d 100644--- a/web/js/fixtures.js+++ b/web/js/fixtures.js@@ -3,6 +3,7 @@ import { register } from 'ol/proj/proj4';import { initialState as initialLayerState } from './modules/layers/reducers';import { initialCompareState } from './modules/compare/reducers';import { getInitialState as getInitialDateState } from './modules/date/reducers';+import { defaultState as initialAnimationState } from './modules/animation/reducers';var fixtures = {red: 'ff0000ff',light_red: 'fff0f0ff',@@ -19,6 +20,7 @@ fixtures.getState = function() {config: fixtures.config(),layers: initialLayerState,date: getInitialDateState(fixtures.config()),+ animation: initialAnimationState,palettes: {active: {},activeB: {},diff --git a/web/js/modules/animation/actions.js b/web/js/modules/animation/actions.jsindex 6dc3e7d3a..e9e40c8e3 100644--- a/web/js/modules/animation/actions.js+++ b/web/js/modules/animation/actions.js@@ -10,12 +10,29 @@ import {UPDATE_END_DATE,TOGGLE_GIF} from './constants';+import util from '../../util/util';export function onActivate() {return (dispatch, getState) => {- const { compare, date } = getState();+ const { compare, date, animation } = getState();const dateStr = compare.isCompareA ? 'selected' : 'selectedB';- dispatch({ type: OPEN_ANIMATION, date: date[dateStr] });+ const activeDate = date[dateStr];+ if (!animation.startDate || !animation.endDate) {+ const sevenDaysBefore = util.dateAdd(activeDate, 'day', -7);+ const severDaysAfter = util.dateAdd(activeDate, 'day', 7);+ const startDate = animation.startDate+ ? animation.startDate+ : date.appNow < severDaysAfter+ ? sevenDaysBefore+ : activeDate;+ const endDate = animation.endDate+ ? animation.endDate+ : date.appNow < severDaysAfter+ ? activeDate+ : severDaysAfter;+ dispatch({ type: UPDATE_START_AND_END_DATE, startDate, endDate });+ }+ dispatch({ type: OPEN_ANIMATION });};}export function onClose() {diff --git a/web/js/modules/animation/actions.test.js b/web/js/modules/animation/actions.test.jsindex 696132c5d..a3e03e077 100644--- a/web/js/modules/animation/actions.test.js+++ b/web/js/modules/animation/actions.test.js@@ -125,8 +125,13 @@ test(const mockStore = configureMockStore(middlewares);const store = mockStore(state);store.dispatch(onActivate());- const response = store.getActions()[0];- expect(response.type).toEqual(constants.OPEN_ANIMATION);- expect(response.date).toEqual(state.date.selected);+ const response1 = store.getActions()[0];+ const response2 = store.getActions()[1];+ expect(response1.type).toEqual(constants.UPDATE_START_AND_END_DATE);+ expect(response1.endDate).toEqual(state.date.selected);+ expect(response1.startDate).toEqual(+ util.dateAdd(state.date.selected, 'day', -7)+ );+ expect(response2.type).toEqual(constants.OPEN_ANIMATION);});diff --git a/web/js/modules/animation/reducer.test.js b/web/js/modules/animation/reducer.test.jsindex a27c52611..904a219c7 100644--- a/web/js/modules/animation/reducer.test.js+++ b/web/js/modules/animation/reducer.test.js@@ -5,13 +5,11 @@ import update from 'immutability-helper';const now = new Date();const then = util.dateAdd(now, 'day', -7);-test('OPEN_ANIMATION action updates start and end dates', () => {+test('OPEN_ANIMATION action updates active state', () => {const response = animationReducer(defaultState, {- type: CONSTANTS.OPEN_ANIMATION,- date: now+ type: CONSTANTS.OPEN_ANIMATION});- expect(response.startDate).toEqual(then);- expect(response.endDate).toEqual(now);+expect(response.isActive).toEqual(true);});diff --git a/web/js/modules/animation/reducers.js b/web/js/modules/animation/reducers.jsindex 7e3f0a9a8..8b8fbf66d 100644--- a/web/js/modules/animation/reducers.js+++ b/web/js/modules/animation/reducers.js@@ -35,11 +35,7 @@ export function animationReducer(state = defaultState, action) {case OPEN_ANIMATION:return lodashAssign({}, state, {isActive: true,- gifActive: false,- startDate: state.startDate- ? state.startDate- : util.dateAdd(action.date, 'day', -7),- endDate: state.endDate ? state.endDate : action.date+ gifActive: false});case EXIT_ANIMATION:return lodashAssign({}, state, {diff --git a/web/js/modules/animation/util.js b/web/js/modules/animation/util.jsindex fcfc95b64..7abea6631 100644--- a/web/js/modules/animation/util.js+++ b/web/js/modules/animation/util.js@@ -1,4 +1,4 @@-import { round as lodashRound } from 'lodash';+import { round as lodashRound, get as lodashGet } from 'lodash';import canvg from 'canvg-browser';import util from '../../util/util';import update from 'immutability-helper';@@ -117,10 +117,22 @@ export function mapLocationToAnimationState(state,config) {+ const startDate = lodashGet(stateFromLocation, 'animation.startDate');+ const endDate = lodashGet(stateFromLocation, 'animation.endDate');if (parameters.playanim && parameters.ab) {stateFromLocation = update(stateFromLocation, {animation: { isPlaying: { $set: true } }});+ } else if (!parameters.ae || (!parameters.as && (!!endDate || !!startDate))) {+ // wipe anim start & end dates on tour change++ stateFromLocation = update(stateFromLocation, {+ animation: { endDate: { $set: undefined } }+ });++ stateFromLocation = update(stateFromLocation, {+ animation: { startDate: { $set: undefined } }+ });}return stateFromLocation;}