Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

make sure social links work

Jason Kent02854e7da6e7
diff --git a/web/js/components/toolbar/share/links.js b/web/js/components/toolbar/share/links.js
index 68661f68a..1754969d0 100644
--- a/web/js/components/toolbar/share/links.js
+++ b/web/js/components/toolbar/share/links.js
@@ -18,7 +18,6 @@ class ShareLinks extends React.Component {
<a
id="fb-share"
className="icon-link social-icon-container-facebook"
- href="#"
onClick={(e) => this.onClick(e, 'facebook')}
title="Share via Facebook!"
>
@@ -27,7 +26,6 @@ class ShareLinks extends React.Component {
<a
id="tw-share"
className="icon-link social-icon-container-twitter"
- href="#"
onClick={(e) => this.onClick(e, 'twitter')}
title="Share via Twitter!"
>
@@ -36,7 +34,6 @@ class ShareLinks extends React.Component {
<a
id="rd-share"
className="icon-link social-icon-container-reddit-alien"
- href="#"
onClick={(e) => this.onClick(e, 'reddit')}
title="Share via Reddit!"
>
@@ -45,7 +42,6 @@ class ShareLinks extends React.Component {
<a
id="email-share"
className="icon-link social-icon-container-email"
- href="#"
onClick={(e) => this.onClick(e, 'email')}
title="Share via Email!"
>
diff --git a/web/js/components/toolbar/share/share.js b/web/js/components/toolbar/share/share.js
deleted file mode 100644
index e64574ee4..000000000
--- a/web/js/components/toolbar/share/share.js
+++ /dev/null
@@ -1,43 +0,0 @@
-import React from 'react';
-import PropTypes from 'prop-types';
-import ShareLinks from './links';
-
-class Share extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- fbLink: props.fbLink,
- twLink: props.twLink,
- rdLink: props.rdLink,
- emailLink: props.emailLink,
- };
- }
-
- render() {
- const {
- fbLink, twLink, rdLink, emailLink,
- } = this.state;
- const { clickFunction } = this.props;
- return (
- <div>
- <ShareLinks
- fbLink={fbLink}
- twLink={twLink}
- rdLink={rdLink}
- emailLink={emailLink}
- onClick={clickFunction}
- />
- </div>
- );
- }
-}
-
-Share.propTypes = {
- clickFunction: PropTypes.func,
- emailLink: PropTypes.string,
- fbLink: PropTypes.string,
- rdLink: PropTypes.string,
- twLink: PropTypes.string,
-};
-
-export default Share;
diff --git a/web/js/containers/share.js b/web/js/containers/share.js
index e10741e46..1e8e1e2d9 100644
--- a/web/js/containers/share.js
+++ b/web/js/containers/share.js
@@ -11,7 +11,7 @@ import {
} from 'reactstrap';
import ShareLinks from '../components/toolbar/share/links';
import ShareToolTips from '../components/toolbar/share/tooltips';
-import { encode, getSharelink, openPromisedSocial } from '../modules/link/util';
+import { encode, getSharelink } from '../modules/link/util';
import { serializeDate } from '../modules/date/util';
import getSelectedDate from '../modules/date/selectors';
import Checkbox from '../components/util/checkbox';
@@ -136,32 +136,25 @@ class ShareLinkContainer extends Component {
onLinkClick = (type) => {
const permalink = this.getPermalink();
+ let shareLink = getSharelink(type, permalink);
+
googleTagManager.pushEvent({
event: 'social_share_platform',
social_type: type,
});
+
// If a short link can be generated, replace the full link.
if (type === 'twitter' || type === 'email') {
- const promise = this.getShortLink();
- let win = window;
- if (type === 'twitter') {
- win = window.open('', '_blank');
- }
- promise
- .then((result) => {
- if (result.status_code === 200) {
- const href = getSharelink(type, result.data.url);
- openPromisedSocial(href, win);
- }
+ this.getShortLink()
+ .then(({ data }) => {
+ shareLink = getSharelink(type, data.url);
})
.catch(() => {
- const href = getSharelink(type, permalink);
- openPromisedSocial(href, win);
console.warn('Unable to shorten URL, full link generated.');
- });
+ })
+ .finally(() => window.open(shareLink, '_blank'));
} else {
- const href = getSharelink(type, permalink);
- window.open(href, '_blank');
+ window.open(shareLink, '_blank');
}
}
diff --git a/web/js/modules/link/util.js b/web/js/modules/link/util.js
index 340958802..32001bb5a 100644
--- a/web/js/modules/link/util.js
+++ b/web/js/modules/link/util.js
@@ -47,6 +47,7 @@ export function emailUrlParams(subject, body) {
encodeURIComponent(body)}`
);
}
+
export function getSharelink(type, url) {
const shareMessage = 'Check out what I found in NASA Worldview!';
const twMessage = 'Check out what I found in #NASAWorldview -';
@@ -65,9 +66,7 @@ export function getSharelink(type, url) {
return undefined;
}
}
-export function openPromisedSocial(url, win) {
- win.location.assign(url);
-}
+
export function encode(value) {
let encoded = encodeURIComponent(value);
lodashEach(ENCODING_EXCEPTIONS, (exception) => {