Commit 9c06646f authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Update sharing links to open in blank browser window

Pull out and consolidate local subcomponent `ShareLink` to make sure
all sharing links are created equal.

Fixes https://github.com/hypothesis/browser-extension/issues/261
parent bf4c06c2
...@@ -7,10 +7,42 @@ const { withServices } = require('../util/service-context'); ...@@ -7,10 +7,42 @@ const { withServices } = require('../util/service-context');
const SvgIcon = require('./svg-icon'); const SvgIcon = require('./svg-icon');
/**
* A single sharing link as a list item
*/
function ShareLink({ iconName, title, uri, onClick }) {
return (
<li className="share-links__link">
<a
href={uri}
title={title}
onClick={onClick}
target="_blank"
rel="noopener noreferrer"
>
<SvgIcon name={iconName} className="share-links__icon" />
</a>
</li>
);
}
ShareLink.propTypes = {
/** The name of the SVG icon to use for this link */
iconName: propTypes.string.isRequired,
/** link title */
title: propTypes.string.isRequired,
/** URI for sharing this annotation on the given social service */
uri: propTypes.string.isRequired,
/** click callback (for analytics tracking) */
onClick: propTypes.func.isRequired,
};
/** /**
* A list of share links to social-media platforms. * A list of share links to social-media platforms.
*/ */
function ShareLinks({ analytics, analyticsEventName, shareURI }) { function ShareLinks({ analytics, analyticsEventName, shareURI }) {
// Return a click callback that will track click events for the given
// social platform (`shareTarget`)
const trackShareClick = shareTarget => { const trackShareClick = shareTarget => {
return () => { return () => {
analytics.track(analyticsEventName, shareTarget); analytics.track(analyticsEventName, shareTarget);
...@@ -23,35 +55,28 @@ function ShareLinks({ analytics, analyticsEventName, shareURI }) { ...@@ -23,35 +55,28 @@ function ShareLinks({ analytics, analyticsEventName, shareURI }) {
return ( return (
<ul className="share-links"> <ul className="share-links">
<li className="share-links__link"> <ShareLink
<a iconName="twitter"
href={`https://twitter.com/intent/tweet?url=${encodedURI}&hashtags=annotated`}
title="Tweet share link" title="Tweet share link"
uri={`https://twitter.com/intent/tweet?url=${encodedURI}&hashtags=annotated`}
onClick={trackShareClick('twitter')} onClick={trackShareClick('twitter')}
> />
<SvgIcon name="twitter" className="share-links__icon" />
</a> <ShareLink
</li> iconName="facebook"
<li className="share-links__link">
<a
href={`https://www.facebook.com/sharer/sharer.php?u=${encodedURI}`}
title="Share on Facebook" title="Share on Facebook"
uri={`https://www.facebook.com/sharer/sharer.php?u=${encodedURI}`}
onClick={trackShareClick('facebook')} onClick={trackShareClick('facebook')}
> />
<SvgIcon name="facebook" className="share-links__icon" />
</a> <ShareLink
</li> iconName="email"
<li className="share-links__link"> title="Share via email"
<a uri={`mailto:?subject=${encodeURIComponent(
href={`mailto:?subject=${encodeURIComponent(
"Let's Annotate" "Let's Annotate"
)}&body=${encodedURI}`} )}&body=${encodedURI}`}
title="Share via email"
onClick={trackShareClick('email')} onClick={trackShareClick('email')}
> />
<SvgIcon name="email" className="share-links__icon" />
</a>
</li>
</ul> </ul>
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment