From 9d8b21edc06e858226411bf06921e9ee7e9986d7 Mon Sep 17 00:00:00 2001 From: Tim Down <158919+timdown@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:55:05 +0000 Subject: [PATCH] Merge pull request #15766 from overleaf/td-ide-page-hide-content-during-resize React IDE page: hide editor and PDF during resize GitOrigin-RevId: bad1a7601d1706e684c91c88c3239a6618479681 --- .../ide-react/components/editor-and-pdf.tsx | 15 ++++++++--- .../components/layout/main-layout.tsx | 10 ++++++-- .../layout/two-column-main-content.tsx | 11 ++++++-- .../resize/horizontal-resize-handle.tsx | 25 +++++++++++++++++-- .../stylesheets/app/editor/ide-react.less | 14 +++++++++++ 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/services/web/frontend/js/features/ide-react/components/editor-and-pdf.tsx b/services/web/frontend/js/features/ide-react/components/editor-and-pdf.tsx index 32d9a7aeb9..34f0492861 100644 --- a/services/web/frontend/js/features/ide-react/components/editor-and-pdf.tsx +++ b/services/web/frontend/js/features/ide-react/components/editor-and-pdf.tsx @@ -1,4 +1,4 @@ -import { ReactNode, useRef } from 'react' +import { ReactNode, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { ImperativePanelHandle, @@ -25,6 +25,7 @@ export default function EditorAndPdf({ const { t } = useTranslation() const { view, pdfLayout, changeLayout, detachRole, reattach } = useLayoutContext() + const [resizing, setResizing] = useState(false) const pdfPanelRef = useRef(null) const isDualPane = pdfLayout === 'sideBySide' @@ -52,7 +53,10 @@ export default function EditorAndPdf({ shouldPersistLayout ? 'ide-react-editor-and-pdf-layout' : undefined } direction="horizontal" - className={classnames({ hide: historyIsOpen })} + className={classnames('ide-react-editor-and-pdf', { + hide: historyIsOpen, + 'ide-react-editor-and-pdf-resizing': resizing, + })} > {editorIsVisible ? ( - {editorContent} +
+ {editorContent} +
) : null} setPdfIsOpen(!pdfIsOpen)} + onDragging={setResizing} > ) : null} - {pdfIsOpen ? ( + {pdfIsOpen || resizing ? ( {headerContent} @@ -40,13 +43,16 @@ export default function MainLayout({ autoSaveId={shouldPersistLayout ? 'ide-react-chat-layout' : undefined} direction="horizontal" onLayout={handleLayout} + className={classNames({ + 'ide-react-main-resizing': resizing, + })} > {mainContent} {chatIsOpen ? ( <> - + { @@ -54,6 +57,9 @@ export default function TwoColumnMainContent({ } direction="horizontal" onLayout={handleLayout} + className={classNames({ + 'ide-react-main-content-resizing': resizing, + })} > setLeftColumnIsOpen(!collapsed)} > - {leftColumnIsOpen ? leftColumnContent : null} + {leftColumnContent} setLeftColumnIsOpen(!leftColumnIsOpen)} resizable={leftColumnIsOpen} + onDragging={setResizing} > = ({ children, resizable = true, onDoubleClick, ...props }) => { const { t } = useTranslation() + const [isDragging, setIsDragging] = useState(false) + + // Only call onDragging prop when the pointer moves after starting a drag + useEffect(() => { + if (isDragging) { + const handlePointerMove = () => { + props.onDragging?.(true) + } + + document.addEventListener('pointermove', handlePointerMove) + return () => { + document.removeEventListener('pointermove', handlePointerMove) + } + } else { + props.onDragging?.(false) + } + }, [isDragging, props]) return ( - +