mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Upgrade react-resizable-panels (#16321)
GitOrigin-RevId: 524257c441fc98ffc0e3da6f1e703ebdfbfbffb7
This commit is contained in:
@@ -5,29 +5,15 @@ export default function useCollapsiblePanel(
|
||||
panelIsOpen: boolean,
|
||||
panelRef: RefObject<ImperativePanelHandle>
|
||||
) {
|
||||
// store the expanded height in localStorage when collapsing,
|
||||
// so it can be restored when expanding after reloading the page
|
||||
// collapse the panel when it is toggled closed (including on initial layout)
|
||||
useEffect(() => {
|
||||
const panelHandle = panelRef.current
|
||||
|
||||
if (panelHandle) {
|
||||
const storageKey = `ide-panel.expanded-size.${panelHandle.getId()}`
|
||||
if (!panelIsOpen) {
|
||||
// collapsing, so store the current size if > 0
|
||||
const size = panelHandle.getSize()
|
||||
if (size > 0) {
|
||||
localStorage.setItem(storageKey, String(size))
|
||||
}
|
||||
|
||||
panelHandle.collapse()
|
||||
if (panelIsOpen) {
|
||||
panelHandle.expand()
|
||||
} else {
|
||||
const storedKey = localStorage.getItem(storageKey)
|
||||
|
||||
if (storedKey) {
|
||||
panelHandle.resize(Number(storedKey))
|
||||
} else {
|
||||
panelHandle.expand()
|
||||
}
|
||||
panelHandle.collapse()
|
||||
}
|
||||
}
|
||||
}, [panelIsOpen, panelRef])
|
||||
|
||||
Reference in New Issue
Block a user