diff --git a/web/app/components/app-sidebar/index.tsx b/web/app/components/app-sidebar/index.tsx index f90b7437d5..6d25a13051 100644 --- a/web/app/components/app-sidebar/index.tsx +++ b/web/app/components/app-sidebar/index.tsx @@ -1,7 +1,6 @@ -import React, { useEffect, useState } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import { usePathname } from 'next/navigation' import { useShallow } from 'zustand/react/shallow' -import { RiLayoutLeft2Line, RiLayoutRight2Line } from '@remixicon/react' import NavLink from './navLink' import type { NavIcon } from './navLink' import AppInfo from './app-info' @@ -11,6 +10,10 @@ import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { useStore as useAppStore } from '@/app/components/app/store' import { useEventEmitterContextContext } from '@/context/event-emitter' import cn from '@/utils/classnames' +import Divider from '../base/divider' +import { useHover, useKeyPress } from 'ahooks' +import ToggleButton from './toggle-button' +import { getKeyboardKeyCodeBySystem } from '../workflow/utils' export type IAppDetailNavProps = { iconType?: 'app' | 'dataset' | 'notion' @@ -33,15 +36,18 @@ const AppDetailNav = ({ appSidebarExpand: state.appSidebarExpand, setAppSidebarExpand: state.setAppSidebarExpand, }))) + const sidebarRef = React.useRef(null) const media = useBreakpoints() const isMobile = media === MediaType.mobile const expand = appSidebarExpand === 'expand' - const handleToggle = (state: string) => { - setAppSidebarExpand(state === 'expand' ? 'collapse' : 'expand') - } + const handleToggle = useCallback(() => { + setAppSidebarExpand(appSidebarExpand === 'expand' ? 'collapse' : 'expand') + }, [appSidebarExpand, setAppSidebarExpand]) + + const isHoveringSidebar = useHover(sidebarRef) - // // Check if the current path is a workflow canvas & fullscreen + // Check if the current path is a workflow canvas & fullscreen const pathname = usePathname() const inWorkflowCanvas = pathname.endsWith('/workflow') const workflowCanvasMaximize = localStorage.getItem('workflow-canvas-maximize') === 'true' @@ -60,16 +66,22 @@ const AppDetailNav = ({ } }, [appSidebarExpand, setAppSidebarExpand]) + useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.shift.b`, (e) => { + e.preventDefault() + handleToggle() + }, { exactMatch: true, useCapture: true }) + if (inWorkflowCanvas && hideHeader) { - return ( + return (
) -} + } return (
)}
-
-
+
+ + {!isMobile && isHoveringSidebar && ( + + )}
- { - !isMobile && ( -
-
handleToggle(appSidebarExpand)} - > - { - expand - ? - : - } -
-
- ) - }
) } diff --git a/web/app/components/app-sidebar/navLink.tsx b/web/app/components/app-sidebar/navLink.tsx index a69f0bd6aa..710c0e15e7 100644 --- a/web/app/components/app-sidebar/navLink.tsx +++ b/web/app/components/app-sidebar/navLink.tsx @@ -48,18 +48,18 @@ export default function NavLink({ type='button' disabled className={classNames( - 'opacity-30 text-components-menu-item-text hover:bg-state-base-hover group flex items-center h-9 rounded-md py-2 system-sm-medium cursor-not-allowed', - mode === 'expand' ? 'px-3' : 'px-2.5', + 'system-sm-medium flex h-8 cursor-not-allowed items-center rounded-lg text-components-menu-item-text opacity-30 hover:bg-state-base-hover', + mode === 'expand' ? 'pl-3 pr-1' : 'px-1.5', )} title={mode === 'collapse' ? name : ''} aria-disabled >
@@ -45,8 +45,7 @@ const VersionHistoryButton: FC = ({ useKeyPress(`${getKeyboardKeyCodeBySystem('ctrl')}.shift.h`, (e) => { e.preventDefault() handleViewVersionHistory() - }, - { exactMatch: true, useCapture: true }) + }, { exactMatch: true, useCapture: true }) return } diff --git a/web/i18n/en-US/layout.ts b/web/i18n/en-US/layout.ts index 928649474b..64f405f7c7 100644 --- a/web/i18n/en-US/layout.ts +++ b/web/i18n/en-US/layout.ts @@ -1,4 +1,8 @@ const translation = { + sidebar: { + expandSidebar: 'Expand Sidebar', + collapseSidebar: 'Collapse Sidebar', + }, } export default translation diff --git a/web/i18n/zh-Hans/layout.ts b/web/i18n/zh-Hans/layout.ts index 928649474b..b7ca9d7bf6 100644 --- a/web/i18n/zh-Hans/layout.ts +++ b/web/i18n/zh-Hans/layout.ts @@ -1,4 +1,8 @@ const translation = { + sidebar: { + expandSidebar: '展开侧边栏', + collapseSidebar: '收起侧边栏', + }, } export default translation