Only call "reattach" when explicitly opening the PDF view (#16330)

GitOrigin-RevId: 53d7ef25a58255bdac46011c3d7b7e4d63e65a6c
This commit is contained in:
Alf Eaton 2024-01-03 11:12:23 +00:00 committed by Copybot
parent 8f592122c9
commit ecfa15cf57

View file

@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef } from 'react'
import { useCallback, useRef } from 'react'
import { ImperativePanelHandle } from 'react-resizable-panels'
import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel'
import { useLayoutContext } from '@/shared/context/layout-context'
@ -12,13 +12,6 @@ export const usePdfPane = () => {
useCollapsiblePanel(pdfIsOpen, pdfPanelRef)
// close a detached PDF when the detacher PDF view opens
useEffect(() => {
if (pdfIsOpen && detachRole === 'detacher') {
reattach()
}
}, [detachRole, pdfIsOpen, reattach])
// triggered by a double-click on the resizer
const togglePdfPane = useCallback(() => {
if (pdfIsOpen) {
@ -32,12 +25,16 @@ export const usePdfPane = () => {
const setPdfIsOpen = useCallback(
(value: boolean) => {
if (value) {
// opening the PDF view, so close a detached PDF
if (detachRole === 'detacher') {
reattach()
}
changeLayout('sideBySide')
} else {
changeLayout('flat', 'editor')
}
},
[changeLayout]
[changeLayout, detachRole, reattach]
)
// triggered when the PDF pane becomes open