Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

only listen for permalink changes when link modal is open #1576

Benjamin King8284caff4914
diff --git a/web/js/containers/share.js b/web/js/containers/share.js
index ce51e8036..fb0f0948c 100644
--- a/web/js/containers/share.js
+++ b/web/js/containers/share.js
@@ -14,6 +14,8 @@ import {
Tooltip
} from 'reactstrap';
+import { history } from '../main';
+
const getShortenRequestString = function(mock, permalink) {
const mockStr = mock || '';
if (/localhost/.test(location)) {
@@ -32,9 +34,23 @@ class ShareLinkContainer extends Component {
this.state = {
shortLinkKey: '',
isShort: false,
- tooltipOpen: false
+ tooltipOpen: false,
+ queryString: history.location.search || ''
};
}
+ componentDidMount() {
+ this.unlisten = history.listen((location, action) => {
+ const newString = location.search;
+ const { queryString } = this.state;
+ if (queryString !== newString) {
+ this.setState({ queryString: newString });
+ }
+ });
+ }
+
+ componentWillUnmount() {
+ if (this.unlisten) this.unlisten();
+ }
getShortLink() {
const { requestShortLink, mock } = this.props;
const link = this.getPermalink();
@@ -42,8 +58,7 @@ class ShareLinkContainer extends Component {
return requestShortLink(location);
}
onToggleShorten() {
- const { queryString } = this.props;
- const { shortLinkKey, isShort } = this.state;
+ const { shortLinkKey, isShort, queryString } = this.state;
if (!isShort && shortLinkKey !== queryString) {
this.getShortLink();
@@ -56,7 +71,7 @@ class ShareLinkContainer extends Component {
}
}
getPermalink() {
- const { queryString } = this.props;
+ const { queryString } = this.state;
let url = window.location.href;
let prefix = url.split('?')[0];
prefix = prefix !== null && prefix !== undefined ? prefix : url;
@@ -184,11 +199,9 @@ class ShareLinkContainer extends Component {
}
function mapStateToProps(state) {
- const { queryString } = state.link;
const { config } = state;
return {
- queryString: queryString,
shortLink: state.shortLink,
mock:
config.parameters && config.parameters.shorten
diff --git a/web/js/main.js b/web/js/main.js
index 1d32be956..9b98e03b8 100644
--- a/web/js/main.js
+++ b/web/js/main.js
@@ -21,7 +21,6 @@ import loadingIndicator from './ui/indicator';
import Brand from './brand';
import { combineModels } from './combine-models';
import { parse } from './parse';
-import { updatePermalink } from './modules/link/actions';
import { combineUi } from './combine-ui';
import palettes from './palettes/palettes';
import { updateLegacyModule } from './modules/migration/actions';
@@ -30,7 +29,7 @@ import { polyfill } from './polyfill';
import { debugConfig } from './debug';
import { changeProjection } from './modules/projection/actions';
-const history = createBrowserHistory();
+export const history = createBrowserHistory();
const isDebugMode = typeof DEBUG !== 'undefined';
const configURI = Brand.url('config/wv.json');
const startTime = new Date().getTime();
@@ -108,15 +107,6 @@ const render = (config, parameters, legacyState) => {
store.dispatch(changeProjection(id, config));
}
});
-
- let queryString = '';
- history.listen((location, action) => {
- const newString = location.search;
- if (queryString !== newString) {
- queryString = newString;
- store.dispatch(updatePermalink(queryString)); // Keep permalink in redux-store
- }
- });
listenForHistoryChange(store, history);
elapsed('Render', startTime, parameters);
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index 62f1709b7..848125bb5 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -41,7 +41,6 @@ const reducers = {
modal: modalReducer,
legacy: legacyReducer,
feedback: feedbackReducer,
- link: linkReducer,
notifications: notificationsReducer,
config: defaultReducer,
models: defaultReducer,