diff --git a/web/app/components/workflow/skill/constants.ts b/web/app/components/workflow/skill/constants.ts index ccf6cc736b..e25bd7442f 100644 --- a/web/app/components/workflow/skill/constants.ts +++ b/web/app/components/workflow/skill/constants.ts @@ -27,3 +27,7 @@ export const NODE_MENU_TYPE = { } as const export type NodeMenuType = (typeof NODE_MENU_TYPE)[keyof typeof NODE_MENU_TYPE] + +export const SIDEBAR_MIN_WIDTH = 240 +export const SIDEBAR_MAX_WIDTH = 480 +export const SIDEBAR_DEFAULT_WIDTH = 320 diff --git a/web/app/components/workflow/skill/sidebar.tsx b/web/app/components/workflow/skill/sidebar.tsx index b581056280..7ad36f3dc6 100644 --- a/web/app/components/workflow/skill/sidebar.tsx +++ b/web/app/components/workflow/skill/sidebar.tsx @@ -1,12 +1,47 @@ +'use client' + import type { FC, PropsWithChildren } from 'react' +import { useDebounceFn } from 'ahooks' import * as React from 'react' +import { useCallback } from 'react' +import { STORAGE_KEYS } from '@/config/storage-keys' +import { storage } from '@/utils/storage' +import { useResizePanel } from '../nodes/_base/hooks/use-resize-panel' +import { SIDEBAR_DEFAULT_WIDTH, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH } from './constants' type SidebarProps = PropsWithChildren const Sidebar: FC = ({ children }) => { + const { run: persistWidth } = useDebounceFn( + (width: number) => storage.set(STORAGE_KEYS.SKILL.SIDEBAR_WIDTH, width), + { wait: 200 }, + ) + + const handleResize = useCallback((width: number) => { + persistWidth(width) + }, [persistWidth]) + + const { triggerRef, containerRef } = useResizePanel({ + direction: 'horizontal', + triggerDirection: 'right', + minWidth: SIDEBAR_MIN_WIDTH, + maxWidth: SIDEBAR_MAX_WIDTH, + onResize: handleResize, + }) + return ( -