Interactive interface for browsing global, full-resolution satellite imagery
Reduxify link module #1576
Benjamin King6427494cc2ed
diff --git a/web/css/link.css b/web/css/link.cssindex 2576af038..9ac06bb87 100644--- a/web/css/link.css+++ b/web/css/link.css@@ -102,28 +102,17 @@display: none;}-#wv-link-shorten {- position: relative;- margin-top: 15px;- width: 100%;- color: #fff;-}--#wv-link-shorten label {- vertical-align: middle;- margin-left: 4px;-}--#social-share {+.social-share {padding-top: 12px;display: -webkit-box;display: -ms-flexbox;display: flex;-ms-flex-pack: distribute;justify-content: space-around;+ border-top: 1px solid #555;}-#social-share .icon-link {+.social-share .icon-link {background-color: #000;border-radius: 50%;color: #fff;@@ -133,24 +122,26 @@width: 48px;font-size: 24px;text-align: center;+ cursor: pointer;+ text-decoration: none;}-#social-share .facebook {+.social-share .facebook {background-color: #3b5998;}-#social-share .twitter {+.social-share .twitter {background-color: #00aced;}-#social-share .reddit {+.social-share .reddit {background-color: #ff5700;}-#social-share .fa-google-plus {+.social-share .fa-google-plus {background-color: #d34836;}-#social-share .email {+.social-share .email {background-color: #505050;}diff --git a/web/css/modal.css b/web/css/modal.cssindex 46578d8d4..97667b536 100644--- a/web/css/modal.css+++ b/web/css/modal.css@@ -15,14 +15,25 @@.toolbar-list-modal .modal-content {width: 150px;}+.toolbar-list-modal .modal-body {+ padding: 0;+}+.toolbar-snapshot-modal .modal-body {+ padding: 5px 10px;+}.toolbar-medium-modal,.toolbar-medium-modal .modal-content {width: 230px;}+.toolbar-share-modal .modal-content {+ width: 300px;+}+.toolbar-medium-modal .modal-header {+ border-bottom:none;+ padding: 5px 8px 0px;++}.toolbar-modal.modal-dialog {position: absolute;top: 33px;}-.toolbar-modal .modal-body {- padding: 0;-};\ No newline at end of filediff --git a/web/js/app.js b/web/js/app.jsindex 0f5f24c26..a1979fd99 100644--- a/web/js/app.js+++ b/web/js/app.js@@ -1,9 +1,11 @@import React from 'react';import { connect } from 'react-redux';-import lodashEach from 'lodash/each';+import { debounce as lodashDebounce, each as lodashEach } from 'lodash';import googleTagManager from 'googleTagManager';+// Permalink+import Permalink from './containers/permalink';// Utilsimport util from './util/util';@@ -71,15 +73,9 @@ import naturalEventsModel from './natural-events/model';import naturalEventsUI from './natural-events/ui';import naturalEventsRequest from './natural-events/request';-// Image-// import { imageRubberband } from './image/rubberband';-// import { imagePanel } from './image/panel';--// Notifications-// import { notificationsUi } from './notifications/ui';-// UIimport loadingIndicator from './ui/indicator';+// Toolbarimport Toolbar from './containers/toolbar';// Link@@ -102,7 +98,7 @@ import tour from './tour';// Crutch between state systemsimport { sendConfigToStore } from './modules/migration/actions';-+import { updatePermalink } from './modules/link/actions';// Dependency CSSimport '../../node_modules/bootstrap/dist/css/bootstrap.css';import '../../node_modules/jquery-ui-bundle/jquery-ui.structure.css';@@ -173,6 +169,7 @@ class App extends React.Component {render() {return (<div className="wv-content" id="wv-content" data-role="content">+ <Permalink /><Toolbar /><section id="wv-sidebar" /><div id="layer-modal" className="layer-modal" />@@ -386,6 +383,7 @@ class App extends React.Component {});models.map = mapModel(models, config);models.link = linkModel(config);+if (config.features.compare) {models.compare = compareModel(models, config);models.link.register(models.compare);@@ -486,12 +484,21 @@ class App extends React.Component {var request = naturalEventsRequest(models, ui, config);ui.naturalEvents = naturalEventsUI(models, ui, config, request);}+ // ui.link = linkUi(models, config);if (config.features.alert) {// ui.alert = notificationsUi(ui, config);}if (config.features.compare) {ui.compare = compareUi(models, ui, config);}+ // permalink Cruch+ models.link.events.on(+ 'update',+ lodashDebounce(+ () => self.props.updatePermalink(models.link.toQueryString()),+ 100+ )+ );// FIXME: Old hack$(window).resize(function() {if (util.browser.small) {@@ -596,6 +603,9 @@ function registerMapMouseHandlers(maps, events) {const mapDispatchToProps = dispatch => ({updateConfig: (models, configObject) => {dispatch(sendConfigToStore(models, configObject));+ },+ updatePermalink: permalink => {+ dispatch(updatePermalink(permalink));}});diff --git a/web/js/components/share/links.js b/web/js/components/share/links.jsindex 863381fda..d0fa310c4 100644--- a/web/js/components/share/links.js+++ b/web/js/components/share/links.js@@ -9,7 +9,7 @@ class ShareLinks extends React.Component {render() {return (- <div id="social-share">+ <div id="social-share" className="social-share"><aid="fb-share"className="icon-link fab facebook fa-facebook-f fa-2x"diff --git a/web/js/containers/image-download.js b/web/js/containers/image-download.jsindex f19b11b32..4bf68d83b 100644--- a/web/js/containers/image-download.js+++ b/web/js/containers/image-download.js@@ -134,7 +134,7 @@ class ImageDownloadContainer extends Component {function mapStateToProps(state) {const { id } = state.projection;- const { config, models } = state.models;+ const { config, models } = state.legacy;let url = DEFAULT_URL;if (config.features.imageDownload && config.features.imageDownload.url) {url = config.features.imageDownload.url;diff --git a/web/js/containers/modal.js b/web/js/containers/modal.jsindex b59495f78..0976c9d16 100644--- a/web/js/containers/modal.js+++ b/web/js/containers/modal.js@@ -44,7 +44,8 @@ class ModalContainer extends Component {backdrop,autoFocus,type,- wrapClassName+ wrapClassName,+ clickableBehindModal} = newProps;const BodyComponent =customProps[id] && customProps[id].bodyComponent@@ -64,7 +65,7 @@ class ModalContainer extends Component {><DetectOuterClickonClick={onToggle}- disabled={!isOpen || type === 'selection'}+ disabled={!isOpen || type === 'selection' || clickableBehindModal}>{headerComponent || headerText ? (<ModalHeader toggle={onToggle}>@@ -90,7 +91,7 @@ class ModalContainer extends Component {}function mapStateToProps(state) {- const { models } = state.models;+ const { models } = state.legacy;const { bodyText, headerText, isCustom, id, isOpen, template } = state.modal;let bodyTemplate;let isTemplateModal = false;diff --git a/web/js/containers/permalink.js b/web/js/containers/permalink.jsindex d2c11fac7..9a160ea5b 100644--- a/web/js/containers/permalink.js+++ b/web/js/containers/permalink.js@@ -1,24 +1,39 @@-import React, { Component } from 'react';+import { Component } from 'react';import PropTypes from 'prop-types';import { connect } from 'react-redux';-import Share from '../components/share/share';+import util from '../util/util';+import { throttle } from 'lodash';++const replaceHistoryState = throttle(+ function(queryString) {+ if (util.browser.history) {+ window.history.replaceState('', '@OFFICIAL_NAME@', '?' + queryString);+ }+ },+ 2000,+ {+ leading: true,+ trailing: true+ }+);class Permalink extends Component {render() {- return <Share />;+ const { queryString } = this.props;+ if (queryString) replaceHistoryState(queryString);+ return '';}}function mapStateToProps(state) {- const { projection } = state.projection;-+ const { queryString } = state.link;return {- projection+ queryString: queryString};}export default connect(mapStateToProps)(Permalink);Permalink.propTypes = {- projection: PropTypes.string+ queryString: PropTypes.string};diff --git a/web/js/containers/projection.js b/web/js/containers/projection.jsindex 9d695c33e..125bceb4d 100644--- a/web/js/containers/projection.js+++ b/web/js/containers/projection.js@@ -45,7 +45,7 @@ class ProjectionList extends Component {}function mapStateToProps(state) {return {- models: state.models.models,+ models: state.legacy.models,projection: state.projection.id};}diff --git a/web/js/containers/share.js b/web/js/containers/share.jsindex 32eb259aa..43fa16f2f 100644--- a/web/js/containers/share.js+++ b/web/js/containers/share.js@@ -5,58 +5,177 @@ 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';+import { requestShortLink } from '../modules/link/actions';+import {+ InputGroupAddon,+ Input,+ InputGroup,+ Button,+ Tooltip+} from 'reactstrap';+const getShortenRequestString = function(mock, permalink) {+ const mockStr = mock || '';+ if (/localhost/.test(location)) {+ return 'mock/short_link.json';+ }+ return (+ 'service/link/shorten.cgi' ++ mockStr ++ '?url=' ++ encodeURIComponent(permalink)+ );+};class ShareLinkContainer extends Component {- onToggleShorten() {}- onLinkClick(type) {- const { models } = this.props;- var href, win;- var shareLink = models.link.get();- var promise = models.link.shorten();+ constructor(props) {+ super(props);+ this.state = {+ shortLinkKey: '',+ isShort: false,+ tooltipOpen: false+ };+ }+ getShortLink() {+ const { requestShortLink, mock } = this.props;+ const link = this.getPermalink();+ const location = getShortenRequestString(mock, link);+ return requestShortLink(location);+ }+ onToggleShorten() {+ const { queryString } = this.props;+ const { shortLinkKey, isShort } = this.state;+ if (!isShort && shortLinkKey !== queryString) {+ this.getShortLink();+ this.setState({+ shortLinkKey: queryString,+ isShort: !isShort+ });+ } else {+ this.setState({ isShort: !isShort });+ }+ }+ getPermalink() {+ const { queryString } = this.props;+ let url = window.location.href;+ let prefix = url.split('?')[0];+ prefix = prefix !== null && prefix !== undefined ? prefix : url;+ return !queryString ? prefix : prefix + '?' + queryString;+ }+ onLinkClick(type) {+ const permalink = this.getPermalink();// If a short link can be generated, replace the full link.if (type === 'twitter' || type === 'email') {- win = window;+ let promise = this.getShortLink();+ let win = window;if (type === 'twitter') {win = window.open('', '_blank');}promise- .done(function(result) {+ .then(function(result) {if (result.status_code === 200) {- href = getSharelink(type, result.data.url);+ const href = getSharelink(type, result.data.url);openPromisedSocial(href, win);}})- .fail(function() {- href = getSharelink(type, shareLink);+ .catch(function() {+ const href = getSharelink(type, permalink);openPromisedSocial(href, win);console.warn('Unable to shorten URL, full link generated.');});} else {- href = getSharelink(type, shareLink);+ let href = getSharelink(type, permalink);window.open(href, '_blank');}}+ static getDerivedStateFromProps(nextProps, prevState) {+ if (prevState.shortLinkKey !== nextProps.queryString) {+ return {+ isShort: false,+ shortLinkKey: ''+ };+ } else if (nextProps.shortLink.error && prevState.isShort) {+ return { isShort: false, showErrorTooltip: true };+ } else return null;+ }+ renderToolTips() {+ const { showErrorTooltip, tooltipOpen } = this.state;+ if (showErrorTooltip) {+ setTimeout(() => {+ this.setState({ showErrorTooltip: false });+ }, 2000);+ }+ return (+ <React.Fragment>+ <Tooltip+ placement="left"+ isOpen={showErrorTooltip}+ target="permalink_content"+ >+ Link cannot be shortened at this time.+ </Tooltip>+ <Tooltip+ placement="right"+ isOpen={tooltipOpen}+ target="copy-to-clipboard-button"+ >+ Copied!+ </Tooltip>+ </React.Fragment>+ );+ }render() {- const { models } = this.props;+ const { shortLink } = this.props;+ const { isShort } = this.state;++ const value =+ shortLink.isLoading && isShort+ ? 'Please wait...'+ : isShort &&+ shortLink.response &&+ shortLink.response.data &&+ shortLink.response.data.url+ ? shortLink.response.data.url+ : this.getPermalink();+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>+ <div>+ {this.renderToolTips()}+ <InputGroup>+ <Input+ type="text"+ value={value}+ name="permalink_content"+ id="permalink_content"+ onChange={e => {+ e.preventDefault();+ }}+ />++ <CopyToClipboard+ text={value}+ onCopy={() => {+ this.setState({ tooltipOpen: true });+ setTimeout(() => {+ this.setState({ tooltipOpen: false });+ }, 2000);+ }}+ >+ <InputGroupAddon addonType="append">+ <Button id="copy-to-clipboard-button">COPY</Button>+ </InputGroupAddon>+ </CopyToClipboard>+ </InputGroup>+ <br /><Checkboxlabel="Shorten link"id="wv-link-shorten"onCheck={this.onToggleShorten.bind(this)}- checked={false}+ checked={isShort}+ disabled={!shortLink.isLoading}/>+ <br /></div><ShareLinks onClick={this.onLinkClick.bind(this)} /></React.Fragment>@@ -65,14 +184,28 @@ class ShareLinkContainer extends Component {}function mapStateToProps(state) {- const { models } = state.models;+ const { queryString } = state.link;+ const { config } = state.legacy;return {- models+ queryString: queryString,+ shortLink: state.shortLink,+ mock:+ config.parameters && config.parameters.shorten+ ? config.parameters.shorten+ : ''};}+const mapDispatchToProps = dispatch => ({+ requestShortLink: (location, signal) => {+ return dispatch(requestShortLink(location, 'json', signal));+ }+});-export default connect(mapStateToProps)(ShareLinkContainer);+export default connect(+ mapStateToProps,+ mapDispatchToProps+)(ShareLinkContainer);ShareLinkContainer.propTypes = {projection: PropTypes.stringdiff --git a/web/js/link/model.js b/web/js/link/model.jsindex 077c5f29e..d7ff5092a 100644--- a/web/js/link/model.js+++ b/web/js/link/model.js@@ -3,40 +3,32 @@ import lodashMap from 'lodash/map';import lodashIsArray from 'lodash/isArray';import lodashIsObject from 'lodash/isObject';import util from '../util/util';-import Cache from 'cachai';export function linkModel(config) {var self = {};- var DEBUG_SHORTEN_LINK = 'http://go.nasa.gov/1iKIZ4j';var ENCODING_EXCEPTIONS = [{match: new RegExp('%2C', 'g'),replace: ','- }, {+ },+ {match: new RegExp('%3B', 'g'),replace: ';'- }, {+ },+ {match: new RegExp('%3D', 'g'),replace: '='}];-- var shortenCache = new Cache(10);- var mock = '';var components = [];-self.events = util.events();- var init = function () {- if (config && config.parameters && config.parameters.shorten) {- mock = '-' + config.parameters.shorten;- }- };+ var init = function() {};- self.register = function (component) {+ self.register = function(component) {components.push(component);if (component.events) {- component.events.any(function () {+ component.events.any(function() {self.events.trigger('update');});}@@ -44,21 +36,21 @@ export function linkModel(config) {};// Returns a serialized string containing information of the current session- self.toQueryString = function () {+ self.toQueryString = function() {var state = {};- lodashEach(components, function (component) {+ lodashEach(components, function(component) {component.save(state);});- var strings = lodashMap(state, function (value, key) {+ var strings = lodashMap(state, function(value, key) {if (lodashIsArray(value)) {var parts = [];- lodashEach(value, function (item) {+ lodashEach(value, function(item) {var part = '';if (lodashIsObject(item)) {part = item.id;if (item.attributes && item.attributes.length > 0) {var attributes = [];- lodashEach(item.attributes, function (attribute) {+ lodashEach(item.attributes, function(attribute) {if (attribute.value) {attributes.push(attribute.id + '=' + attribute.value);} else {@@ -79,46 +71,16 @@ export function linkModel(config) {return strings.join('&');};- self.get = function () {- var queryString = self.toQueryString();- var url = window.location.href;- var prefix = url.split('?')[0];- prefix = (prefix !== null && prefix !== undefined) ? prefix : url;- return prefix + '?' + queryString;- };-- self.shorten = function (link) {- if (!link) {- link = self.get();- }- if (shortenCache[link]) {- return $.Deferred().resolve(shortenCache[link]);- }- if (/localhost/.test(link)) {- return $.Deferred().resolve({- status_code: 200,- data: {- url: DEBUG_SHORTEN_LINK- }- });- }- var promise = $.getJSON('service/link/shorten.cgi' + mock + '?url=' + encodeURIComponent(link));- promise.done(function (result) {- shortenCache[link] = result;- });- return promise;- };-- self.load = function (state, errors) {+ self.load = function(state, errors) {errors = errors || [];- lodashEach(components, function (component) {+ lodashEach(components, function(component) {component.load(state, errors);});};- var encode = function (value) {+ var encode = function(value) {var encoded = encodeURIComponent(value);- lodashEach(ENCODING_EXCEPTIONS, function (exception) {+ lodashEach(ENCODING_EXCEPTIONS, function(exception) {encoded = encoded.replace(exception.match, exception.replace);});return encoded;@@ -127,4 +89,4 @@ export function linkModel(config) {init();return self;-};+}diff --git a/web/js/link/ui.js b/web/js/link/ui.jsindex ec79b6786..e7c685f28 100644--- a/web/js/link/ui.js+++ b/web/js/link/ui.js@@ -1,48 +1,11 @@-import 'jquery-ui-bundle/jquery-ui';-import 'icheck';import lodashThrottle from 'lodash/throttle';-import React from 'react';-import ReactDOM from 'react-dom';-import Clipboard from 'clipboard';-import Share from '../components/share/share';-import googleTagManager from 'googleTagManager';import util from '../util/util';-import wvui from '../ui/ui';export function linkUi(models, config) {var self = {};- var id = 'wv-link-button';- var selector = '#' + id;- var $button, $label;- var clipboard = new Clipboard('.copy-btn');var init = function() {- $button = $('<input></input>')- .attr('type', 'checkbox')- .attr('id', 'wv-link-button-check');- $label = $('<label></label>')- .attr('for', 'wv-link-button-check')- .attr('title', 'Share this map');- var $icon = $('<i></i>').addClass('fas fa-share-square fa-2x');- $label.append($icon);- $(selector).append($label);- $(selector).append($button);- $button- .button({- text: false- })- .click(function() {- var checked = $('#wv-link-button-check').prop('checked');- googleTagManager.pushEvent({- event: 'social_link_share'- });- if (checked) {- self.show();- } else {- wvui.closeDialog();- }- });models.link.events.on('update', replaceHistoryState);};@@ -64,247 +27,6 @@ export function linkUi(models, config) {});- // Facebook: https://developers.facebook.com/docs/sharing/reference/share-dialog#redirect- var facebookUrlParams = function(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- var twitterUrlParams = function(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]- var redditUrlParams = function(url, title) {- return (- 'https://www.reddit.com/r/nasa/submit?' +- 'url=' +- encodeURIComponent(url) +- '&title=' +- encodeURIComponent(title)- );- };-- // Email: mailto:?subject=[SUBJECT]&body=[BODY]- var emailUrlParams = function(subject, body) {- return (- 'mailto:?' +- 'subject=' +- encodeURIComponent(subject) +- '&body=' +- encodeURIComponent(body)- );- };-- var getSharelink = function(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;- googleTagManager.pushEvent({- event: 'social_share_platform',- social_type: type- });-- 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;- };- var openPromisedSocial = function(url, win) {- win.location.assign(url);- };- var clickFunction = function(type) {- 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');- }- };-- self.show = function() {- var $dialog = wvui.getDialog();- var item =- "<div id='wv-link' class='wv-link'>" +- "<div class='input-group'>" +- "<input type='text' value='' name='permalink_content' id='permalink_content' readonly/>" +- "<span class='input-group-button hide-icon' data-balloon-visible data-tooltip='Copied!' data-tooltip-pos='up' data-tooltip-length='xsmall'>" +- "<button title='Copy to clipboard' class='copy-btn' data-clipboard-target='#permalink_content'>COPY</button>" +- '</span>' +- '</div>';- if (config.features.urlShortening) {- item +=- "<span autofocus></span><div id='wv-link-shorten'>" +- "<input type='checkbox' value='' id='wv-link-shorten-check' />" +- "<label id='wv-link-shorten-label' for='wv-link-shorten-check'>Shorten link</label>" +- '</div>';- }- item += '</div>';-- var dialogWidth = '300';- if (util.browser.small) {- dialogWidth = '242';- }-- var Widget = React.createElement(Share, {- clickFunction: clickFunction,- fbLink: '#',- twLink: '#',- rdLink: '#',- emailLink: '#'- });-- // Render Dialog Box Content- self.reactComponent = ReactDOM.render(Widget, $dialog[0]);-- // If selected during the animation, the cursor will go to the- // end of the input box- var updateLink = function() {- $('#permalink_content').val(models.link.get());- $('#wv-link-shorten-check').iCheck('uncheck');- $('#permalink_content').focus();- $('#permalink_content').select();- };-- models.link.events.on('update', updateLink);-- $dialog- .dialog({- dialogClass: 'wv-panel wv-link-panel',- title: 'Copy link to share:',- show: {- effect: 'slide',- direction: 'up'- },- width: dialogWidth,- height: 'auto',- minHeight: 10,- draggable: false,- resizable: false,- autoOpen: false,- closeText: ''- })- .on('dialogcreate', $dialog.prepend(item))- .on('dialogclose', function() {- $('#wv-link-button-check').prop('checked', false);- $button.button('refresh');- models.link.events.off('update', updateLink);- });- if (util.browser.small) {- wvui.positionDialog($dialog, {- my: 'right top',- at: 'right-58 bottom+5',- of: '#wv-toolbar'- });- } else {- wvui.positionDialog($dialog, {- my: 'right top',- at: 'right bottom+5',- of: $label- });- }-- $('#permalink_content').val(models.link.get());- $dialog.dialog('open');- setTimeout(updateLink, 500);-- $('#wv-link-shorten-check').on('change', function() {- var checked = $('#wv-link-shorten-check').prop('checked');- if (checked) {- var promise = models.link.shorten();- googleTagManager.pushEvent({- event: 'social_link_shorten'- });- $('#permalink_content').val('Please wait...');- promise- .done(function(result) {- if (result.status_code === 200) {- $('#permalink_content').val(result.data.url);- } else {- error(result.status_code, result.status_txt);- }- })- .fail(function(jqXHR, textStatus, errorThrown) {- error(textStatus, errorThrown);- });- } else {- $('#permalink_content').val(models.link.get());- }- $('#permalink_content').focus();- $('#permalink_content').select();- });-- var error = function() {- console.warn('Unable to shorten URL');- console.warn.apply(console, arguments);- wvui.notify(- 'Unable to shorten the permalink at this time. ' +- 'Please try again later.'- );- };-- $('#wv-link-shorten-check').prop('checked', false);-- clipboard.on('success', function(e) {- e.clearSelection();-- $('.wv-link .input-group-button').removeClass('hide-icon');-- setTimeout(function() {- $('.wv-link .input-group-button').addClass('hide-icon');- }, 1000);- });-- clipboard.on('error', function(e) {- console.error('Link could not be copied!');- console.error('Action:', e.action);- console.error('Trigger:', e.trigger);- });- };-init();return self;}diff --git a/web/js/main.js b/web/js/main.jsindex 980784808..53766dee4 100644--- a/web/js/main.js+++ b/web/js/main.js@@ -5,17 +5,20 @@ import App from './app';import { Provider } from 'react-redux';import { createStore, combineReducers, applyMiddleware } from 'redux';import { modalReducer, modalAboutPage } from './modules/modal/reducers';-import modelReducer from './modules/migration/reducers';+import legacyReducer from './modules/migration/reducers';import feedbackReducer from './modules/feedback/reducers';import projectionReducer from './modules/projection/reducer';+import { shortLink, linkReducer } from './modules/link/reducers';import thunk from 'redux-thunk';const reducers = {projection: projectionReducer,modal: modalReducer,- models: modelReducer,+ legacy: legacyReducer,feedback: feedbackReducer,- modalAboutPage+ link: linkReducer,+ modalAboutPage,+ shortLink};const store = createStore(combineReducers(reducers), applyMiddleware(thunk));diff --git a/web/js/modules/core/actions.js b/web/js/modules/core/actions.jsindex 0e933a66d..52ad3636f 100644--- a/web/js/modules/core/actions.js+++ b/web/js/modules/core/actions.js@@ -1,17 +1,21 @@import { fetch } from 'whatwg-fetch';-export function requestAction(dispatch, actionName, url, fileType) {+export function requestAction(dispatch, actionName, url, fileType, signal) {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));- });+ return new Promise(function(resolve, reject) {+ return fetch(url, { signal })+ .then(function(response) {+ return fileType === 'json' ? response.json() : response.text();+ })+ .then(function(data) {+ dispatch(fetchSuccess(actionName, data));+ resolve(data);+ })+ .catch(function(err) {+ dispatch(fetchFailure(actionName, err));+ reject(err);+ });+ });}export function startRequest(actionName) {return {diff --git a/web/js/modules/core/reducers.js b/web/js/modules/core/reducers.jsindex 217d2657d..cfadcd0d4 100644--- a/web/js/modules/core/reducers.js+++ b/web/js/modules/core/reducers.js@@ -5,8 +5,8 @@ export function requestResponse(props = {}) {{},{isLoading: false,- error: {},- response: {},+ error: null,+ response: null,type: null},props@@ -21,19 +21,17 @@ export function requestReducer(actionName, state, action) {case START:return requestResponse({response: state.response,- isLoading: true,- type: action.type+ isLoading: true});case SUCCESS:return requestResponse({response: action.response,- isLoading: false,- type: action.type+ isLoading: false});case FAILURE:return requestResponse({error: action.error,- type: action.type+ isLoading: false});default:return state;diff --git a/web/js/modules/link/actions.js b/web/js/modules/link/actions.jsindex 14bece0ac..e0883065b 100644--- a/web/js/modules/link/actions.js+++ b/web/js/modules/link/actions.js@@ -1,7 +1,19 @@-import { TOGGLE_URL } from './constants';+import { TOGGLE_URL, UPDATE_PERMALINK, REQUEST_SHORT_LINK } from './constants';+import { requestAction } from '../core/actions';export function toggleUrl() {return {type: TOGGLE_URL};}+export function updatePermalink(queryString) {+ return {+ type: UPDATE_PERMALINK,+ queryString: queryString+ };+}+export function requestShortLink(location, type, signal, debug) {+ return dispatch => {+ return requestAction(dispatch, REQUEST_SHORT_LINK, location, type, signal);+ };+}diff --git a/web/js/modules/link/constants.js b/web/js/modules/link/constants.jsindex 97f574a85..372656a3c 100644--- a/web/js/modules/link/constants.js+++ b/web/js/modules/link/constants.js@@ -1 +1,9 @@export const TOGGLE_URL = 'TOGGLE_SHARE_LINK';+export const UPDATE_PERMALINK = 'UPDATE_PERMALINK';++export const REQUEST_SHORT_LINK_START = 'REQUEST_BITLY_SHORTENED_LINK_START';+export const REQUEST_SHORT_LINK_SUCCESS =+ 'REQUEST_BITLY_SHORTENED_LINK_SUCCESS';+export const REQUEST_SHORT_LINKE_FAILURE =+ 'REQUEST_BITLY_SHORTENED_LINK_FAILURE';+export const REQUEST_SHORT_LINK = 'REQUEST_BITLY_SHORTENED_LINK';diff --git a/web/js/modules/link/reducer.js b/web/js/modules/link/reducer.jsdeleted file mode 100644index 9ed08d209..000000000--- a/web/js/modules/link/reducer.js+++ /dev/null@@ -1,17 +0,0 @@-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/reducers.js b/web/js/modules/link/reducers.jsnew file mode 100644index 000000000..1d88799d1--- /dev/null+++ b/web/js/modules/link/reducers.js@@ -0,0 +1,22 @@+import { UPDATE_PERMALINK, REQUEST_SHORT_LINK } from './constants';+import { requestReducer } from '../core/reducers';+import { assign as lodashAssign } from 'lodash';++const linkState = {+ permalink: ''+};++export function shortLink(state = {}, action) {+ return requestReducer(REQUEST_SHORT_LINK, state, action);+}++export function linkReducer(state = linkState, action) {+ switch (action.type) {+ case UPDATE_PERMALINK:+ return lodashAssign({}, state, {+ queryString: action.queryString+ });+ default:+ return state;+ }+}diff --git a/web/js/modules/migration/constants.js b/web/js/modules/migration/constants.jsindex 8bd5e43a3..b630296bd 100644--- a/web/js/modules/migration/constants.js+++ b/web/js/modules/migration/constants.js@@ -1 +1 @@-export const CONFIG_HAS_BEEN_LOADED = 'CONFIG_HAVE_BEEN_LOADED';+export const CONFIG_HAS_BEEN_LOADED = 'CONFIG_AND_MODELS_HAVE_BEEN_LOADED';diff --git a/web/js/modules/migration/reducers.js b/web/js/modules/migration/reducers.jsindex 1d8342852..e59fe991c 100644--- a/web/js/modules/migration/reducers.js+++ b/web/js/modules/migration/reducers.js@@ -1,14 +1,13 @@import { CONFIG_HAS_BEEN_LOADED } from './constants';import { assign as lodashAssign } from 'lodash';-const modelsState = {+const legacyState = {loaded: false,models: {},config: {}};-export default function modelsReducer(state = modelsState, action) {- console.log(action);+export default function legacyReducer(state = legacyState, action) {switch (action.type) {case CONFIG_HAS_BEEN_LOADED:return lodashAssign({}, state, {diff --git a/web/js/modules/modal/actions.js b/web/js/modules/modal/actions.jsindex 1670d986d..949c49802 100644--- a/web/js/modules/modal/actions.js+++ b/web/js/modules/modal/actions.js@@ -1,6 +1,6 @@import util from '../../util/util';import { OPEN_BASIC, OPEN_CUSTOM, TOGGLE, RENDER_TEMPLATE } from './constants';-import { actionOrienter, requestAction } from '../core/actions';+import { requestAction } from '../core/actions';export function openBasicContent(modalHeader, bodyText) {return {diff --git a/web/js/modules/modal/customs.js b/web/js/modules/modal/customs.jsindex 43b69b822..7498ec5fa 100644--- a/web/js/modules/modal/customs.js+++ b/web/js/modules/modal/customs.js@@ -13,11 +13,13 @@ export const customProps = {offsetRight: '40px'},TOOLBAR_SHARE_LINK: {- headerText: 'Copy link to share:',+ 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: {@@ -25,6 +27,7 @@ export const customProps = {backdrop: false,type: 'toolbar',modalClassName: 'toolbar-list-modal toolbar-modal',+offsetRight: '10px',bodyComponent: InfoList},diff --git a/web/mock/short_link.json b/web/mock/short_link.jsonnew file mode 100644index 000000000..fd04bf571--- /dev/null+++ b/web/mock/short_link.json@@ -0,0 +1,7 @@+{+ "data": {+ "url": "http://go.nasa.gov/1iKIZ4j"+ },+ "status_code": 200,+ "status_txt": "OK"+}\ No newline at end of file