Interactive interface for browsing global, full-resolution satellite imagery
Pass modal custom props in action #1576
Benjamin King27f2df3066c1
diff --git a/web/js/containers/info.js b/web/js/containers/info.jsindex 0a104d251..76977c688 100644--- a/web/js/containers/info.js+++ b/web/js/containers/info.js@@ -14,6 +14,12 @@ import { addToLocalStorage } from '../modules/notifications/util';import { initFeedback } from '../modules/feedback/actions';import { notificationsSeen } from '../modules/notifications/actions';import util from '../util/util';+import Notifications from '../containers/notifications';++const NOTIFICATION_CUSTOM_MODAL_PARAMS = {+ headerText: 'Notifications',+ bodyComponent: Notifications+};class InfoList extends Component {getNotificationListItem(obj) {@@ -121,14 +127,18 @@ const mapDispatchToProps = dispatch => ({dispatch(initFeedback());}},- startTour: () => {},notificationClick: (obj, num) => {if (num > 0) {dispatch(notificationsSeen());addToLocalStorage(obj);}- dispatch(openCustomContent('NOTIFICATION_LIST_MODAL'));+ dispatch(+ openCustomContent(+ 'NOTIFICATION_LIST_MODAL',+ NOTIFICATION_CUSTOM_MODAL_PARAMS+ )+ );},aboutClick: () => {if (util.browser.small) {diff --git a/web/js/containers/modal.js b/web/js/containers/modal.jsindex fb0d134d8..b3f44a8b2 100644--- a/web/js/containers/modal.js+++ b/web/js/containers/modal.js@@ -4,7 +4,6 @@ import { connect } from 'react-redux';import update from 'immutability-helper';import { toLower } from 'lodash';import { Modal, ModalBody, ModalHeader } from 'reactstrap';-import { customProps } from '../modules/modal/customs';import { onToggle } from '../modules/modal/actions';import DetectOuterClick from '../components/util/detect-outer-click';@@ -28,12 +27,10 @@ class ModalContainer extends Component {);}render() {- const { isCustom, id, isOpen, isTemplateModal } = this.props;+ const { isCustom, id, isOpen, isTemplateModal, customProps } = this.props;// Populate props from custom objconst newProps =- isCustom && id- ? update(this.props, { $merge: customProps[id] })- : this.props;+ isCustom && id ? update(this.props, { $merge: customProps }) : this.props;const {onToggle,bodyText,@@ -45,14 +42,12 @@ class ModalContainer extends Component {autoFocus,type,wrapClassName,- clickableBehindModal+ clickableBehindModal,+ bodyComponent} = newProps;- const BodyComponent =- customProps[id] && customProps[id].bodyComponent- ? customProps[id].bodyComponent- : '';const style = this.getStyle(newProps);const lowerCaseId = toLower(id);+ const BodyComponent = bodyComponent || '';return (<ModalisOpen={isOpen}@@ -93,7 +88,15 @@ class ModalContainer extends Component {function mapStateToProps(state) {const { models } = state.legacy;- const { bodyText, headerText, isCustom, id, isOpen, template } = state.modal;+ const {+ bodyText,+ headerText,+ isCustom,+ id,+ isOpen,+ template,+ customProps+ } = state.modal;let bodyTemplate;let isTemplateModal = false;if (template) {@@ -109,7 +112,8 @@ function mapStateToProps(state) {id,models,bodyTemplate,- isTemplateModal+ isTemplateModal,+ customProps};}const mapDispatchToProps = dispatch => ({diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.jsindex 39cd96157..7cfdd56b6 100644--- a/web/js/containers/toolbar.js+++ b/web/js/containers/toolbar.js@@ -3,7 +3,47 @@ import PropTypes from 'prop-types';import { connect } from 'react-redux';import { ButtonToolbar, Button } from 'reactstrap';import { openCustomContent } from '../modules/modal/actions';-+import ImageDownload from './image-download';+import Projection from './projection';+import InfoList from './info';+import ShareLinks from './share';+const CUSTOM_MODAL_PROPS = {+ TOOLBAR_PROJECTION: {+ headerText: null,+ type: 'toolbar',+ modalClassName: 'toolbar-list-modal toolbar-modal',+ backdrop: true,+ bodyComponent: Projection,+ offsetRight: '40px'+ },+ TOOLBAR_SHARE_LINK: {+ headerText: 'Copy Link to Share',+ type: 'toolbar',+ backdrop: false,+ offsetRight: '198px',+ modalClassName: 'toolbar-share-modal toolbar-modal toolbar-medium-modal',+ clickableBehindModal: true,+ wrapClassName: 'clickable-behind-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',+ backdrop: false,+ wrapClassName: 'clickable-behind-modal',+ type: 'selection',+ offsetRight: '70px',+ modalClassName: 'toolbar-snapshot-modal toolbar-modal toolbar-medium-modal',+ bodyComponent: ImageDownload+ }+};class LinksContainer extends Component {render() {const {@@ -20,7 +60,12 @@ class LinksContainer extends Component {id="wv-link-button"className="wv-toolbar-button"title="Share this map"- onClick={() => openModal('TOOLBAR_SHARE_LINK')}+ onClick={() =>+ openModal(+ 'TOOLBAR_SHARE_LINK',+ CUSTOM_MODAL_PROPS['TOOLBAR_SHARE_LINK']+ )+ }><i className="fas fa-share-square fa-2x" /></Button>@@ -28,7 +73,12 @@ class LinksContainer extends Component {id="wv-proj-button"className="wv-toolbar-button"title="Switch projection"- onClick={() => openModal('TOOLBAR_PROJECTION')}+ onClick={() =>+ openModal(+ 'TOOLBAR_PROJECTION',+ CUSTOM_MODAL_PROPS['TOOLBAR_PROJECTION']+ )+ }><i className="fas fa-globe-asia fa-2x" />{' '}</Button>@@ -36,7 +86,12 @@ class LinksContainer extends Component {id="wv-image-button"className="wv-toolbar-button"title="Take a snapshot"- onClick={() => openModal('TOOLBAR_SNAPSHOT')}+ onClick={() =>+ openModal(+ 'TOOLBAR_SNAPSHOT',+ CUSTOM_MODAL_PROPS['TOOLBAR_SNAPSHOT']+ )+ }><i className="fa fa-camera fa-2x" />{' '}</Button>@@ -44,7 +99,9 @@ class LinksContainer extends Component {id="wv-info-button"title="Information"className={'wv-toolbar-button' + notificationClass}- onClick={() => openModal('TOOLBAR_INFO')}+ onClick={() =>+ openModal('TOOLBAR_INFO', CUSTOM_MODAL_PROPS['TOOLBAR_INFO'])+ }datacontent={notificationContentNumber}><i className="fa fa-info-circle fa-2x" />{' '}@@ -62,8 +119,8 @@ function mapStateToProps(state) {};}const mapDispatchToProps = dispatch => ({- openModal: text => {- dispatch(openCustomContent(text));+ openModal: (key, customParams) => {+ dispatch(openCustomContent(key, customParams));}});diff --git a/web/js/modules/date/util.js b/web/js/modules/date/util.jsindex 705b7a671..b4a583107 100644--- a/web/js/modules/date/util.js+++ b/web/js/modules/date/util.js@@ -65,10 +65,6 @@ export function getDateParameterSetup(}}}- // now: {- // stateKey: 'legacy.date.now',- // initialState: ''- // }};}export function serializeDate(date) {diff --git a/web/js/modules/modal/actions.js b/web/js/modules/modal/actions.jsindex 751a885a5..d4af0830b 100644--- a/web/js/modules/modal/actions.js+++ b/web/js/modules/modal/actions.js@@ -10,10 +10,11 @@ export function openBasicContent(modalHeader, bodyText) {key: util.encodeId('__BASIC_MODAL__' + modalHeader)};}-export function openCustomContent(key) {+export function openCustomContent(key, params) {return {type: OPEN_CUSTOM,- key: key+ key: key,+ customProps: params};}export function renderTemplate(headerText, template) {diff --git a/web/js/modules/modal/customs.js b/web/js/modules/modal/customs.jsindex 4e23fd467..97934f148 100644--- a/web/js/modules/modal/customs.js+++ b/web/js/modules/modal/customs.js@@ -2,7 +2,6 @@ import ImageDownload from '../../containers/image-download';import Projection from '../../containers/projection';import InfoList from '../../containers/info';import ShareLinks from '../../containers/share';-import Notifications from '../../containers/notifications';export const customProps = {TOOLBAR_PROJECTION: {@@ -39,9 +38,9 @@ export const customProps = {offsetRight: '70px',modalClassName: 'toolbar-snapshot-modal toolbar-modal toolbar-medium-modal',bodyComponent: ImageDownload- },- NOTIFICATION_LIST_MODAL: {- headerText: 'Notifications',- bodyComponent: Notifications}+ // NOTIFICATION_LIST_MODAL: {+ // headerText: 'Notifications',+ // bodyComponent: Notifications+ // }};diff --git a/web/js/modules/modal/reducers.js b/web/js/modules/modal/reducers.jsindex 0e674f151..9b4e44503 100644--- a/web/js/modules/modal/reducers.js+++ b/web/js/modules/modal/reducers.js@@ -7,7 +7,6 @@ import {} from './constants';import { requestReducer } from '../core/reducers';import { assign as lodashAssign } from 'lodash';-import update from 'immutability-helper';const modalState = {headerText: '',@@ -19,7 +18,8 @@ const modalState = {bodyHeader: null,bodyChildren: null,isCustom: false,- bodyHTML: null+ bodyHTML: null,+ customProps: {}};export function modalAboutPage(state = {}, action) {return requestReducer(ABOUT_PAGE_REQUEST, state, action);@@ -31,29 +31,32 @@ export function modalReducer(state = modalState, action) {isOpen: !state.isOpen});case OPEN_BASIC:- return Object.assign({}, state, {+ return lodashAssign({}, state, {isOpen: action.key === state.key ? !state.isOpen : true,isCustom: false,id: action.key,headerText: action.headerText,- bodyText: action.bodyText+ bodyText: action.bodyText,+ customProps: {}});case OPEN_CUSTOM:- 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 }+ return lodashAssign({}, state, {+ isOpen: action.key === state.key ? !state.isOpen : true,+ isCustom: true,+ customProps: action.customProps,+ id: action.key,+ headerText: action.headerText,+ bodyText: action.bodyText});case RENDER_TEMPLATE:- return update(state, {- isOpen: { $set: action.key === state.key ? !state.isOpen : true },- isCustom: { $set: false },- id: { $set: action.key },- headerText: { $set: action.headerText },- bodyText: { $set: null },- template: { $set: action.template }+ return lodashAssign({}, state, {+ isOpen: action.key === state.key ? !state.isOpen : true,+ isCustom: false,+ id: action.key,+ headerText: action.headerText,+ bodyText: null,+ template: action.template,+ customProps: {}});default:return state;