Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

create modal module w redux #1553

Benjamin King6241ee47a6f9
diff --git a/web/js/app.js b/web/js/app.js
index 0c0fcb591..5addf4009 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -79,7 +79,8 @@ import { notificationsUi } from './notifications/ui';
// UI
import loadingIndicator from './ui/indicator';
-
+// Toolbar
+import Toolbar from './containers/toolbar';
// Link
import { linkModel } from './link/model';
import { linkUi } from './link/ui';
@@ -92,6 +93,9 @@ import { projectionUi } from './projection/ui';
// A|B comparison
import { compareModel } from './compare/model';
import { compareUi } from './compare/ui';
+
+// Modal
+import Modal from './containers/modal';
// Other
import { debugConfig, debugLayers } from './debug';
import Brand from './brand';
@@ -166,15 +170,7 @@ class App extends React.Component {
render() {
return (
<div className="wv-content" data-role="content">
- <ul id="wv-toolbar">
- <li id="wv-link-button" className="wv-toolbar-button" />
- <li id="wv-proj-button" className="wv-toolbar-button" />
- <li id="wv-image-button" className="wv-toolbar-button" />
- <li
- id="wv-info-button"
- className="wv-toolbar-button wv-status-hide"
- />
- </ul>
+ <Toolbar />
<section id="wv-sidebar" />
<div id="layer-modal" className="layer-modal" />
<div id="layer-settings-modal" />
@@ -277,6 +273,7 @@ class App extends React.Component {
</div>
</section>
<OlCoordinates mouseEvents={this.mapMouseEvents} />
+ <Modal />
</div>
);
}
diff --git a/web/js/components/modal/modal.js b/web/js/components/modal/modal.js
new file mode 100644
index 000000000..db3d9f82d
--- /dev/null
+++ b/web/js/components/modal/modal.js
@@ -0,0 +1,46 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Modal, ModalBody, ModalHeader } from 'reactstrap';
+
+/*
+ * A scrollable list of layers
+ * @class LayerList
+ * @extends React.Component
+ */
+class ModalComponent extends React.Component {
+ /**
+ * Update modal visibility
+ * @function toggle
+ */
+
+ render() {
+ const {
+ ModalClassName,
+ headerChildren,
+ headerText,
+ bodyHeader,
+ bodyChildren,
+ bodyText,
+ onToggle,
+ isOpen
+ } = this.props;
+ return (
+ <Modal
+ isOpen={isOpen}
+ toggle={onToggle}
+ backdrop={true}
+ className={ModalClassName || 'default-modal'}
+ autoFocus={false}
+ >
+ <ModalHeader toggle={onToggle}>
+ {headerChildren || (headerText || '')}
+ </ModalHeader>
+ <ModalBody>
+ {bodyHeader ? <h3>{bodyHeader}</h3> : ''}
+ {bodyChildren || (bodyText || '')}
+ </ModalBody>
+ </Modal>
+ );
+ }
+}
+export default ModalComponent;
diff --git a/web/js/containers/modal.js b/web/js/containers/modal.js
new file mode 100644
index 000000000..cfad3d111
--- /dev/null
+++ b/web/js/containers/modal.js
@@ -0,0 +1,41 @@
+import React, { Component } from 'react';
+import PropTypes from 'prop-types';
+import { connect } from 'react-redux';
+import update from 'immutability-helper';
+import Modal from '../components/modal/modal';
+import { customProps } from '../modules/modal/customs';
+import { onToggle } from '../modules/modal/actions';
+
+class ModalContainer extends Component {
+ render() {
+ const { isCustom, id } = this.props;
+ const props =
+ isCustom && id
+ ? update(this.props, { $merge: customProps[id] })
+ : this.props;
+ return <Modal {...props} />;
+ }
+}
+
+function mapStateToProps(state) {
+ const { isOpen, bodyText, headerText, isCustom, key } = state;
+ const id = key;
+
+ return {
+ isOpen,
+ bodyText,
+ headerText,
+ isCustom,
+ id
+ };
+}
+const mapDispatchToProps = dispatch => ({
+ onToggle: () => {
+ dispatch(onToggle());
+ }
+});
+
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(ModalContainer);
diff --git a/web/js/containers/toolbar.js b/web/js/containers/toolbar.js
new file mode 100644
index 000000000..16aa33d75
--- /dev/null
+++ b/web/js/containers/toolbar.js
@@ -0,0 +1,33 @@
+import React, { Component } from 'react';
+import PropTypes from 'prop-types';
+import { connect } from 'react-redux';
+import { openCustomContent } from '../modules/modal/actions';
+
+class LinksContainer extends Component {
+ render() {
+ const { openModal } = this.props;
+ return (
+ <ul id="wv-toolbar">
+ <li id="wv-link-button" className="wv-toolbar-button" />
+ <li id="wv-proj-button" className="wv-toolbar-button" />
+ <li
+ id="wv-image-button"
+ className="wv-toolbar-button"
+ onClick={openModal}
+ />
+ <li id="wv-info-button" className="wv-toolbar-button wv-status-hide" />
+ </ul>
+ );
+ }
+}
+
+const mapDispatchToProps = dispatch => ({
+ openModal: () => {
+ dispatch(openCustomContent('TOOLBAR-SNAPSHOT_MODAL'));
+ }
+});
+
+export default connect(
+ null,
+ mapDispatchToProps
+)(LinksContainer);
diff --git a/web/js/main.js b/web/js/main.js
index ad77c8a23..f5654e2e7 100644
--- a/web/js/main.js
+++ b/web/js/main.js
@@ -2,8 +2,17 @@ import 'babel-polyfill'; // Needed for worldview-components in IE and older brow
import React from 'react';
import ReactDOM from 'react-dom';
import App from './app';
+import { Provider } from 'react-redux';
+import { createStore } from 'redux';
+import modalReducer from './modules/modal/reducer';
+const store = createStore(modalReducer);
// Document ready function
window.onload = () => {
- ReactDOM.render(<App />, document.getElementById('app'));
+ ReactDOM.render(
+ <Provider store={store}>
+ <App />
+ </Provider>,
+ document.getElementById('app')
+ );
};
diff --git a/web/js/modules/modal/actions.js b/web/js/modules/modal/actions.js
new file mode 100644
index 000000000..c55f60edf
--- /dev/null
+++ b/web/js/modules/modal/actions.js
@@ -0,0 +1,22 @@
+import util from '../../util/util';
+import { OPEN_BASIC, OPEN_CUSTOM, TOGGLE } from './constants';
+
+export function openBasicContent(modalHeader, bodyText) {
+ return {
+ type: OPEN_BASIC,
+ headerText: modalHeader,
+ bodyText: bodyText,
+ key: util.encodeId(' __BASIC_MODAL__' + modalHeader)
+ };
+}
+export function openCustomContent(key) {
+ return {
+ type: OPEN_CUSTOM,
+ key: key
+ };
+}
+export function onToggle() {
+ return {
+ type: TOGGLE
+ };
+}
diff --git a/web/js/modules/modal/constants.js b/web/js/modules/modal/constants.js
new file mode 100644
index 000000000..5122f3867
--- /dev/null
+++ b/web/js/modules/modal/constants.js
@@ -0,0 +1,3 @@
+export const TOGGLE = 'TOGGLE_MODAL_OPEN';
+export const OPEN_CUSTOM = 'OPEN_MODAL_WITH_CUSTOM_CONTENT';
+export const OPEN_BASIC = 'OPEN_MODAL_WITH_BASIC_CONTENT';
diff --git a/web/js/modules/modal/customs.js b/web/js/modules/modal/customs.js
new file mode 100644
index 000000000..eee98473a
--- /dev/null
+++ b/web/js/modules/modal/customs.js
@@ -0,0 +1,8 @@
+import ImageSelect from '../../components/image-panel/select';
+import React from 'react';
+export const customProps = {
+ 'TOOLBAR-SNAPSHOT_MODAL': {
+ headerText: 'Take a Snapshot',
+ bodyChildren: <ImageSelect />
+ }
+};
diff --git a/web/js/modules/modal/reducer.js b/web/js/modules/modal/reducer.js
new file mode 100644
index 000000000..3876fe5d0
--- /dev/null
+++ b/web/js/modules/modal/reducer.js
@@ -0,0 +1,41 @@
+import { TOGGLE, OPEN_CUSTOM, OPEN_BASIC } from './constants';
+import { assign as lodashAssign } from 'lodash';
+
+const modalState = {
+ headerText: 'header Text',
+ bodyText: 'Body Text',
+ isOpen: true,
+ key: '__default__',
+ ModalClassName: '',
+ headerChildren: null,
+ bodyHeader: null,
+ bodyChildren: null,
+ isCustom: false
+};
+
+export default function modalReducer(state = modalState, action) {
+ switch (action.type) {
+ case TOGGLE:
+ return lodashAssign({}, state, {
+ isOpen: !state.isOpen
+ });
+ case OPEN_BASIC:
+ return lodashAssign({}, state, {
+ isOpen: action.key === state.key ? !state.isOpen : true,
+ isCustom: false,
+ key: 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
+ });
+ default:
+ return state;
+ }
+}