Interactive interface for browsing global, full-resolution satellite imagery
Create toolbar modal components #1553
Benjamin King71e2aa3d00b5
diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.jsnew file mode 100644index 000000000..560c1255e--- /dev/null+++ b/web/js/containers/image-download.js@@ -0,0 +1,51 @@+import React, { Component } from 'react';+import PropTypes from 'prop-types';+import { connect } from 'react-redux';+import Panel from '../components/image-download/panel';+import CropSelection from '../components/util/image-crop';++import {+ resolutionsGeo,+ resolutionsPolar,+ fileTypesGeo,+ fileTypesPolar+} from '../modules/image-download/constants';+// import BoundarySelection from '../components/image-download/select-boundary';++class ImageDownloadContainer extends Component {+ onSelectionChange() {}+ render() {+ const { projection, boundaries, el } = this.props;+ const fileTypes =+ projection === 'geographic' ? fileTypesGeo : fileTypesPolar;+ const resolutions =+ projection === 'geographic' ? resolutionsGeo : resolutionsPolar;+ return (+ <React.Fragment>+ <Panel+ projection={projection}+ fileTypes={fileTypes}+ resolutions={resolutions}+ boundaries={boundaries}+ />+ <CropSelection onChange={this.onSelectionChange.bind(this)} el={el} />+ </React.Fragment>+ );+ }+}++function mapStateToProps(state) {+ const { projection } = state.projection;+ // const { boundaries } = state.imageDownload;++ return {+ projection,+ boundaries: 0+ };+}++export default connect(mapStateToProps)(ImageDownloadContainer);++ImageDownloadContainer.propTypes = {+ projection: PropTypes.string+};diff --git a/web/js/containers/info.js b/web/js/containers/info.jsnew file mode 100644index 000000000..7804389ef--- /dev/null+++ b/web/js/containers/info.js@@ -0,0 +1,65 @@+import React, { Component } from 'react';+import PropTypes from 'prop-types';+import { connect } from 'react-redux';+import { openCustomContent } from '../modules/modal/actions';+import IconList from '../components/util/list';++const infoArray = [+ {+ text: 'Send feedback',+ iconClass: 'ui-icon fa fa-envelope fa-fw',+ id: 'send_feedback_info_item'+ },+ {+ text: 'Start Tour',+ iconClass: 'ui-icon fa fa-truck fa-fw',+ id: 'start_tour_info_item'+ },+ {+ text: 'Source Code',+ iconClass: 'ui-icon fa fa-code fa-fw',+ id: 'source_code_info_item'+ },+ {+ text: 'Whats new',+ iconClass: 'ui-icon fa fa-flag fa-fw',+ id: 'source_code_info_item'+ },+ {+ text: 'Notifications',+ iconClass: 'ui-icon fa fa-file fa-fw',+ id: 'source_code_info_item'+ }+];++class InfoList extends Component {+ render() {+ return <IconList list={infoArray} size="small" />;+ }+}+function mapStateToProps(state) {+ const { isOpen, bodyText, headerText, isCustom, key } = state;+ const id = key;++ return {+ isOpen,+ bodyText,+ headerText,+ isCustom,+ id+ };+}+const mapDispatchToProps = dispatch => ({+ openModal: text => {+ dispatch(openCustomContent(text));+ }+});++export default connect(+ mapStateToProps,+ mapDispatchToProps+)(InfoList);++InfoList.propTypes = {+ openModal: PropTypes.func+};diff --git a/web/js/containers/modal.js b/web/js/containers/modal.jsindex cfad3d111..4a884dd89 100644--- a/web/js/containers/modal.js+++ b/web/js/containers/modal.js@@ -2,31 +2,86 @@ 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 { Modal, ModalBody, ModalHeader } from 'reactstrap';+import { customProps } from '../modules/modal/customs';import { onToggle } from '../modules/modal/actions';+import Crop from '../components/util/image-crop';+import DetectOuterClick from '../components/util/detect-outer-click';class ModalContainer extends Component {+ getStyle(props) {+ return {+ left: props.offsetLeft,+ right: props.offsetRight,+ width: props.width+ };+ }render() {- const { isCustom, id } = this.props;- const props =+ const { isCustom, id, isOpen } = this.props;+ // Populate props from custom obj+ const newProps =isCustom && id? update(this.props, { $merge: customProps[id] }): this.props;- return <Modal {...props} />;+ const {+ onToggle,+ bodyText,+ bodyHeader,+ headerComponent,+ headerText,+ modalClassName,+ backdrop,+ autoFocus,+ type+ } = newProps;+ const BodyComponent =+ customProps[id] && customProps[id].bodyComponent+ ? customProps[id].bodyComponent+ : '';+ const style = this.getStyle(newProps);+ return (+ <React.Fragment>+ <Modal+ isOpen={isOpen}+ toggle={onToggle}+ backdrop={backdrop}+ id={id}+ className={modalClassName || 'default-modal'}+ autoFocus={autoFocus || false}+ style={style}+ >+ <DetectOuterClick onClick={onToggle} disabled={!isOpen}>+ {headerComponent || headerText ? (+ <ModalHeader toggle={onToggle}>+ {headerComponent ? <headerComponent /> : headerText || ''}+ </ModalHeader>+ ) : (+ ''+ )}+ <ModalBody>+ {bodyHeader ? <h3>{bodyHeader}</h3> : ''}+ {BodyComponent ? <BodyComponent /> : bodyText || ''}+ </ModalBody>+ </DetectOuterClick>+ </Modal>+ {isOpen && type === 'selection' ? <Crop /> : ''}+ </React.Fragment>+ );}}function mapStateToProps(state) {- const { isOpen, bodyText, headerText, isCustom, key } = state;- const id = key;+ const { models } = state.models;+ const { bodyText, headerText, isCustom, id, isOpen } = state.modal;return {- isOpen,+ isOpen: isOpen,bodyText,headerText,isCustom,- id+ id,+ models};}const mapDispatchToProps = dispatch => ({@@ -39,3 +94,12 @@ export default connect(mapStateToProps,mapDispatchToProps)(ModalContainer);++ModalContainer.propTypes = {+ isCustom: PropTypes.bool,+ id: PropTypes.string+};+ModalContainer.defualtProps = {+ type: 'default',+ backdrop: true+};diff --git a/web/js/containers/permalink.js b/web/js/containers/permalink.jsnew file mode 100644index 000000000..d2c11fac7--- /dev/null+++ b/web/js/containers/permalink.js@@ -0,0 +1,24 @@+import React, { Component } from 'react';+import PropTypes from 'prop-types';+import { connect } from 'react-redux';+import Share from '../components/share/share';++class Permalink extends Component {+ render() {+ return <Share />;+ }+}++function mapStateToProps(state) {+ const { projection } = state.projection;++ return {+ projection+ };+}++export default connect(mapStateToProps)(Permalink);++Permalink.propTypes = {+ projection: PropTypes.string+};diff --git a/web/js/containers/projection.js b/web/js/containers/projection.jsnew file mode 100644index 000000000..9d695c33e--- /dev/null+++ b/web/js/containers/projection.js@@ -0,0 +1,65 @@+import React, { Component } from 'react';+import PropTypes from 'prop-types';+import { connect } from 'react-redux';+import { changeProjection } from '../modules/projection/actions';+import IconList from '../components/util/list';++const infoArray = [+ {+ text: 'Arctic',+ iconClass: 'ui-icon icon-large fa fa-arrow-circle-up fa-fw',+ id: 'change-arctic-button',+ key: 'arctic'+ },+ {+ text: 'Geographic',+ iconClass: 'ui-icon icon-large fa fa-circle fa-fw',+ id: 'change-geographic-button',+ key: 'geographic'+ },+ {+ text: 'Antarctic',+ iconClass: 'ui-icon icon-large fa fa-arrow-circle-down fa-fw',+ id: 'change-antarctic-button',+ key: 'antarctic'+ }+];++class ProjectionList extends Component {+ updateProjection(id) {+ const { updateProjection, models } = this.props;+ models.proj.select(id); // state migration crutch+ updateProjection(id);+ }+ render() {+ const { projection } = this.props;+ return (+ <IconList+ list={infoArray}+ active={projection}+ onClick={this.updateProjection.bind(this)}+ size="small"+ />+ );+ }+}+function mapStateToProps(state) {+ return {+ models: state.models.models,+ projection: state.projection.id+ };+}+const mapDispatchToProps = (dispatch, ownProps) => ({+ updateProjection: id => {+ dispatch(changeProjection(id));+ }+});++export default connect(+ mapStateToProps,+ mapDispatchToProps+)(ProjectionList);++ProjectionList.propTypes = {+ openModal: PropTypes.func+};diff --git a/web/js/containers/share.js b/web/js/containers/share.jsnew file mode 100644index 000000000..32eb259aa--- /dev/null+++ b/web/js/containers/share.js@@ -0,0 +1,79 @@+import React, { Component } from 'react';+import PropTypes from 'prop-types';+import { connect } from 'react-redux';+import ShareLinks from '../components/share/links';+import { getSharelink, openPromisedSocial } from '../modules/link/util';+import { CopyToClipboard } from 'react-copy-to-clipboard';+import { Checkbox } from '../components/util/checkbox';++class ShareLinkContainer extends Component {+ onToggleShorten() {}+ onLinkClick(type) {+ const { models } = this.props;+ var href, win;+ var shareLink = models.link.get();+ var promise = models.link.shorten();++ // If a short link can be generated, replace the full link.+ if (type === 'twitter' || type === 'email') {+ win = window;+ if (type === 'twitter') {+ win = window.open('', '_blank');+ }+ promise+ .done(function(result) {+ if (result.status_code === 200) {+ href = getSharelink(type, result.data.url);+ openPromisedSocial(href, win);+ }+ })+ .fail(function() {+ href = getSharelink(type, shareLink);+ openPromisedSocial(href, win);+ console.warn('Unable to shorten URL, full link generated.');+ });+ } else {+ href = getSharelink(type, shareLink);+ window.open(href, '_blank');+ }+ }+ render() {+ const { models } = this.props;+ return (+ <React.Fragment>+ <div className="wv-link" id="wv-link">+ <input+ type="text"+ value=""+ name="permalink_content"+ id="permalink_content"+ />+ <CopyToClipboard text="Copied!">+ <button>COPY</button>+ </CopyToClipboard>+ <Checkbox+ label="Shorten link"+ id="wv-link-shorten"+ onCheck={this.onToggleShorten.bind(this)}+ checked={false}+ />+ </div>+ <ShareLinks onClick={this.onLinkClick.bind(this)} />+ </React.Fragment>+ );+ }+}++function mapStateToProps(state) {+ const { models } = state.models;++ return {+ models+ };+}++export default connect(mapStateToProps)(ShareLinkContainer);++ShareLinkContainer.propTypes = {+ projection: PropTypes.string+};