Commit 54e7beed authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Convert `ShareAnnotationsPanel` to TS

parent 8d393848
...@@ -10,15 +10,16 @@ import { useSidebarStore } from '../store'; ...@@ -10,15 +10,16 @@ import { useSidebarStore } from '../store';
import { pageSharingLink } from '../helpers/annotation-sharing'; import { pageSharingLink } from '../helpers/annotation-sharing';
import { copyText } from '../util/copy-to-clipboard'; import { copyText } from '../util/copy-to-clipboard';
import { withServices } from '../service-context'; import { withServices } from '../service-context';
import type { ToastMessengerService } from '../services/toast-messenger';
import { notNull } from '../util/typing'; import { notNull } from '../util/typing';
import ShareLinks from './ShareLinks'; import ShareLinks from './ShareLinks';
import SidebarPanel from './SidebarPanel'; import SidebarPanel from './SidebarPanel';
/** export type ShareAnnotationPanelProps = {
* @typedef ShareAnnotationsPanelProps // injected
* @prop {import('../services/toast-messenger').ToastMessengerService} toastMessenger toastMessenger: ToastMessengerService;
*/ };
/** /**
* A panel for sharing the current group's annotations on the current document. * A panel for sharing the current group's annotations on the current document.
...@@ -26,10 +27,8 @@ import SidebarPanel from './SidebarPanel'; ...@@ -26,10 +27,8 @@ import SidebarPanel from './SidebarPanel';
* Links within this component allow a user to share the set of annotations that * 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 * are on the current page (as defined by the main frame's URI) and contained
* within the app's currently-focused group. * within the app's currently-focused group.
*
* @param {ShareAnnotationsPanelProps} props
*/ */
function ShareAnnotationsPanel({ toastMessenger }) { function ShareAnnotationsPanel({ toastMessenger }: ShareAnnotationPanelProps) {
const store = useSidebarStore(); const store = useSidebarStore();
const mainFrame = store.mainFrame(); const mainFrame = store.mainFrame();
const focusedGroup = store.focusedGroup(); const focusedGroup = store.focusedGroup();
...@@ -41,13 +40,14 @@ function ShareAnnotationsPanel({ toastMessenger }) { ...@@ -41,13 +40,14 @@ function ShareAnnotationsPanel({ toastMessenger }) {
const sharingReady = focusedGroup && mainFrame; const sharingReady = focusedGroup && mainFrame;
const shareURI = const shareURI =
sharingReady && sharingReady && pageSharingLink(mainFrame.uri, focusedGroup.id);
pageSharingLink(notNull(mainFrame).uri, notNull(focusedGroup).id);
const copyShareLink = () => { const copyShareLink = () => {
try { try {
copyText(/** @type {string} */ (shareURI)); if (shareURI) {
toastMessenger.success('Copied share link to clipboard'); copyText(shareURI);
toastMessenger.success('Copied share link to clipboard');
}
} catch (err) { } catch (err) {
toastMessenger.error('Unable to copy link'); toastMessenger.error('Unable to copy link');
} }
......
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