diff --git a/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx b/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx index 8c9078514c..196c36f330 100644 --- a/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/file-tree-open-context.tsx @@ -32,6 +32,8 @@ const FileTreeOpenContext = createContext< handleFileTreeDelete: (entity: FileTreeFindResult) => void fileTreeExpanded: boolean toggleFileTreeExpanded: () => void + expandFileTree: () => void + collapseFileTree: () => void } | undefined >(undefined) @@ -59,6 +61,14 @@ export const FileTreeOpenProvider: FC = ({ setFileTreeExpanded(prev => !prev) }, []) + const expandFileTree = useCallback(() => { + setFileTreeExpanded(true) + }, []) + + const collapseFileTree = useCallback(() => { + setFileTreeExpanded(false) + }, []) + const handleFileTreeInit = useCallback(() => { setFileTreeReady(true) }, []) @@ -144,6 +154,8 @@ export const FileTreeOpenProvider: FC = ({ handleFileTreeDelete, fileTreeExpanded, toggleFileTreeExpanded, + expandFileTree, + collapseFileTree, } }, [ handleFileTreeDelete, @@ -153,6 +165,8 @@ export const FileTreeOpenProvider: FC = ({ selectedEntityCount, fileTreeExpanded, toggleFileTreeExpanded, + expandFileTree, + collapseFileTree, ]) return ( diff --git a/services/web/frontend/js/features/ide-react/context/outline-context.tsx b/services/web/frontend/js/features/ide-react/context/outline-context.tsx index 40c2cb1928..05409cf075 100644 --- a/services/web/frontend/js/features/ide-react/context/outline-context.tsx +++ b/services/web/frontend/js/features/ide-react/context/outline-context.tsx @@ -38,6 +38,8 @@ const OutlineContext = createContext< canShowOutline: boolean outlineExpanded: boolean toggleOutlineExpanded: () => void + expandOutline: () => void + collapseOutline: () => void } | undefined >(undefined) @@ -133,15 +135,29 @@ export const OutlineProvider: FC = ({ children }) => { const canShowOutline = isTexFile && !binaryFileOpened - const toggleOutlineExpanded = useCallback(() => { + const expandOutline = useCallback(() => { if (canShowOutline) { - localStorage.setItem(storageKey, !outlineExpanded) - eventTracking.sendMB( - outlineExpanded ? 'outline-collapse' : 'outline-expand' - ) - setOutlineExpanded(!outlineExpanded) + localStorage.setItem(storageKey, true) + eventTracking.sendMB('outline-expand') + setOutlineExpanded(true) } - }, [canShowOutline, outlineExpanded, storageKey]) + }, [canShowOutline, storageKey]) + + const collapseOutline = useCallback(() => { + if (canShowOutline) { + localStorage.setItem(storageKey, false) + eventTracking.sendMB('outline-collapse') + setOutlineExpanded(false) + } + }, [canShowOutline, storageKey]) + + const toggleOutlineExpanded = useCallback(() => { + if (outlineExpanded) { + collapseOutline() + } else { + expandOutline() + } + }, [collapseOutline, expandOutline, outlineExpanded]) const value = useMemo( () => ({ @@ -152,6 +168,8 @@ export const OutlineProvider: FC = ({ children }) => { canShowOutline, outlineExpanded, toggleOutlineExpanded, + expandOutline, + collapseOutline, }), [ flatOutline, @@ -160,6 +178,8 @@ export const OutlineProvider: FC = ({ children }) => { canShowOutline, outlineExpanded, toggleOutlineExpanded, + expandOutline, + collapseOutline, ] ) diff --git a/services/web/frontend/js/features/ide-react/hooks/use-outline-pane.ts b/services/web/frontend/js/features/ide-react/hooks/use-outline-pane.ts index f17c94427b..a8929a7387 100644 --- a/services/web/frontend/js/features/ide-react/hooks/use-outline-pane.ts +++ b/services/web/frontend/js/features/ide-react/hooks/use-outline-pane.ts @@ -4,11 +4,18 @@ import { useRef } from 'react' import { ImperativePanelHandle } from 'react-resizable-panels' export const useOutlinePane = () => { - const { canShowOutline, outlineExpanded } = useOutlineContext() + const { canShowOutline, outlineExpanded, expandOutline, collapseOutline } = + useOutlineContext() const outlinePanelRef = useRef(null) const outlineEnabled = canShowOutline && outlineExpanded useCollapsiblePanel(outlineEnabled, outlinePanelRef) - return { outlineEnabled, outlinePanelRef } + return { + outlineEnabled, + canShowOutline, + outlinePanelRef, + expandOutline, + collapseOutline, + } } diff --git a/services/web/frontend/js/features/ide-redesign/components/file-tree/file-tree-outline-panel.tsx b/services/web/frontend/js/features/ide-redesign/components/file-tree/file-tree-outline-panel.tsx index 62c228973e..3fe4af3942 100644 --- a/services/web/frontend/js/features/ide-redesign/components/file-tree/file-tree-outline-panel.tsx +++ b/services/web/frontend/js/features/ide-redesign/components/file-tree/file-tree-outline-panel.tsx @@ -7,8 +7,14 @@ import useCollapsibleFileTree from '../../hooks/use-collapsible-file-tree' import classNames from 'classnames' function FileTreeOutlinePanel() { - const { outlineEnabled, outlinePanelRef } = useOutlinePane() - const { fileTreeExpanded, fileTreePanelRef } = useCollapsibleFileTree() + const { canShowOutline, outlinePanelRef, expandOutline, collapseOutline } = + useOutlinePane() + const { + fileTreeExpanded, + fileTreePanelRef, + expandFileTree, + collapseFileTree, + } = useCollapsibleFileTree() return ( diff --git a/services/web/frontend/js/features/ide-redesign/hooks/use-collapsible-file-tree.tsx b/services/web/frontend/js/features/ide-redesign/hooks/use-collapsible-file-tree.tsx index 89b4d252a1..9fdcacf01f 100644 --- a/services/web/frontend/js/features/ide-redesign/hooks/use-collapsible-file-tree.tsx +++ b/services/web/frontend/js/features/ide-redesign/hooks/use-collapsible-file-tree.tsx @@ -4,9 +4,21 @@ import useCollapsiblePanel from '@/features/ide-react/hooks/use-collapsible-pane import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context' export default function useCollapsibleFileTree() { - const { fileTreeExpanded, toggleFileTreeExpanded } = useFileTreeOpenContext() + const { + fileTreeExpanded, + toggleFileTreeExpanded, + expandFileTree, + collapseFileTree, + } = useFileTreeOpenContext() const fileTreePanelRef = useRef(null) + useCollapsiblePanel(fileTreeExpanded, fileTreePanelRef) - return { fileTreeExpanded, fileTreePanelRef, toggleFileTreeExpanded } + return { + fileTreeExpanded, + fileTreePanelRef, + toggleFileTreeExpanded, + expandFileTree, + collapseFileTree, + } }