From 8cd7e823c57e5933952bda027ec91978efa1eb79 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 9 Mar 2023 18:22:51 +0800 Subject: [PATCH] Make notebook modal closer to highlights view, add exports --- .../components/elements/MenuTriggerButton.tsx | 57 ---------------- .../templates/article/HighlightsLayer.tsx | 10 +-- .../templates/article/NotebookModal.tsx | 65 +++++++++++++++++-- .../templates/homeFeed/HighlightItem.tsx | 2 +- .../templates/homeFeed/HighlightsLayout.tsx | 23 +------ 5 files changed, 70 insertions(+), 87 deletions(-) delete mode 100644 packages/web/components/elements/MenuTriggerButton.tsx diff --git a/packages/web/components/elements/MenuTriggerButton.tsx b/packages/web/components/elements/MenuTriggerButton.tsx deleted file mode 100644 index 29a1700c9..000000000 --- a/packages/web/components/elements/MenuTriggerButton.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { DotsThreeVertical, X } from 'phosphor-react' -import { useState } from 'react' -import { Button } from './Button' -import { Box, SpanBox } from './LayoutPrimitives' - -export function MenuTrigger(): JSX.Element { - const [hover, setHover] = useState(false) - - return ( - setHover(true)} - onMouseOut={() => setHover(false)} - > - - {/* color="#ADADAD" /> - */} - - ) -} diff --git a/packages/web/components/templates/article/HighlightsLayer.tsx b/packages/web/components/templates/article/HighlightsLayer.tsx index 6ee2145eb..675393b70 100644 --- a/packages/web/components/templates/article/HighlightsLayer.tsx +++ b/packages/web/components/templates/article/HighlightsLayer.tsx @@ -68,13 +68,15 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element { >([]) const focusedHighlightMousePos = useRef({ pageX: 0, pageY: 0 }) - const [focusedHighlight, setFocusedHighlight] = - useState(undefined) + const [focusedHighlight, setFocusedHighlight] = useState< + Highlight | undefined + >(undefined) const [selectionData, setSelectionData] = useSelection(highlightLocations) - const [labelsTarget, setLabelsTarget] = - useState(undefined) + const [labelsTarget, setLabelsTarget] = useState( + undefined + ) const canShareNative = useCanShareNative() diff --git a/packages/web/components/templates/article/NotebookModal.tsx b/packages/web/components/templates/article/NotebookModal.tsx index 6dadb8030..1aca83f46 100644 --- a/packages/web/components/templates/article/NotebookModal.tsx +++ b/packages/web/components/templates/article/NotebookModal.tsx @@ -23,6 +23,9 @@ import { updateHighlightMutation } from '../../../lib/networking/mutations/updat import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers' import { diff_match_patch } from 'diff-match-patch' import { HighlightNoteTextEditArea } from '../../elements/HighlightNoteTextEditArea' +import { CloseButton } from '../../elements/CloseButton' +import { MenuTrigger } from '../../elements/MenuTrigger' +import { highlightsAsMarkdown, HighlightsMenu } from '../homeFeed/HighlightItem' type NotebookModalProps = { highlights: Highlight[] @@ -46,6 +49,18 @@ export function NotebookModal(props: NotebookModalProps): JSX.Element { ) const [, updateState] = useState({}) + const exportHighlights = useCallback(() => { + ;(async () => { + if (!props.highlights) { + showErrorToast('No highlights to export') + return + } + const markdown = highlightsAsMarkdown(props.highlights) + await navigator.clipboard.writeText(markdown) + showSuccessToast('Highlight copied') + })() + }, [props.highlights]) + const sortedHighlights = useMemo(() => { const sorted = (a: number, b: number) => { if (a < b) { @@ -85,7 +100,24 @@ export function NotebookModal(props: NotebookModalProps): JSX.Element { css={{ overflow: 'auto', px: '24px' }} > - + + Notebook + + }> + { + exportHighlights() + }} + title="Export" + /> + + props.onOpenChange(false)} /> + + {sortedHighlights.map((highlight) => ( { @@ -174,9 +207,13 @@ function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { }, [props.highlight]) return ( - <> + setHover(true)} + onMouseLeave={() => setHover(false)} + > - + {/* @@ -201,7 +238,7 @@ function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { title="Delete" /> - + */} - + + + + ) } diff --git a/packages/web/components/templates/homeFeed/HighlightItem.tsx b/packages/web/components/templates/homeFeed/HighlightItem.tsx index dd2e3841d..912d1964f 100644 --- a/packages/web/components/templates/homeFeed/HighlightItem.tsx +++ b/packages/web/components/templates/homeFeed/HighlightItem.tsx @@ -199,7 +199,7 @@ type HighlightsMenuProps = { setShowConfirmDeleteHighlightId: (set: string) => void } -function HighlightsMenu(props: HighlightsMenuProps): JSX.Element { +export function HighlightsMenu(props: HighlightsMenuProps): JSX.Element { const copyHighlight = useCallback(() => { ;(async () => { await navigator.clipboard.writeText(props.highlight.quote) diff --git a/packages/web/components/templates/homeFeed/HighlightsLayout.tsx b/packages/web/components/templates/homeFeed/HighlightsLayout.tsx index 0d0c72d76..129d0f8f7 100644 --- a/packages/web/components/templates/homeFeed/HighlightsLayout.tsx +++ b/packages/web/components/templates/homeFeed/HighlightsLayout.tsx @@ -1,4 +1,4 @@ -import { DotsThreeVertical, HighlighterCircle } from 'phosphor-react' +import { HighlighterCircle } from 'phosphor-react' import { useCallback, useEffect, useState } from 'react' import { Toaster } from 'react-hot-toast' import { LibraryItem } from '../../../lib/networking/queries/useGetLibraryItemsQuery' @@ -7,6 +7,7 @@ import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers' import { Dropdown, DropdownOption } from '../../elements/DropdownElements' import { Box, HStack, SpanBox, VStack } from '../../elements/LayoutPrimitives' +import { MenuTrigger } from '../../elements/MenuTrigger' import { StyledText } from '../../elements/StyledText' import { MetaStyle, @@ -292,25 +293,7 @@ function HighlightList(props: HighlightListProps): JSX.Element { > HIGHLIGHTS - - - - } - > + }> { exportHighlights()