From 95d866a120e332fc8d897c55780026a14889f148 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 28 Jul 2022 12:18:21 -0700 Subject: [PATCH] Display the highlight delete confirmation outside the modal content This fixes an issue where a long list of highlights wouldn't show the confirmation modal properly if scrolled because the modal would be in the scrolled content. --- .../components/elements/ModalPrimitives.tsx | 5 -- .../templates/article/HighlightsModal.tsx | 51 +++++++++---------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/packages/web/components/elements/ModalPrimitives.tsx b/packages/web/components/elements/ModalPrimitives.tsx index 33006fc8b..ec5ee1416 100644 --- a/packages/web/components/elements/ModalPrimitives.tsx +++ b/packages/web/components/elements/ModalPrimitives.tsx @@ -23,11 +23,6 @@ export const ModalOverlay = styled(Overlay, { }, }) -const contentShow = keyframes({ - '0%': { opacity: 0, transform: 'translate(-50%, -48%) scale(.96)' }, - '100%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' }, -}) - const Modal = styled(Content, { backgroundColor: '$grayBg', borderRadius: 6, diff --git a/packages/web/components/templates/article/HighlightsModal.tsx b/packages/web/components/templates/article/HighlightsModal.tsx index f8f7569fd..f3ba0f560 100644 --- a/packages/web/components/templates/article/HighlightsModal.tsx +++ b/packages/web/components/templates/article/HighlightsModal.tsx @@ -26,6 +26,8 @@ type HighlightsModalProps = { } export function HighlightsModal(props: HighlightsModalProps): JSX.Element { + const [showConfirmDeleteHighlightId, setShowConfirmDeleteHighlightId] = useState(undefined) + return ( @@ -45,6 +47,7 @@ export function HighlightsModal(props: HighlightsModalProps): JSX.Element { highlight={highlight} showDelete={!!props.deleteHighlightAction} scrollToHighlight={props.scrollToHighlight} + setShowConfirmDeleteHighlightId={setShowConfirmDeleteHighlightId} deleteHighlightAction={() => { if (props.deleteHighlightAction) { props.deleteHighlightAction(highlight.id) @@ -60,6 +63,24 @@ export function HighlightsModal(props: HighlightsModalProps): JSX.Element { + {showConfirmDeleteHighlightId ? ( + { + if (props.deleteHighlightAction) { + props.deleteHighlightAction(showConfirmDeleteHighlightId) + } + setShowConfirmDeleteHighlightId(undefined) + }} + onOpenChange={() => setShowConfirmDeleteHighlightId(undefined)} + icon={ + + } + /> + ) : null} ) } @@ -69,11 +90,11 @@ type ModalHighlightViewProps = { showDelete: boolean scrollToHighlight?: (arg: string) => void; deleteHighlightAction: () => void + setShowConfirmDeleteHighlightId: (id: string | undefined) => void } function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { const [isEditing, setIsEditing] = useState(false) - const [showDeleteConfirmation, setShowDeleteConfirmation] = useState(false) const [noteContent, setNoteContent] = useState( props.highlight.annotation ?? '' @@ -92,18 +113,8 @@ function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { distribution="end" css={{ width: '100%', pt: '$2' }} > - {/* */} {props.showDelete && ( - )} @@ -148,22 +159,6 @@ function ModalHighlightView(props: ModalHighlightViewProps): JSX.Element { ) : null} {isEditing ? : } - {showDeleteConfirmation ? ( - { - setShowDeleteConfirmation(false) - props.deleteHighlightAction() - }} - onOpenChange={() => setShowDeleteConfirmation(false)} - icon={ - - } - /> - ) : null} )