cleanup
This commit is contained in:
@@ -98,12 +98,13 @@ const persistWidth = (panel: PanelKey, value: number): void => {
|
||||
window.localStorage.setItem(STORAGE_KEYS[panel], String(Math.round(value)));
|
||||
};
|
||||
|
||||
const applyPanelWidthToRoot = (panel: PanelKey, width: number): void => {
|
||||
const applyPanelWidthToRoot = (panel: PanelKey, width: number, active: boolean): void => {
|
||||
if (!Number.isFinite(width)) {
|
||||
return;
|
||||
}
|
||||
const varName = panel === 'sidebar' ? '--sidebar-width' : '--detail-panel-width';
|
||||
document.documentElement.style.setProperty(varName, `${width}px`);
|
||||
const resolvedValue = panel === 'detail' && !active ? '0px' : `${width}px`;
|
||||
document.documentElement.style.setProperty(varName, resolvedValue);
|
||||
};
|
||||
|
||||
interface PanelManagerProviderProps {
|
||||
@@ -132,13 +133,13 @@ export const PanelManagerProvider: React.FC<PanelManagerProviderProps> = ({ chil
|
||||
|
||||
useEffect(() => {
|
||||
panelWidthsRef.current.sidebar = sidebarWidth;
|
||||
applyPanelWidthToRoot('sidebar', sidebarWidth);
|
||||
applyPanelWidthToRoot('sidebar', sidebarWidth, true);
|
||||
}, [sidebarWidth]);
|
||||
|
||||
useEffect(() => {
|
||||
panelWidthsRef.current.detail = detailWidth;
|
||||
applyPanelWidthToRoot('detail', detailWidth);
|
||||
}, [detailWidth]);
|
||||
applyPanelWidthToRoot('detail', detailWidth, detailPanelOpen);
|
||||
}, [detailWidth, detailPanelOpen]);
|
||||
|
||||
const handlePanelLayoutChange = useCallback((
|
||||
panel: PanelKey,
|
||||
@@ -187,7 +188,6 @@ export const PanelManagerProvider: React.FC<PanelManagerProviderProps> = ({ chil
|
||||
setDetailWidthState((prev) => (prev === clamped ? prev : clamped));
|
||||
}
|
||||
panelWidthsRef.current[panel] = clamped;
|
||||
applyPanelWidthToRoot(panel, clamped);
|
||||
if (commit) {
|
||||
preferredPanelWidthsRef.current[panel] = clamped;
|
||||
persistWidth(panel, clamped);
|
||||
|
||||
Reference in New Issue
Block a user