-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not provide share link if (annotation or document) URL is not available on the web #2871
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import propTypes from 'prop-types'; | |
|
||
import { useStoreProxy } from '../store/use-store'; | ||
import uiConstants from '../ui-constants'; | ||
import { getSharingLink, isShareableURI } from '../util/annotation-sharing'; | ||
import { copyText } from '../util/copy-to-clipboard'; | ||
import { withServices } from '../util/service-context'; | ||
|
||
|
@@ -18,7 +19,7 @@ import SvgIcon from '../../shared/components/svg-icon'; | |
*/ | ||
|
||
/** | ||
* A panel for sharing the current group's annotations. | ||
* A panel for sharing the current group's annotations on the current document. | ||
* | ||
* Links within this component allow a user to share the set of annotations that | ||
* are on the current page (as defined by the main frame's URI) and contained | ||
|
@@ -30,24 +31,24 @@ function ShareAnnotationsPanel({ analytics, toastMessenger }) { | |
const store = useStoreProxy(); | ||
const mainFrame = store.mainFrame(); | ||
const focusedGroup = store.focusedGroup(); | ||
|
||
const groupName = (focusedGroup && focusedGroup.name) || '...'; | ||
const panelTitle = `Share Annotations in ${groupName}`; | ||
|
||
// Generate bouncer sharing link for annotations in the current group. | ||
// Not all URIs are valid to share: the document needs to be available | ||
// on the web. | ||
const uriShareable = mainFrame?.uri && isShareableURI(mainFrame?.uri); | ||
lyzadanger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Generate bouncer sharing link. | ||
// This is the URI format for the web-sharing link shown in the input | ||
// and is available to be copied to clipboard | ||
const shareURI = ((frame, group) => { | ||
return group && frame | ||
? `https://hyp.is/go?url=${encodeURIComponent(frame.uri)}&group=${ | ||
group.id | ||
}` | ||
: ''; | ||
})(mainFrame, focusedGroup); | ||
// and is available to be copied to clipboard. We need the frame's URI | ||
// (document URL) and the focused group to be available before this link | ||
// can be generated. | ||
const shareURI = | ||
focusedGroup && mainFrame && getSharingLink(mainFrame.uri, focusedGroup.id); | ||
|
||
const copyShareLink = () => { | ||
try { | ||
copyText(shareURI); | ||
copyText(shareURI ?? ''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appeasing the TS gods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though it is a bit verbose I would prefer to use a cast here ( As an aside, this is one area where TypeScript's native syntax is much more succinct (just add an exclamation mark after the expression - |
||
toastMessenger.success('Copied share link to clipboard'); | ||
} catch (err) { | ||
toastMessenger.error('Unable to copy link'); | ||
|
@@ -59,10 +60,10 @@ function ShareAnnotationsPanel({ analytics, toastMessenger }) { | |
title={panelTitle} | ||
panelName={uiConstants.PANEL_SHARE_ANNOTATIONS} | ||
> | ||
{focusedGroup && mainFrame && ( | ||
{shareURI && uriShareable && ( | ||
<div className="share-annotations-panel"> | ||
<div className="share-annotations-panel__intro"> | ||
{focusedGroup.type === 'private' ? ( | ||
{focusedGroup?.type === 'private' ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TS again... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to resolve this by changing the conditional to I found an existing issue in TypeScript about this: microsoft/TypeScript#24865. |
||
<p> | ||
Use this link to share these annotations with other group | ||
members: | ||
|
@@ -87,15 +88,15 @@ function ShareAnnotationsPanel({ analytics, toastMessenger }) { | |
/> | ||
</div> | ||
<p> | ||
{focusedGroup.type === 'private' ? ( | ||
{focusedGroup?.type === 'private' ? ( | ||
<span> | ||
Annotations in the private group <em>{focusedGroup.name}</em>{' '} | ||
are only visible to group members. | ||
</span> | ||
) : ( | ||
<span> | ||
Anyone using this link may view the annotations in the group{' '} | ||
<em>{focusedGroup.name}</em>. | ||
<em>{focusedGroup?.name}</em>. | ||
</span> | ||
)}{' '} | ||
<span> | ||
|
@@ -110,6 +111,14 @@ function ShareAnnotationsPanel({ analytics, toastMessenger }) { | |
/> | ||
</div> | ||
)} | ||
{shareURI && !uriShareable && ( | ||
<div className="share-annotations-panel"> | ||
<p> | ||
These annotations cannot be shared because this document is not | ||
available on the web. | ||
</p> | ||
</div> | ||
)} | ||
</SidebarPanel> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall refactor of
annotation-sharing
logic made it more coherent to have this logic in two discrete functions instead of one. There is some complexity because "is sharing allowed" is not a single question, but, kind of, four:AnnotationActionBar
at present.links
?