From b92a1539021ed071f7f1ec706f3714eb5e26dc47 Mon Sep 17 00:00:00 2001 From: hjlarry Date: Sun, 14 Sep 2025 13:03:08 +0800 Subject: [PATCH] refactor code --- .../components/workflow/comment/cursor.tsx | 33 +++++ web/app/components/workflow/comment/icon.tsx | 28 ++++ web/app/components/workflow/comment/index.tsx | 133 +----------------- web/app/components/workflow/comment/input.tsx | 73 ++++++++++ 4 files changed, 137 insertions(+), 130 deletions(-) create mode 100644 web/app/components/workflow/comment/cursor.tsx create mode 100644 web/app/components/workflow/comment/icon.tsx create mode 100644 web/app/components/workflow/comment/input.tsx diff --git a/web/app/components/workflow/comment/cursor.tsx b/web/app/components/workflow/comment/cursor.tsx new file mode 100644 index 0000000000..70f3f12c6e --- /dev/null +++ b/web/app/components/workflow/comment/cursor.tsx @@ -0,0 +1,33 @@ +import type { FC } from 'react' +import { memo } from 'react' +import { useStore } from '../store' +import { ControlMode } from '../types' + +type CommentCursorProps = { + mousePosition: { elementX: number; elementY: number } +} + +export const CommentCursor: FC = memo(({ mousePosition }) => { + const controlMode = useStore(s => s.controlMode) + + if (controlMode !== ControlMode.Comment) + return null + + return ( +
+ + + + +
+ ) +}) + +CommentCursor.displayName = 'CommentCursor' diff --git a/web/app/components/workflow/comment/icon.tsx b/web/app/components/workflow/comment/icon.tsx new file mode 100644 index 0000000000..a183145421 --- /dev/null +++ b/web/app/components/workflow/comment/icon.tsx @@ -0,0 +1,28 @@ +import type { FC } from 'react' +import { memo } from 'react' +import type { WorkflowComment } from '@/service/workflow-comment' + +type CommentIconProps = { + comment: WorkflowComment + onClick: () => void +} + +export const CommentIcon: FC = memo(({ comment, onClick }) => { + return ( +
+
+ {'A'} +
+
+ ) +}) + +CommentIcon.displayName = 'CommentIcon' diff --git a/web/app/components/workflow/comment/index.tsx b/web/app/components/workflow/comment/index.tsx index bb5343f74e..558c15089c 100644 --- a/web/app/components/workflow/comment/index.tsx +++ b/web/app/components/workflow/comment/index.tsx @@ -1,130 +1,3 @@ -import type { FC } from 'react' -import { memo, useCallback, useState } from 'react' -import { useTranslation } from 'react-i18next' -import { useStore } from '../store' -import { ControlMode } from '../types' -import type { WorkflowComment } from '@/service/workflow-comment' - -type CommentCursorProps = { - mousePosition: { elementX: number; elementY: number } -} - -export const CommentCursor: FC = memo(({ mousePosition }) => { - const controlMode = useStore(s => s.controlMode) - - if (controlMode !== ControlMode.Comment) - return null - - return ( -
- - - - -
- ) -}) - -CommentCursor.displayName = 'CommentCursor' - -type CommentInputProps = { - position: { x: number; y: number } - onSubmit: (content: string) => void - onCancel: () => void -} - -export const CommentInput: FC = memo(({ position, onSubmit, onCancel }) => { - const { t } = useTranslation() - const [content, setContent] = useState('') - - const handleSubmit = useCallback(() => { - try { - if (content.trim()) { - onSubmit(content.trim()) - setContent('') - } - } - catch (error) { - console.error('Error in CommentInput handleSubmit:', error) - } - }, [content, onSubmit]) - - const handleKeyDown = useCallback((e: React.KeyboardEvent) => { - if (e.key === 'Enter' && !e.shiftKey) { - e.preventDefault() - handleSubmit() - } - else if (e.key === 'Escape') { - onCancel() - } - }, [handleSubmit, onCancel]) - - return ( -
-