Interactive interface for browsing global, full-resolution satellite imagery
Add toolbar redux modules #1576
Benjamin King60dab46b23c1
diff --git a/web/js/app.js b/web/js/app.jsindex 5addf4009..e7671ba73 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -1,4 +1,5 @@import React from 'react';+import { connect } from 'react-redux';import lodashEach from 'lodash/each';import googleTagManager from 'googleTagManager';@@ -71,11 +72,11 @@ import naturalEventsUI from './natural-events/ui';import naturalEventsRequest from './natural-events/request';// Image-import { imageRubberband } from './image/rubberband';-import { imagePanel } from './image/panel';+// import { imageRubberband } from './image/rubberband';+// import { imagePanel } from './image/panel';// Notifications-import { notificationsUi } from './notifications/ui';+// import { notificationsUi } from './notifications/ui';// UIimport loadingIndicator from './ui/indicator';@@ -83,12 +84,10 @@ import loadingIndicator from './ui/indicator';import Toolbar from './containers/toolbar';// Linkimport { linkModel } from './link/model';-import { linkUi } from './link/ui';// Projectionsimport { parse as projectionParser } from './projection/projection';import { projectionModel } from './projection/model';-import { projectionUi } from './projection/ui';// A|B comparisonimport { compareModel } from './compare/model';@@ -100,7 +99,9 @@ import Modal from './containers/modal';import { debugConfig, debugLayers } from './debug';import Brand from './brand';import tour from './tour';-import { uiInfo } from './ui/info';++// Crutch between state systems+import { sendModelsToStore } from './modules/migration/actions';// Dependency CSSimport '../../node_modules/bootstrap/dist/css/bootstrap.css';@@ -118,7 +119,7 @@ import '../../node_modules/ol/ol.css';import '../../node_modules/rc-slider/dist/rc-slider.css';import '../../node_modules/simplebar/dist/simplebar.css';import '../../node_modules/@fortawesome/fontawesome-free/css/all.css';-+import 'react-image-crop/dist/ReactCrop.css';// App CSSimport '../css/fonts.css';import '../css/reset.css';@@ -152,9 +153,12 @@ import '../css/anim.widget.css';import '../css/dateselector.css';import '../css/tooltip.css';import '../css/mobile.css';+import '../css/modal.css';+import '../css/list.css';import '../pages/css/document.css';import { polyfill } from './polyfill';+polyfill(); // Polyfills some browser featuresclass App extends React.Component {@@ -166,7 +170,6 @@ class App extends React.Component {this.mapMouseEvents = util.events();this.onload();}-render() {return (<div className="wv-content" data-role="content">@@ -289,10 +292,6 @@ class App extends React.Component {var state = util.fromQueryString(location.search);var parameters = util.fromQueryString(location.search);- // Add font Awesome fonts- // library.add(faInfoCircle);- // dom.watch();-var main = function() {if (parameters.elapsed) {startTime = new Date().getTime();@@ -367,7 +366,6 @@ class App extends React.Component {initialDate.setUTCDate(initialDate.getUTCDate() - 1);}}-// Modelsvar models = {wv: {@@ -377,6 +375,7 @@ class App extends React.Component {var ui = {};// Attach to wvx object for debuggingwvx.models = models;+wvx.ui = ui;models.proj = projectionModel(config);@@ -429,10 +428,9 @@ class App extends React.Component {// HACK: Map needs permalink state loaded before starting. But// data download now needs it too.models.link.load(state); // needs to be loaded twice-+ self.props.updateModels(models); // crutch between old state system and reduxelapsed('ui');// Create widgets- ui.proj = projectionUi(models, config);ui.tour = tour(models, ui, config);ui.sidebar = sidebarUi(models, config, ui);ui.activeLayers = layersActive(models, ui, config);@@ -481,8 +479,6 @@ class App extends React.Component {ui.dateWheels = dateWheels(models, config);}- ui.rubberband = imageRubberband(models, ui, config);- ui.image = imagePanel(models, ui, config);if (config.features.dataDownload) {ui.data = dataUi(models, ui, config);}@@ -490,10 +486,8 @@ class App extends React.Component {var request = naturalEventsRequest(models, ui, config);ui.naturalEvents = naturalEventsUI(models, ui, config, request);}- ui.link = linkUi(models, config);- ui.info = uiInfo(ui, config);if (config.features.alert) {- ui.alert = notificationsUi(ui, config);+ // ui.alert = notificationsUi(ui, config);}if (config.features.compare) {ui.compare = compareUi(models, ui, config);@@ -599,4 +593,13 @@ function registerMapMouseHandlers(maps, events) {});}-export default App;+const mapDispatchToProps = dispatch => ({+ updateModels: modelsObject => {+ dispatch(sendModelsToStore(modelsObject));+ }+});++export default connect(+ null,+ mapDispatchToProps+)(App);diff --git a/web/js/main.js b/web/js/main.jsindex f5654e2e7..2952ae32a 100644--- a/web/js/main.js+++ b/web/js/main.js@@ -3,9 +3,18 @@ import React from 'react';import ReactDOM from 'react-dom';import App from './app';import { Provider } from 'react-redux';-import { createStore } from 'redux';+import { createStore, combineReducers } from 'redux';import modalReducer from './modules/modal/reducer';-const store = createStore(modalReducer);+import modelReducer from './modules/migration/reducer';+import projectionReducer from './modules/projection/reducer';++const reducers = {+ projection: projectionReducer,+ modal: modalReducer,+ models: modelReducer+};++const store = createStore(combineReducers(reducers));// Document ready functionwindow.onload = () => {diff --git a/web/js/modules/image-download/actions.js b/web/js/modules/image-download/actions.jsnew file mode 100644index 000000000..e69de29bbdiff --git a/web/js/modules/image-download/constants.js b/web/js/modules/image-download/constants.jsnew file mode 100644index 000000000..5c51d02cc--- /dev/null+++ b/web/js/modules/image-download/constants.js@@ -0,0 +1,37 @@+export const resolutionsGeo = {+ values: [+ { value: '0.125', text: '30m' },+ { value: '0.25', text: '60m' },+ { value: '0.5', text: '125m' },+ { value: '1', text: '250m' },+ { value: '2', text: '500m' },+ { value: '4', text: '1km' },+ { value: '20', text: '5km' },+ { value: '40', text: '10km' }+ ]+};+export const resolutionsPolar = {+ values: [+ { value: '1', text: '250m' },+ { value: '2', text: '500m' },+ { value: '4', text: '1km' },+ { value: '20', text: '5km' },+ { value: '40', text: '10km' }+ ]+};+export const fileTypesGeo = {+ values: [+ { value: 'image/jpeg', text: 'JPEG' },+ { value: 'image/png', text: 'PNG' },+ { value: 'image/tiff', text: 'GeoTIFF' },+ { value: 'application/vnd.google-earth.kmz', text: 'KMZ' }+ ]+};+export const fileTypesPolar = {+ values: [+ { value: 'image/jpeg', text: 'JPEG' },+ { value: 'image/png', text: 'PNG' },+ { value: 'image/tiff', text: 'GeoTIFF' }+ ]+};+export const maxSize = 8200;diff --git a/web/js/modules/image-download/reducer.js b/web/js/modules/image-download/reducer.jsnew file mode 100644index 000000000..0d6d04a20--- /dev/null+++ b/web/js/modules/image-download/reducer.js@@ -0,0 +1,16 @@+import { CHANGE_PROJECTION } from './constants';+import { assign as lodashAssign } from 'lodash';+const projectionState = {+ id: 'geographic'+};++export default function projectionReducer(state = projectionState, action) {+ switch (action.type) {+ case CHANGE_PROJECTION:+ return lodashAssign({}, state, {+ id: action.id+ });+ default:+ return state;+ }+}diff --git a/web/js/modules/link/actions.js b/web/js/modules/link/actions.jsnew file mode 100644index 000000000..14bece0ac--- /dev/null+++ b/web/js/modules/link/actions.js@@ -0,0 +1,7 @@+import { TOGGLE_URL } from './constants';++export function toggleUrl() {+ return {+ type: TOGGLE_URL+ };+}diff --git a/web/js/modules/link/constants.js b/web/js/modules/link/constants.jsnew file mode 100644index 000000000..97f574a85--- /dev/null+++ b/web/js/modules/link/constants.js@@ -0,0 +1 @@+export const TOGGLE_URL = 'TOGGLE_SHARE_LINK';diff --git a/web/js/modules/link/reducer.js b/web/js/modules/link/reducer.jsnew file mode 100644index 000000000..9ed08d209--- /dev/null+++ b/web/js/modules/link/reducer.js@@ -0,0 +1,17 @@+import { TOGGLE_URL } from './constants';+import { assign as lodashAssign } from 'lodash';++const linkState = {+ shortened: false+};++export default function linkReducer(state = linkState, action) {+ switch (action.type) {+ case TOGGLE_URL:+ return lodashAssign({}, state, {+ shortened: !state.shortened+ });+ default:+ return state;+ }+}diff --git a/web/js/modules/link/util.js b/web/js/modules/link/util.jsnew file mode 100644index 000000000..81003e032--- /dev/null+++ b/web/js/modules/link/util.js@@ -0,0 +1,67 @@+// Facebook: https://developers.facebook.com/docs/sharing/reference/share-dialog#redirect+export function facebookUrlParams(appId, href, redirectUri, display) {+ return (+ 'https://www.facebook.com/dialog/share?' ++ 'app_id=' ++ encodeURIComponent(appId) ++ '&href=' ++ encodeURIComponent(href) ++ '&redirect_uri=' ++ encodeURIComponent(redirectUri) ++ '&display=' ++ encodeURIComponent(display)+ );+}++// Twitter: https://dev.twitter.com/web/tweet-button/parameters#web-intent-example+export function twitterUrlParams(url, text) {+ return (+ 'https://twitter.com/intent/tweet?' ++ 'url=' ++ encodeURIComponent(url) ++ '&text=' ++ encodeURIComponent(text)+ );+}++// Reddit: https://www.reddit.com/r/nasa/submit?url=[URL]&title=[TITLE]+export function redditUrlParams(url, title) {+ return (+ 'https://www.reddit.com/r/nasa/submit?' ++ 'url=' ++ encodeURIComponent(url) ++ '&title=' ++ encodeURIComponent(title)+ );+}++// Email: mailto:?subject=[SUBJECT]&body=[BODY]+export function emailUrlParams(subject, body) {+ return (+ 'mailto:?' ++ 'subject=' ++ encodeURIComponent(subject) ++ '&body=' ++ encodeURIComponent(body)+ );+}+export function getSharelink(type, url) {+ var shareMessage = 'Check out what I found in NASA Worldview!';+ var twMessage = 'Check out what I found in #NASAWorldview -';+ var emailBody = shareMessage + ' - ' + url;++ switch (type) {+ case 'twitter':+ return twitterUrlParams(url, twMessage);+ case 'facebook':+ return facebookUrlParams('121285908450463', url, url, 'popup');+ case 'reddit':+ return redditUrlParams(url, shareMessage);+ case 'email':+ return emailUrlParams(shareMessage, emailBody);+ }+ return undefined;+}+export function openPromisedSocial(url, win) {+ win.location.assign(url);+}diff --git a/web/js/modules/migration/actions.js b/web/js/modules/migration/actions.jsnew file mode 100644index 000000000..f3474e184--- /dev/null+++ b/web/js/modules/migration/actions.js@@ -0,0 +1,8 @@+import { MODELS_HAVE_BEEN_LOADED } from './constants';++export function sendModelsToStore(models) {+ return {+ type: MODELS_HAVE_BEEN_LOADED,+ models: models+ };+}diff --git a/web/js/modules/migration/constants.js b/web/js/modules/migration/constants.jsnew file mode 100644index 000000000..f3d267cd8--- /dev/null+++ b/web/js/modules/migration/constants.js@@ -0,0 +1 @@+export const MODELS_HAVE_BEEN_LOADED = 'MODELS_HAVE_BEEN_LOADED';diff --git a/web/js/modules/migration/reducer.js b/web/js/modules/migration/reducer.jsnew file mode 100644index 000000000..1b5ecae51--- /dev/null+++ b/web/js/modules/migration/reducer.js@@ -0,0 +1,21 @@+import { MODELS_HAVE_BEEN_LOADED } from './constants';+import { assign as lodashAssign } from 'lodash';++const modelsState = {+ loaded: false,+ models: {}+};++export default function modelsReducer(state = modelsState, action) {+ console.log(action);+ switch (action.type) {+ case MODELS_HAVE_BEEN_LOADED:+ console.log(action);+ return lodashAssign({}, state, {+ models: action.models,+ loaded: true+ });+ default:+ return state;+ }+}diff --git a/web/js/modules/modal/customs.js b/web/js/modules/modal/customs.jsindex eee98473a..f6486ef4c 100644--- a/web/js/modules/modal/customs.js+++ b/web/js/modules/modal/customs.js@@ -1,8 +1,37 @@-import ImageSelect from '../../components/image-panel/select';-import React from 'react';+import ImageDownload from '../../containers/image-download';+import Projection from '../../containers/projection';+import InfoList from '../../containers/info';+import ShareLinks from '../../containers/share';+export const customProps = {- 'TOOLBAR-SNAPSHOT_MODAL': {+ TOOLBAR_PROJECTION: {+ headerText: null,+ type: 'toolbar',+ modalClassName: 'toolbar-list-modal toolbar-modal',+ backdrop: false,+ bodyComponent: Projection,+ offsetRight: '40px'+ },+ TOOLBAR_SHARE_LINK: {+ headerText: 'Copy link to share:',+ type: 'toolbar',+ backdrop: false,+ modalClassName: 'toolbar-share-modal toolbar-modal',+ bodyComponent: ShareLinks+ },+ TOOLBAR_INFO: {+ headerText: null,+ backdrop: false,+ type: 'toolbar',+ modalClassName: 'toolbar-list-modal toolbar-modal',+ offsetRight: '10px',+ bodyComponent: InfoList+ },+ TOOLBAR_SNAPSHOT: {headerText: 'Take a Snapshot',- bodyChildren: <ImageSelect />+ backdrop: false,+ type: 'selection',+ modalClassName: 'toolbar-snapshot-modal toolbar-modal',+ bodyComponent: ImageDownload}};diff --git a/web/js/modules/modal/reducer.js b/web/js/modules/modal/reducer.jsindex 3876fe5d0..7e2867afb 100644--- a/web/js/modules/modal/reducer.js+++ b/web/js/modules/modal/reducer.js@@ -1,12 +1,13 @@import { TOGGLE, OPEN_CUSTOM, OPEN_BASIC } from './constants';import { assign as lodashAssign } from 'lodash';+import update from 'immutability-helper';const modalState = {headerText: 'header Text',bodyText: 'Body Text',- isOpen: true,- key: '__default__',- ModalClassName: '',+ isOpen: false,+ id: '__default__',+ modalClassName: '',headerChildren: null,bodyHeader: null,bodyChildren: null,@@ -20,20 +21,21 @@ export default function modalReducer(state = modalState, action) {isOpen: !state.isOpen});case OPEN_BASIC:- return lodashAssign({}, state, {+ return Object.assign({}, state, {isOpen: action.key === state.key ? !state.isOpen : true,isCustom: false,- key: action.key,+ id: action.key,headerText: action.headerText,bodyText: action.bodyText});case OPEN_CUSTOM:- return lodashAssign({}, state, {- isOpen: action.key === state.key ? !state.isOpen : true,- isCustom: true,- key: action.key,- headerText: action.headerText,- bodyText: action.bodyText+ console.log(action, state);+ return update(state, {+ isOpen: { $set: action.key === state.key ? !state.isOpen : true },+ isCustom: { $set: true },+ id: { $set: action.key },+ headerText: { $set: action.headerText },+ bodyText: { $set: action.bodyText }});default:return state;diff --git a/web/js/modules/projection/actions.js b/web/js/modules/projection/actions.jsnew file mode 100644index 000000000..a224f007a--- /dev/null+++ b/web/js/modules/projection/actions.js@@ -0,0 +1,8 @@+import { CHANGE_PROJECTION } from './constants';++export function changeProjection(id) {+ return {+ type: CHANGE_PROJECTION,+ id: id+ };+}diff --git a/web/js/modules/projection/constants.js b/web/js/modules/projection/constants.jsnew file mode 100644index 000000000..dd502616d--- /dev/null+++ b/web/js/modules/projection/constants.js@@ -0,0 +1 @@+export const CHANGE_PROJECTION = 'CHANGE_PROJECTION';diff --git a/web/js/modules/projection/reducer.js b/web/js/modules/projection/reducer.jsnew file mode 100644index 000000000..0d6d04a20--- /dev/null+++ b/web/js/modules/projection/reducer.js@@ -0,0 +1,16 @@+import { CHANGE_PROJECTION } from './constants';+import { assign as lodashAssign } from 'lodash';+const projectionState = {+ id: 'geographic'+};++export default function projectionReducer(state = projectionState, action) {+ switch (action.type) {+ case CHANGE_PROJECTION:+ return lodashAssign({}, state, {+ id: action.id+ });+ default:+ return state;+ }+}