diff --git a/packages/web/components/elements/icons/CopyIcon.tsx b/packages/web/components/elements/icons/CopyIcon.tsx new file mode 100644 index 000000000..18a384421 --- /dev/null +++ b/packages/web/components/elements/icons/CopyIcon.tsx @@ -0,0 +1,39 @@ +/* eslint-disable functional/no-class */ +/* eslint-disable functional/no-this-expression */ +import { IconProps } from './IconProps' + +import React from 'react' + +export class CopyIcon extends React.Component { + render() { + const size = (this.props.size || 26).toString() + const color = (this.props.color || '#2A2A2A').toString() + + return ( + + + + + + + ) + } +} diff --git a/packages/web/components/patterns/HighlightBar.tsx b/packages/web/components/patterns/HighlightBar.tsx index a352c90f0..dc2e8aa9e 100644 --- a/packages/web/components/patterns/HighlightBar.tsx +++ b/packages/web/components/patterns/HighlightBar.tsx @@ -20,6 +20,7 @@ import { LabelIcon } from '../elements/icons/LabelIcon' import { NotebookIcon } from '../elements/icons/NotebookIcon' import { highlightColor, highlightColors } from '../../lib/themeUpdater' import { useState } from 'react' +import { CopyIcon } from '../elements/icons/CopyIcon' type PageCoordinates = { pageX: number @@ -87,6 +88,7 @@ const Separator = styled('div', { function BarContent(props: HighlightBarProps): JSX.Element { const [hovered, setHovered] = useState(undefined) + const size = props.displayAtBottom ? 35 : 25 return ( @@ -127,16 +129,16 @@ function BarContent(props: HighlightBarProps): JSX.Element { {props.isNewHighlight || props.highlightColor != color ? ( ) : ( @@ -159,7 +161,7 @@ function BarContent(props: HighlightBarProps): JSX.Element { }} > - { + const initial = highlight.color + highlight.color = color + updateHighlightsCallback(highlight) + ;(async () => { + const update = await props.articleMutations.updateHighlightMutation({ + highlightId: highlight.id, + color: color, + }) + if (!update) { + highlight.color = initial + updateHighlightsCallback(highlight) + showErrorToast('Error updating highlight color') + } + document.dispatchEvent(new Event('highlightsUpdated')) + })() + }, + [props, highlights, highlightLocations, updateHighlightsCallback] + ) + const openNoteModal = useCallback( (inputs: HighlightActionProps) => { // First try to send a signal to the ios app @@ -242,6 +263,7 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { } setHighlightModalAction(inputs) } + document.dispatchEvent(new Event('highlightsUpdated')) }, [props.highlightBarDisabled, createHighlightFromSelection] ) @@ -462,9 +484,10 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { }) break case 'updateColor': - if (focusedHighlight) { - focusedHighlight.color = param - await updateHighlightsCallback(focusedHighlight) + if (focusedHighlight && param) { + updateHighlightColor(focusedHighlight, param) + } else { + showErrorToast('Error updating color') } break case 'comment': @@ -540,6 +563,7 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { removeHighlightCallback, selectionData, setSelectionData, + updateHighlightColor, confirmDeleteHighlightWithNoteId, ] ) @@ -709,6 +733,7 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { dispatchHighlightError('saveAnnotation', error) } } + document.dispatchEvent(new Event('highlightsUpdated')) } document.addEventListener('annotate', annotate) diff --git a/packages/web/lib/networking/mutations/updateHighlightMutation.ts b/packages/web/lib/networking/mutations/updateHighlightMutation.ts index 3ac1850a3..680e22998 100644 --- a/packages/web/lib/networking/mutations/updateHighlightMutation.ts +++ b/packages/web/lib/networking/mutations/updateHighlightMutation.ts @@ -5,6 +5,7 @@ export type UpdateHighlightInput = { highlightId: string annotation?: string sharedAt?: string + color?: string } type UpdateHighlightOutput = {