From 36898eea935ee8996af20e3cfceb030305b6b8fe Mon Sep 17 00:00:00 2001 From: Rahul Tripathi Date: Thu, 22 Jun 2023 17:16:29 +0530 Subject: [PATCH 1/4] Issue 2267 - add a copy button to highlights --- .../web/components/patterns/HighlightBar.tsx | 30 +++++++++++++++-- .../templates/article/HighlightsLayer.tsx | 32 +++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/packages/web/components/patterns/HighlightBar.tsx b/packages/web/components/patterns/HighlightBar.tsx index ee1b16414..b1ba39049 100644 --- a/packages/web/components/patterns/HighlightBar.tsx +++ b/packages/web/components/patterns/HighlightBar.tsx @@ -6,7 +6,7 @@ import { StyledText } from '../elements/StyledText' import { Button } from '../elements/Button' import { HStack, Box } from '../elements/LayoutPrimitives' import { PenWithColorIcon } from '../elements/images/PenWithColorIcon' -import { Note, Tag, Trash } from 'phosphor-react' +import { Note, Tag, Trash, Copy } from 'phosphor-react' type PageCoordinates = { pageX: number @@ -21,6 +21,7 @@ export type HighlightAction = | 'post' | 'unshare' | 'setHighlightLabels' + | 'copy' type HighlightBarProps = { anchorCoordinates: PageCoordinates @@ -36,7 +37,7 @@ export function HighlightBar(props: HighlightBarProps): JSX.Element { + + {/* + ) } function BarContent(props: HighlightBarProps): JSX.Element { @@ -97,139 +122,51 @@ function BarContent(props: HighlightBarProps): JSX.Element { }} > {props.isNewHighlight ? ( - + /> ) : ( <> - + } + onClick={() => props.handleButtonClick('delete')} + /> - - + } + onClick={() => props.handleButtonClick('setHighlightLabels')} + /> )} - + } + onClick={() => props.handleButtonClick('comment')} + /> - - {/* - */} + } + onClick={() => props.handleButtonClick('copy')} + /> ) } From cc27a8e3735a63e78807ad933cd9faaabfa2e49a Mon Sep 17 00:00:00 2001 From: Rahul Tripathi Date: Thu, 22 Jun 2023 19:24:27 +0530 Subject: [PATCH 3/4] 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) From 09abc46102ae8429d3ce76a85a11265663969ac2 Mon Sep 17 00:00:00 2001 From: Rahul Tripathi Date: Fri, 23 Jun 2023 03:23:01 +0530 Subject: [PATCH 4/4] Correct highlight bar css object conditional. --- .../web/components/patterns/HighlightBar.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/web/components/patterns/HighlightBar.tsx b/packages/web/components/patterns/HighlightBar.tsx index ad1aff3f3..98a92a39a 100644 --- a/packages/web/components/patterns/HighlightBar.tsx +++ b/packages/web/components/patterns/HighlightBar.tsx @@ -43,19 +43,19 @@ export function HighlightBar(props: HighlightBarProps): JSX.Element { borderRadius: '4px', border: '1px solid $grayBorder', boxShadow: theme.shadows.cardBoxShadow.toString(), - bottom: props.displayAtBottom - ? 'calc(38px + env(safe-area-inset-bottom, 40px))' - : undefined, - '@smDown': props.displayAtBottom - ? { - maxWidth: '85%', - bottom: `calc(28px + ${ - isAndroid() ? 30 : 0 - }px + env(safe-area-inset-bottom, 40px))`, - } - : undefined, - left: props.displayAtBottom ? undefined : props.anchorCoordinates.pageX, - top: props.displayAtBottom ? undefined : props.anchorCoordinates.pageY, + ...(props.displayAtBottom && { + bottom: 'calc(38px + env(safe-area-inset-bottom, 40px))', + }), + ...(props.displayAtBottom && { + '@smDown': { + maxWidth: '85%', + bottom: `calc(28px + ${ + isAndroid() ? 30 : 0 + }px + env(safe-area-inset-bottom, 40px))`, + }, + }), + ...(!props.displayAtBottom && { left: props.anchorCoordinates.pageX }), + ...(!props.displayAtBottom && { top: props.anchorCoordinates.pageY }), }} >