From ea17f41b5b0034693620d37c3610ee72cbdbbb35 Mon Sep 17 00:00:00 2001 From: hjlarry Date: Wed, 17 Sep 2025 20:29:23 +0800 Subject: [PATCH] refactor reply code --- .../workflow/comment/comment-input.tsx | 2 - .../workflow/comment/mention-input.tsx | 55 ++++++++++++------- .../components/workflow/comment/thread.tsx | 29 +++++----- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/web/app/components/workflow/comment/comment-input.tsx b/web/app/components/workflow/comment/comment-input.tsx index aec613c4ca..0a0bfb3ee3 100644 --- a/web/app/components/workflow/comment/comment-input.tsx +++ b/web/app/components/workflow/comment/comment-input.tsx @@ -80,8 +80,6 @@ export const CommentInput: FC = memo(({ position, onSubmit, o onSubmit={handleMentionSubmit} placeholder="Add a comment" autoFocus - minRows={1} - maxRows={4} className="relative" /> diff --git a/web/app/components/workflow/comment/mention-input.tsx b/web/app/components/workflow/comment/mention-input.tsx index 64a5ab63c4..560fa94739 100644 --- a/web/app/components/workflow/comment/mention-input.tsx +++ b/web/app/components/workflow/comment/mention-input.tsx @@ -15,16 +15,12 @@ type MentionInputProps = { value: string onChange: (value: string) => void onSubmit: (content: string, mentionedUserIds: string[]) => void - onKeyDown?: (e: React.KeyboardEvent) => void + onCancel?: () => void placeholder?: string disabled?: boolean loading?: boolean className?: string - minRows?: number - maxRows?: number - showSubmitButton?: boolean - showMentionButton?: boolean - submitButtonIcon?: React.ReactNode + isEditing?: boolean autoFocus?: boolean } @@ -32,13 +28,12 @@ export const MentionInput: FC = memo(({ value, onChange, onSubmit, - onKeyDown, + onCancel, placeholder = 'Add a comment', disabled = false, loading = false, className, - showSubmitButton = true, - showMentionButton = true, + isEditing = false, autoFocus = false, }) => { const params = useParams() @@ -140,14 +135,16 @@ export const MentionInput: FC = memo(({ onChange(newContent) setShowMentionDropdown(false) - setMentionedUserIds(prev => [...prev, user.id]) + + const newMentionedUserIds = [...mentionedUserIds, user.id] + setMentionedUserIds(newMentionedUserIds) setTimeout(() => { const newCursorPos = mentionPosition + user.name.length + 2 // @ + name + space textarea.setSelectionRange(newCursorPos, newCursorPos) textarea.focus() }, 0) - }, [value, mentionPosition, onChange]) + }, [value, mentionPosition, onChange, mentionedUserIds]) const handleSubmit = useCallback((e?: React.MouseEvent) => { if (e) { @@ -194,9 +191,7 @@ export const MentionInput: FC = memo(({ e.preventDefault() handleSubmit() } - - onKeyDown?.(e) - }, [showMentionDropdown, filteredMentionUsers, selectedMentionIndex, insertMention, handleSubmit, onKeyDown]) + }, [showMentionDropdown, filteredMentionUsers, selectedMentionIndex, insertMention, handleSubmit]) const resetMentionState = useCallback(() => { setMentionedUserIds([]) @@ -221,7 +216,7 @@ export const MentionInput: FC = memo(({ )} placeholder={placeholder} autoFocus={autoFocus} - minRows={1} + minRows={isEditing ? 4 : 1} maxRows={4} value={value} disabled={disabled || loading} @@ -229,17 +224,14 @@ export const MentionInput: FC = memo(({ onKeyDown={handleKeyDown} /> - {(showMentionButton || showSubmitButton) && ( + {!isEditing && (
- {showMentionButton && (
- )} - {showSubmitButton && ( - )} +
+ )} + + {isEditing && ( +
+
+ +
+
+ + +
)} diff --git a/web/app/components/workflow/comment/thread.tsx b/web/app/components/workflow/comment/thread.tsx index 48417550cd..3e2b380786 100644 --- a/web/app/components/workflow/comment/thread.tsx +++ b/web/app/components/workflow/comment/thread.tsx @@ -1,13 +1,10 @@ 'use client' -import { useParams } from 'next/navigation' import type { FC } from 'react' import { memo, useCallback, useEffect, useMemo, useState } from 'react' import { useReactFlow, useViewport } from 'reactflow' import { RiArrowDownSLine, RiArrowUpSLine, RiCheckboxCircleFill, RiCheckboxCircleLine, RiCloseLine, RiDeleteBinLine, RiMoreFill } from '@remixicon/react' -import Textarea from 'react-textarea-autosize' import Avatar from '@/app/components/base/avatar' -import Button from '@/app/components/base/button' import Divider from '@/app/components/base/divider' import cn from '@/utils/classnames' import { useFormatTimeFromNow } from '@/app/components/workflow/hooks' @@ -75,7 +72,6 @@ export const CommentThread: FC = memo(({ onReplyEdit, onReplyDelete, }) => { - const params = useParams() const { flowToScreenPosition } = useReactFlow() const viewport = useViewport() const { userProfile } = useAppContext() @@ -115,11 +111,11 @@ export const CommentThread: FC = memo(({ setEditingReply({ id: '', content: '' }) }, []) - const handleSaveEdit = useCallback(async () => { + const handleEditSubmit = useCallback(async (content: string, mentionedUserIds: string[]) => { if (!onReplyEdit || !editingReply) return - const trimmed = editingReply.content.trim() + const trimmed = content.trim() if (!trimmed) return - await onReplyEdit(editingReply.id, trimmed, []) + await onReplyEdit(editingReply.id, trimmed, mentionedUserIds) setEditingReply({ id: '', content: '' }) }, [editingReply, onReplyEdit]) @@ -235,17 +231,18 @@ export const CommentThread: FC = memo(({ {isReplyEditing ? (
-