diff --git a/services/web/frontend/js/features/ide-redesign/components/rail.tsx b/services/web/frontend/js/features/ide-redesign/components/rail.tsx index 1625e56b0d..877e40666e 100644 --- a/services/web/frontend/js/features/ide-redesign/components/rail.tsx +++ b/services/web/frontend/js/features/ide-redesign/components/rail.tsx @@ -44,6 +44,7 @@ import OldErrorPane from './error-logs/old-error-pane' import { useFeatureFlag } from '@/shared/context/split-test-context' import { useSurveyUrl } from '../hooks/use-survey-url' import { useProjectContext } from '@/shared/context/project-context' +import usePreviousValue from '@/shared/hooks/use-previous-value' type RailElement = { icon: AvailableUnfilledIcon @@ -217,6 +218,18 @@ export const RailLayout = () => { const isReviewPanelOpen = selectedTab === 'review-panel' + const prevTab = usePreviousValue(selectedTab) + + const tabHasChanged = useMemo(() => { + return prevTab !== selectedTab + }, [prevTab, selectedTab]) + + const onCollapse = useCallback(() => { + if (!tabHasChanged) { + handlePaneCollapse() + } + }, [tabHasChanged, handlePaneCollapse]) + return ( { maxSize={80} ref={panelRef} collapsible - onCollapse={handlePaneCollapse} + onCollapse={onCollapse} onExpand={handlePaneExpand} > {isHistoryView && } diff --git a/services/web/frontend/js/features/ide-redesign/contexts/rail-context.tsx b/services/web/frontend/js/features/ide-redesign/contexts/rail-context.tsx index c52671b42b..4a882076ec 100644 --- a/services/web/frontend/js/features/ide-redesign/contexts/rail-context.tsx +++ b/services/web/frontend/js/features/ide-redesign/contexts/rail-context.tsx @@ -1,5 +1,4 @@ import { sendSearchEvent } from '@/features/event-tracking/search-events' -import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-panel' import useEventListener from '@/shared/hooks/use-event-listener' import { isMac } from '@/shared/utils/os' import { @@ -9,6 +8,8 @@ import { SetStateAction, useCallback, useContext, + useEffect, + useLayoutEffect, useMemo, useRef, useState, @@ -55,7 +56,6 @@ export const RailProvider: FC = ({ children }) => { }, []) const panelRef = useRef(null) - useCollapsiblePanel(isOpen, panelRef) const togglePane = useCallback(() => { setIsOpen(value => !value) @@ -73,6 +73,19 @@ export const RailProvider: FC = ({ children }) => { // since it is responsible for opening the initial document. const [selectedTab, setSelectedTab] = useState('file-tree') + // Keep the panel collapse/expanded state in sync with isOpen and selectedTab + useLayoutEffect(() => { + const panelHandle = panelRef.current + + if (panelHandle) { + if (isOpen) { + panelHandle.expand() + } else { + panelHandle.collapse() + } + } + }, [isOpen, selectedTab]) + const openTab = useCallback( (tab: RailTabKey) => { setSelectedTab(tab)