From cc27a8e3735a63e78807ad933cd9faaabfa2e49a Mon Sep 17 00:00:00 2001 From: Rahul Tripathi Date: Thu, 22 Jun 2023 19:24:27 +0530 Subject: [PATCH] Add success and error toasts on copy --- .../templates/article/HighlightsLayer.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/web/components/templates/article/HighlightsLayer.tsx b/packages/web/components/templates/article/HighlightsLayer.tsx index adc40c786..12f4a7fc1 100644 --- a/packages/web/components/templates/article/HighlightsLayer.tsx +++ b/packages/web/components/templates/article/HighlightsLayer.tsx @@ -20,7 +20,7 @@ import { removeHighlights } from '../../../lib/highlights/deleteHighlight' import { createHighlight } from '../../../lib/highlights/createHighlight' import { HighlightNoteModal } from './HighlightNoteModal' import { NotebookModal } from './NotebookModal' -import { showErrorToast } from '../../../lib/toastHelpers' +import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers' import { ArticleMutations } from '../../../lib/articleActions' import { isTouchScreenDevice } from '../../../lib/deviceType' import { UserBasicData } from '../../../lib/networking/queries/useGetViewerQuery' @@ -473,7 +473,18 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { textToCopy = userSelectionText } - if (textToCopy) await navigator.clipboard.writeText(textToCopy) + if (textToCopy) { + try { + await navigator.clipboard.writeText(textToCopy) + showSuccessToast('Highlight copied', { + position: 'bottom-right', + }) + } catch (error) { + showErrorToast('Error copying highlight, permission denied.', { + position: 'bottom-right', + }) + } + } selection.empty() setSelectionData(null)