Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
94398f41
Commit
94398f41
authored
Nov 18, 2019
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract `ShareLinks` sub-component for reuse
parent
249b7b2b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
155 additions
and
87 deletions
+155
-87
share-annotations-panel.js
src/sidebar/components/share-annotations-panel.js
+5
-48
share-links.js
src/sidebar/components/share-links.js
+69
-0
share-annotations-panel-test.js
src/sidebar/components/test/share-annotations-panel-test.js
+0
-39
share-links-test.js
src/sidebar/components/test/share-links-test.js
+70
-0
share-links.scss
src/styles/sidebar/components/share-links.scss
+10
-0
sidebar.scss
src/styles/sidebar/sidebar.scss
+1
-0
No files found.
src/sidebar/components/share-annotations-panel.js
View file @
94398f41
...
@@ -7,6 +7,7 @@ const { copyText } = require('../util/copy-to-clipboard');
...
@@ -7,6 +7,7 @@ const { copyText } = require('../util/copy-to-clipboard');
const
{
withServices
}
=
require
(
'../util/service-context'
);
const
{
withServices
}
=
require
(
'../util/service-context'
);
const
uiConstants
=
require
(
'../ui-constants'
);
const
uiConstants
=
require
(
'../ui-constants'
);
const
ShareLinks
=
require
(
'./share-links'
);
const
SidebarPanel
=
require
(
'./sidebar-panel'
);
const
SidebarPanel
=
require
(
'./sidebar-panel'
);
const
SvgIcon
=
require
(
'./svg-icon'
);
const
SvgIcon
=
require
(
'./svg-icon'
);
...
@@ -41,14 +42,6 @@ function ShareAnnotationsPanel({ analytics, flash }) {
...
@@ -41,14 +42,6 @@ function ShareAnnotationsPanel({ analytics, flash }) {
}
`
;
}
`
;
})(
mainFrame
,
focusedGroup
);
})(
mainFrame
,
focusedGroup
);
// This is the double-encoded format needed for other services (the entire
// URI needs to be encoded because it's used as the value of querystring params)
const
encodedURI
=
encodeURIComponent
(
shareURI
);
const
trackShareClick
=
shareTarget
=>
{
analytics
.
track
(
analytics
.
events
.
DOCUMENT_SHARED
,
shareTarget
);
};
const
copyShareLink
=
()
=>
{
const
copyShareLink
=
()
=>
{
try
{
try
{
copyText
(
shareURI
);
copyText
(
shareURI
);
...
@@ -114,46 +107,10 @@ function ShareAnnotationsPanel({ analytics, flash }) {
...
@@ -114,46 +107,10 @@ function ShareAnnotationsPanel({ analytics, flash }) {
<
em
>
Only
Me
<
/em>
)
annotations are only visible to you
.
<
em
>
Only
Me
<
/em>
)
annotations are only visible to you
.
<
/span
>
<
/span
>
<
/p
>
<
/p
>
<
ul
className
=
"share-annotations-panel-links"
>
<
ShareLinks
<
li
className
=
"share-annotations-panel-links__link"
>
shareURI
=
{
shareURI
}
<
a
analyticsEventName
=
{
analytics
.
events
.
DOCUMENT_SHARED
}
href
=
{
`https://twitter.com/intent/tweet?url=
${
encodedURI
}
&hashtags=annotated`
}
/
>
title
=
"Tweet share link"
onClick
=
{
trackShareClick
(
'twitter'
)}
>
<
SvgIcon
name
=
"twitter"
className
=
"share-annotations-panel-links__icon"
/>
<
/a
>
<
/li
>
<
li
className
=
"share-annotations-panel__link"
>
<
a
href
=
{
`https://www.facebook.com/sharer/sharer.php?u=
${
encodedURI
}
`
}
title
=
"Share on Facebook"
onClick
=
{
trackShareClick
(
'facebook'
)}
>
<
SvgIcon
name
=
"facebook"
className
=
"share-annotations-panel-links__icon"
/>
<
/a
>
<
/li
>
<
li
className
=
"share-annotations-panel__link"
>
<
a
href
=
{
`mailto:?subject=
${
encodeURIComponent
(
"Let's Annotate"
)}
&body=
${
encodedURI
}
`
}
title
=
"Share via email"
onClick
=
{
trackShareClick
(
'email'
)}
>
<
SvgIcon
name
=
"email"
className
=
"share-annotations-panel-links__icon"
/>
<
/a
>
<
/li
>
<
/ul
>
<
/div
>
<
/div
>
)}
)}
<
/SidebarPanel
>
<
/SidebarPanel
>
...
...
src/sidebar/components/share-links.js
0 → 100644
View file @
94398f41
'use strict'
;
const
propTypes
=
require
(
'prop-types'
);
const
{
createElement
}
=
require
(
'preact'
);
const
{
withServices
}
=
require
(
'../util/service-context'
);
const
SvgIcon
=
require
(
'./svg-icon'
);
/**
* A list of share links to social-media platforms.
*/
function
ShareLinks
({
analytics
,
analyticsEventName
,
shareURI
})
{
const
trackShareClick
=
shareTarget
=>
{
analytics
.
track
(
analyticsEventName
,
shareTarget
);
};
// This is the double-encoded format needed for other services (the entire
// URI needs to be encoded because it's used as the value of querystring params)
const
encodedURI
=
encodeURIComponent
(
shareURI
);
return
(
<
ul
className
=
"share-links"
>
<
li
className
=
"share-links__link"
>
<
a
href
=
{
`https://twitter.com/intent/tweet?url=
${
encodedURI
}
&hashtags=annotated`
}
title
=
"Tweet share link"
onClick
=
{
trackShareClick
(
'twitter'
)}
>
<
SvgIcon
name
=
"twitter"
className
=
"share-links__icon"
/>
<
/a
>
<
/li
>
<
li
className
=
"share-links__link"
>
<
a
href
=
{
`https://www.facebook.com/sharer/sharer.php?u=
${
encodedURI
}
`
}
title
=
"Share on Facebook"
onClick
=
{
trackShareClick
(
'facebook'
)}
>
<
SvgIcon
name
=
"facebook"
className
=
"share-links__icon"
/>
<
/a
>
<
/li
>
<
li
className
=
"share-links__link"
>
<
a
href
=
{
`mailto:?subject=
${
encodeURIComponent
(
"Let's Annotate"
)}
&body=
${
encodedURI
}
`
}
title
=
"Share via email"
onClick
=
{
trackShareClick
(
'email'
)}
>
<
SvgIcon
name
=
"email"
className
=
"share-links__icon"
/>
<
/a
>
<
/li
>
<
/ul
>
);
}
ShareLinks
.
propTypes
=
{
/** Analytics event to track when share links are clicked */
analyticsEventName
:
propTypes
.
string
.
isRequired
,
/** URI to shared resource(s), e.g. an annotation or collection of annotations */
shareURI
:
propTypes
.
string
.
isRequired
,
// Services/injected
analytics
:
propTypes
.
object
.
isRequired
,
};
ShareLinks
.
injectedProps
=
[
'analytics'
];
module
.
exports
=
withServices
(
ShareLinks
);
src/sidebar/components/test/share-annotations-panel-test.js
View file @
94398f41
...
@@ -174,43 +174,4 @@ describe('ShareAnnotationsPanel', () => {
...
@@ -174,43 +174,4 @@ describe('ShareAnnotationsPanel', () => {
});
});
});
});
});
});
describe
(
'other share links'
,
()
=>
{
const
shareLink
=
'https://hyp.is/go?url=https%3A%2F%2Fwww.example.com&group=testprivate'
;
const
encodedLink
=
encodeURIComponent
(
shareLink
);
const
encodedSubject
=
encodeURIComponent
(
"Let's Annotate"
);
[
{
service
:
'facebook'
,
expectedURI
:
`https://www.facebook.com/sharer/sharer.php?u=
${
encodedLink
}
`
,
title
:
'Share on Facebook'
,
},
{
service
:
'twitter'
,
expectedURI
:
`https://twitter.com/intent/tweet?url=
${
encodedLink
}
&hashtags=annotated`
,
title
:
'Tweet share link'
,
},
{
service
:
'email'
,
expectedURI
:
`mailto:?subject=
${
encodedSubject
}
&body=
${
encodedLink
}
`
,
title
:
'Share via email'
,
},
].
forEach
(
testCase
=>
{
it
(
`creates a share link for
${
testCase
.
service
}
and tracks clicks`
,
()
=>
{
const
wrapper
=
createShareAnnotationsPanel
();
const
link
=
wrapper
.
find
(
`a[title="
${
testCase
.
title
}
"]`
);
link
.
simulate
(
'click'
);
assert
.
equal
(
link
.
prop
(
'href'
),
testCase
.
expectedURI
);
assert
.
calledWith
(
fakeAnalytics
.
track
,
fakeAnalytics
.
events
.
DOCUMENT_SHARED
,
testCase
.
service
);
});
});
});
});
});
src/sidebar/components/test/share-links-test.js
0 → 100644
View file @
94398f41
'use strict'
;
const
{
createElement
}
=
require
(
'preact'
);
const
{
mount
}
=
require
(
'enzyme'
);
const
ShareLinks
=
require
(
'../share-links'
);
const
mockImportedComponents
=
require
(
'./mock-imported-components'
);
describe
(
'ShareLinks'
,
()
=>
{
let
fakeAnalytics
;
const
shareLink
=
'https://hyp.is/go?url=https%3A%2F%2Fwww.example.com&group=testprivate'
;
const
createComponent
=
props
=>
mount
(
<
ShareLinks
analyticsEventName
=
"potato-peeling"
analytics
=
{
fakeAnalytics
}
shareURI
=
{
shareLink
}
{...
props
}
/
>
);
beforeEach
(()
=>
{
fakeAnalytics
=
{
track
:
sinon
.
stub
(),
};
ShareLinks
.
$imports
.
$mock
(
mockImportedComponents
());
});
afterEach
(()
=>
{
ShareLinks
.
$imports
.
$restore
();
});
const
encodedLink
=
encodeURIComponent
(
shareLink
);
const
encodedSubject
=
encodeURIComponent
(
"Let's Annotate"
);
[
{
service
:
'facebook'
,
expectedURI
:
`https://www.facebook.com/sharer/sharer.php?u=
${
encodedLink
}
`
,
title
:
'Share on Facebook'
,
},
{
service
:
'twitter'
,
expectedURI
:
`https://twitter.com/intent/tweet?url=
${
encodedLink
}
&hashtags=annotated`
,
title
:
'Tweet share link'
,
},
{
service
:
'email'
,
expectedURI
:
`mailto:?subject=
${
encodedSubject
}
&body=
${
encodedLink
}
`
,
title
:
'Share via email'
,
},
].
forEach
(
testCase
=>
{
it
(
`creates a share link for
${
testCase
.
service
}
and tracks clicks`
,
()
=>
{
const
wrapper
=
createComponent
({
shareURI
:
shareLink
});
const
link
=
wrapper
.
find
(
`a[title="
${
testCase
.
title
}
"]`
);
link
.
simulate
(
'click'
);
assert
.
equal
(
link
.
prop
(
'href'
),
testCase
.
expectedURI
);
assert
.
calledWith
(
fakeAnalytics
.
track
,
'potato-peeling'
,
testCase
.
service
);
});
});
});
src/styles/sidebar/components/share-links.scss
0 → 100644
View file @
94398f41
@use
'../../mixins/links'
;
.share-links
{
@include
links
.
footer-links
;
&
__icon
{
width
:
24px
;
height
:
24px
;
}
}
src/styles/sidebar/sidebar.scss
View file @
94398f41
...
@@ -45,6 +45,7 @@ $base-line-height: 20px;
...
@@ -45,6 +45,7 @@ $base-line-height: 20px;
@import
'./components/selection-tabs'
;
@import
'./components/selection-tabs'
;
@import
'./components/share-annotations-panel'
;
@import
'./components/share-annotations-panel'
;
@import
'./components/search-input'
;
@import
'./components/search-input'
;
@import
'./components/share-links'
;
@import
'./components/sidebar-panel'
;
@import
'./components/sidebar-panel'
;
@import
'./components/svg-icon'
;
@import
'./components/svg-icon'
;
@import
'./components/spinner'
;
@import
'./components/spinner'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment