Merge pull request #5982 from overleaf/jel-pdf-detach-childless

Editor tab in detach layout when no PDF tab

GitOrigin-RevId: 979c179dbe4b447e1eb222b2649d6a235f6ab229
This commit is contained in:
Jessica Lawshe 2021-12-02 09:18:38 -06:00 committed by Copybot
parent 994b34bb2d
commit 956724c838

View file

@ -4,10 +4,8 @@ import {
useCallback,
useMemo,
useEffect,
useRef,
} from 'react'
import PropTypes from 'prop-types'
import { debounce } from 'lodash'
import useScopeValue from '../hooks/use-scope-value'
import useDetachLayout from '../hooks/use-detach-layout'
import { useIdeContext } from './ide-context'
@ -97,16 +95,6 @@ export function LayoutProvider({ children }) {
[setPdfLayout, setView]
)
// helper to avoid changing layout multiple times in rapid succession. This is
// especially useful for calling `changeLayout` as a side-effect. Calling
// `changeLayout` multiple times on page load cause layout rendering issues do
// to timming clash with Angular.
const debouncedChangeLayout = useRef(
debounce((newLayout, newView) => changeLayout(newLayout, newView), 1000, {
leading: true,
})
).current
const {
reattach,
detach,
@ -129,11 +117,9 @@ export function LayoutProvider({ children }) {
if (detachIsLinking || detachIsLinked) {
// the tab is linked to a detached tab (or about to be linked); show
// editor only
debouncedChangeLayout('flat', 'editor')
} else {
debouncedChangeLayout('sideBySide')
changeLayout('flat', 'editor')
}
}, [detachRole, detachIsLinking, detachIsLinked, debouncedChangeLayout])
}, [detachRole, detachIsLinking, detachIsLinked, changeLayout])
const value = useMemo(
() => ({