Interactive interface for browsing global, full-resolution satellite imagery
Create core request module and utilize it to request about page #1553
Benjamin King72ef049ea71c
diff --git a/package-lock.json b/package-lock.jsonindex 31cb6cfb5..7292dd52c 100644--- a/package-lock.json+++ b/package-lock.json@@ -18371,6 +18371,11 @@}}},+ "redux-thunk": {+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz",+ "integrity": "sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw=="+ },"ref": {"version": "1.3.5","resolved": "https://registry.npmjs.org/ref/-/ref-1.3.5.tgz",diff --git a/package.json b/package.jsonindex 9bdbd7708..983711b15 100644--- a/package.json+++ b/package.json@@ -183,6 +183,7 @@"react-redux": "^6.0.0","reactstrap": "^6.3.1","redux": "^4.0.1",+ "redux-thunk": "^2.3.0","simplebar": "^3.0.0-beta.1","supercluster": "3.0.2","web-streams-polyfill": "^1.3.2",diff --git a/web/js/main.js b/web/js/main.jsindex 2952ae32a..980784808 100644--- a/web/js/main.js+++ b/web/js/main.js@@ -3,18 +3,22 @@ import React from 'react';import ReactDOM from 'react-dom';import App from './app';import { Provider } from 'react-redux';-import { createStore, combineReducers } from 'redux';-import modalReducer from './modules/modal/reducer';-import modelReducer from './modules/migration/reducer';+import { createStore, combineReducers, applyMiddleware } from 'redux';+import { modalReducer, modalAboutPage } from './modules/modal/reducers';+import modelReducer from './modules/migration/reducers';+import feedbackReducer from './modules/feedback/reducers';import projectionReducer from './modules/projection/reducer';+import thunk from 'redux-thunk';const reducers = {projection: projectionReducer,modal: modalReducer,- models: modelReducer+ models: modelReducer,+ feedback: feedbackReducer,+ modalAboutPage};-const store = createStore(combineReducers(reducers));+const store = createStore(combineReducers(reducers), applyMiddleware(thunk));// Document ready functionwindow.onload = () => {diff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.jsnew file mode 100644index 000000000..0e933a66d--- /dev/null+++ b/web/js/modules/core/actions.js@@ -0,0 +1,34 @@+import { fetch } from 'whatwg-fetch';++export function requestAction(dispatch, actionName, url, fileType) {+ dispatch(startRequest(actionName));+ fetch(url)+ .then(function(response) {+ return fileType === 'json' ? response.json() : response.text();+ })+ .then(function(body) {+ dispatch(fetchSuccess(actionName, body));+ })+ .catch(function(err) {+ dispatch(fetchFailure(actionName, err));+ });+}+export function startRequest(actionName) {+ return {+ type: `${actionName}_START`+ };+}++export function fetchSuccess(actionName, response) {+ return {+ type: `${actionName}_SUCCESS`,+ response: response+ };+}++export function fetchFailure(actionName, error) {+ return {+ type: `${actionName}_FAILURE`,+ error: { error }+ };+}diff --git a/web/js/modules/core/reducers.js b/web/js/modules/core/reducers.jsnew file mode 100644index 000000000..217d2657d--- /dev/null+++ b/web/js/modules/core/reducers.js@@ -0,0 +1,41 @@+import { assign as lodashAssign } from 'lodash';++export function requestResponse(props = {}) {+ return lodashAssign(+ {},+ {+ isLoading: false,+ error: {},+ response: {},+ type: null+ },+ props+ );+}++export function requestReducer(actionName, state, action) {+ const START = `${actionName}_START`;+ const SUCCESS = `${actionName}_SUCCESS`;+ const FAILURE = `${actionName}_FAILURE`;+ switch (action.type) {+ case START:+ return requestResponse({+ response: state.response,+ isLoading: true,+ type: action.type+ });+ case SUCCESS:+ return requestResponse({+ response: action.response,+ isLoading: false,+ type: action.type+ });+ case FAILURE:+ return requestResponse({+ error: action.error,+ type: action.type+ });+ default:+ return state;+ }+}diff --git a/web/js/modules/modal/actions.js b/web/js/modules/modal/actions.jsindex c55f60edf..1670d986d 100644--- a/web/js/modules/modal/actions.js+++ b/web/js/modules/modal/actions.js@@ -1,12 +1,13 @@import util from '../../util/util';-import { OPEN_BASIC, OPEN_CUSTOM, TOGGLE } from './constants';+import { OPEN_BASIC, OPEN_CUSTOM, TOGGLE, RENDER_TEMPLATE } from './constants';+import { actionOrienter, requestAction } from '../core/actions';export function openBasicContent(modalHeader, bodyText) {return {type: OPEN_BASIC,headerText: modalHeader,bodyText: bodyText,- key: util.encodeId(' __BASIC_MODAL__' + modalHeader)+ key: util.encodeId('__BASIC_MODAL__' + modalHeader)};}export function openCustomContent(key) {@@ -15,6 +16,19 @@ export function openCustomContent(key) {key: key};}+export function renderTemplate(headerText, template) {+ return {+ type: RENDER_TEMPLATE,+ key: template,+ template: template,+ headerText: headerText+ };+}+export function requestLoadedPage(pageName, location, type) {+ return dispatch => {+ return requestAction(dispatch, pageName, location);+ };+}export function onToggle() {return {type: TOGGLEdiff --git a/web/js/modules/modal/constants.js b/web/js/modules/modal/constants.jsindex 5122f3867..d5bea3618 100644--- a/web/js/modules/modal/constants.js+++ b/web/js/modules/modal/constants.js@@ -1,3 +1,8 @@export const TOGGLE = 'TOGGLE_MODAL_OPEN';export const OPEN_CUSTOM = 'OPEN_MODAL_WITH_CUSTOM_CONTENT';export const OPEN_BASIC = 'OPEN_MODAL_WITH_BASIC_CONTENT';+export const RENDER_TEMPLATE = 'OPEN_MODAL_CONTAINING_LOADED_PAGE';++export const ABOUT_PAGE_START = 'MODAL_ABOUT_PAGE_REQUEST_START';+export const ABOUT_PAGE_SUCCESS = 'MODAL_ABOUT_PAGE_REQUEST_SUCCESS';+export const ABOUT_PAGE_FAILURE = 'MODAL_ABOUT_PAGE_REQUEST_FAILURE';