From 0715dafd4b17ac7236f91f8596d86e8ff874d4e4 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 14 Apr 2022 15:06:27 -0700 Subject: [PATCH 1/4] Display the all highlights modal from PDFs via the article actions button --- .../templates/article/ArticleContainer.tsx | 1 - .../templates/article/HighlightsModal.tsx | 20 ++++++++++++------- .../templates/article/PdfArticleContainer.tsx | 9 +++++++++ .../web/pages/[username]/[slug]/index.tsx | 2 ++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/web/components/templates/article/ArticleContainer.tsx b/packages/web/components/templates/article/ArticleContainer.tsx index 46a846637..62e4a7b8d 100644 --- a/packages/web/components/templates/article/ArticleContainer.tsx +++ b/packages/web/components/templates/article/ArticleContainer.tsx @@ -35,7 +35,6 @@ type ArticleContainerProps = { export function ArticleContainer(props: ArticleContainerProps): JSX.Element { const [showShareModal, setShowShareModal] = useState(false) const [showReportIssuesModal, setShowReportIssuesModal] = useState(false) - const [showHighlightsModal, setShowHighlightsModal] = useState(props.showHighlightsModal) const [fontSize, setFontSize] = useState(props.fontSize ?? 20) const updateFontSize = async (newFontSize: number) => { diff --git a/packages/web/components/templates/article/HighlightsModal.tsx b/packages/web/components/templates/article/HighlightsModal.tsx index 92358b057..d31557c4b 100644 --- a/packages/web/components/templates/article/HighlightsModal.tsx +++ b/packages/web/components/templates/article/HighlightsModal.tsx @@ -19,7 +19,7 @@ import { Pen, Trash } from 'phosphor-react' type HighlightsModalProps = { highlights: Highlight[] - deleteHighlightAction: (highlightId: string) => void + deleteHighlightAction?: (highlightId: string) => void onOpenChange: (open: boolean) => void } @@ -59,9 +59,12 @@ export function HighlightsModal(props: HighlightsModalProps): JSX.Element { - props.deleteHighlightAction(highlight.id) - } + showDelete={!!props.deleteHighlightAction} + deleteHighlightAction={() => { + if (props.deleteHighlightAction) { + props.deleteHighlightAction(highlight.id) + } + }} /> ))} {props.highlights.length === 0 && ( @@ -78,6 +81,7 @@ export function HighlightsModal(props: HighlightsModalProps): JSX.Element { type ModalHighlightViewProps = { highlight: Highlight + showDelete: boolean deleteHighlightAction: () => void } @@ -112,9 +116,11 @@ function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { /> )} */} - + {props.showDelete && ( + + )} ) diff --git a/packages/web/components/templates/article/PdfArticleContainer.tsx b/packages/web/components/templates/article/PdfArticleContainer.tsx index 77659e737..06cb94286 100644 --- a/packages/web/components/templates/article/PdfArticleContainer.tsx +++ b/packages/web/components/templates/article/PdfArticleContainer.tsx @@ -15,10 +15,13 @@ import { ShareHighlightModal } from './ShareHighlightModal' import { useCanShareNative } from '../../../lib/hooks/useCanShareNative' import { webBaseURL } from '../../../lib/appConfig' import { pspdfKitKey } from '../../../lib/appConfig' +import { HighlightsModal } from './HighlightsModal' export type PdfArticleContainerProps = { viewerUsername: string article: ArticleAttributes + showHighlightsModal: boolean + setShowHighlightsModal: React.Dispatch> } export default function PdfArticleContainer( @@ -348,6 +351,12 @@ export default function PdfArticleContainer( }} /> )} + {props.showHighlightsModal && ( + props.setShowHighlightsModal(false)} + /> + )} ) } diff --git a/packages/web/pages/[username]/[slug]/index.tsx b/packages/web/pages/[username]/[slug]/index.tsx index 282bbf0d4..18bd8a00c 100644 --- a/packages/web/pages/[username]/[slug]/index.tsx +++ b/packages/web/pages/[username]/[slug]/index.tsx @@ -209,6 +209,8 @@ export default function Home(): JSX.Element { {article.contentReader == 'PDF' ? ( ) : ( From 0842aba57cf565c64a68e9eb0e0e89bc00a12c03 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 14 Apr 2022 15:53:51 -0700 Subject: [PATCH 2/4] Always display the article actions toolbar on top for PDFs Because we dont have margin space on PDFs we want to always display this on top. --- .../web/components/patterns/PrimaryHeader.tsx | 5 +- .../components/templates/PrimaryLayout.tsx | 4 +- .../templates/article/ArticleActionsMenu.tsx | 66 ++++++++++--------- .../web/pages/[username]/[slug]/index.tsx | 7 +- 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/packages/web/components/patterns/PrimaryHeader.tsx b/packages/web/components/patterns/PrimaryHeader.tsx index 79294d02f..12c7e4754 100644 --- a/packages/web/components/patterns/PrimaryHeader.tsx +++ b/packages/web/components/patterns/PrimaryHeader.tsx @@ -26,6 +26,7 @@ type HeaderProps = { isFixedPosition: boolean scrollElementRef?: React.RefObject toolbarControl?: JSX.Element + alwaysDisplayToolbar?: boolean setShowLogoutConfirmation: (showShareModal: boolean) => void setShowKeyboardCommandsModal: (showShareModal: boolean) => void } @@ -128,6 +129,7 @@ export function PrimaryHeader(props: HeaderProps): JSX.Element { isVisible={true} isFixedPosition={true} toolbarControl={props.toolbarControl} + alwaysDisplayToolbar={props.alwaysDisplayToolbar} /> ) @@ -143,6 +145,7 @@ type NavHeaderProps = { isVisible?: boolean isFixedPosition: boolean toolbarControl?: JSX.Element + alwaysDisplayToolbar?: boolean } function NavHeader(props: NavHeaderProps): JSX.Element { @@ -187,7 +190,7 @@ function NavHeader(props: NavHeaderProps): JSX.Element { headerToolbarControl?: JSX.Element + alwaysDisplayToolbar?: boolean } export function PrimaryLayout(props: PrimaryLayoutProps): JSX.Element { @@ -75,8 +76,9 @@ export function PrimaryLayout(props: PrimaryLayoutProps): JSX.Element { userInitials={viewerData?.me?.name.charAt(0) ?? ''} profileImageURL={viewerData?.me?.profile.pictureUrl} isFixedPosition={true} - toolbarControl={props.headerToolbarControl} scrollElementRef={props.scrollElementRef} + toolbarControl={props.headerToolbarControl} + alwaysDisplayToolbar={props.alwaysDisplayToolbar} setShowLogoutConfirmation={setShowLogoutConfirmation} setShowKeyboardCommandsModal={setShowKeyboardCommandsModal} /> diff --git a/packages/web/components/templates/article/ArticleActionsMenu.tsx b/packages/web/components/templates/article/ArticleActionsMenu.tsx index 880cfea9a..9b82691f0 100644 --- a/packages/web/components/templates/article/ArticleActionsMenu.tsx +++ b/packages/web/components/templates/article/ArticleActionsMenu.tsx @@ -1,7 +1,6 @@ import { Separator } from "@radix-ui/react-separator" import { ArchiveBox, DotsThree, HighlighterCircle, TagSimple, TextAa } from "phosphor-react" import { ArticleAttributes } from "../../../lib/networking/queries/useGetArticleQuery" -import { useGetUserPreferences } from "../../../lib/networking/queries/useGetUserPreferences" import { Button } from "../../elements/Button" import { Dropdown } from "../../elements/DropdownElements" import { Box, SpanBox } from "../../elements/LayoutPrimitives" @@ -9,15 +8,15 @@ import { TooltipWrapped } from "../../elements/Tooltip" import { styled, theme } from "../../tokens/stitches.config" import { SetLabelsControl } from "./SetLabelsControl" import { ReaderSettingsControl } from "./ReaderSettingsControl" -import { usePersistedState } from "../../../lib/hooks/usePersistedState" -export type ArticleActionsMenuLayout = 'horizontal' | 'vertical' +export type ArticleActionsMenuLayout = 'top' | 'side' type ArticleActionsMenuProps = { article: ArticleAttributes layout: ArticleActionsMenuLayout lineHeight: number marginWidth: number + showReaderDisplaySettings?: boolean articleActionHandler: (action: string, arg?: unknown) => void } @@ -32,7 +31,7 @@ const MenuSeparator = (props: MenuSeparatorProps): JSX.Element => { borderBottom: `1px solid ${theme.colors.grayLine.toString()}`, my: '8px', }) - return (props.layout == 'vertical' ? : <>) + return (props.layout == 'side' ? : <>) } type ActionDropdownProps = { @@ -45,10 +44,10 @@ const ActionDropdown = (props: ActionDropdownProps): JSX.Element => { return {props.children} @@ -62,32 +61,35 @@ export function ArticleActionsMenu(props: ArticleActionsMenuProps): JSX.Element css={{ display: 'flex', alignItems: 'center', - flexDirection: props.layout == 'vertical' ? 'column' : 'row', - justifyContent: props.layout == 'vertical' ? 'center' : 'flex-end', - gap: props.layout == 'vertical' ? '8px' : '24px', + flexDirection: props.layout == 'side' ? 'column' : 'row', + justifyContent: props.layout == 'side' ? 'center' : 'flex-end', + gap: props.layout == 'side' ? '8px' : '24px', paddingTop: '6px', }} > - - + + + + } > - - - } - > - - + + - + + + )} @@ -127,7 +129,7 @@ export function ArticleActionsMenu(props: ArticleActionsMenuProps): JSX.Element