mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 15:57:06 +08:00
refactor delete comment and reply
This commit is contained in:
parent
ff2f7206f3
commit
3d6295c622
@ -138,8 +138,6 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const reactflow = useReactFlow()
|
const reactflow = useReactFlow()
|
||||||
const [isMouseOverCanvas, setIsMouseOverCanvas] = useState(false)
|
const [isMouseOverCanvas, setIsMouseOverCanvas] = useState(false)
|
||||||
const [pendingDeleteCommentId, setPendingDeleteCommentId] = useState<string | null>(null)
|
|
||||||
const [pendingDeleteReply, setPendingDeleteReply] = useState<{ commentId: string; replyId: string } | null>(null)
|
|
||||||
const [nodes, setNodes] = useNodesState(originalNodes)
|
const [nodes, setNodes] = useNodesState(originalNodes)
|
||||||
const [edges, setEdges] = useEdgesState(originalEdges)
|
const [edges, setEdges] = useEdgesState(originalEdges)
|
||||||
const controlMode = useStore(s => s.controlMode)
|
const controlMode = useStore(s => s.controlMode)
|
||||||
@ -243,6 +241,33 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
setTimeout(() => handleRefreshWorkflowDraft(), 500)
|
setTimeout(() => handleRefreshWorkflowDraft(), 500)
|
||||||
}, [syncWorkflowDraftWhenPageClose, handleRefreshWorkflowDraft])
|
}, [syncWorkflowDraftWhenPageClose, handleRefreshWorkflowDraft])
|
||||||
|
|
||||||
|
// Optimized comment deletion using showConfirm
|
||||||
|
const handleCommentDeleteClick = useCallback((commentId: string) => {
|
||||||
|
if (!showConfirm) {
|
||||||
|
setShowConfirm({
|
||||||
|
title: 'Delete this thread?',
|
||||||
|
desc: 'This action will permanently delete the thread and all its replies. This cannot be undone.',
|
||||||
|
onConfirm: async () => {
|
||||||
|
await handleCommentDelete(commentId)
|
||||||
|
setShowConfirm(undefined)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [showConfirm, setShowConfirm, handleCommentDelete])
|
||||||
|
|
||||||
|
const handleCommentReplyDeleteClick = useCallback((commentId: string, replyId: string) => {
|
||||||
|
if (!showConfirm) {
|
||||||
|
setShowConfirm({
|
||||||
|
title: 'Delete this reply?',
|
||||||
|
desc: 'This reply will be removed permanently.',
|
||||||
|
onConfirm: async () => {
|
||||||
|
await handleCommentReplyDelete(commentId, replyId)
|
||||||
|
setShowConfirm(undefined)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [showConfirm, setShowConfirm, handleCommentReplyDelete])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.addEventListener('visibilitychange', handleSyncWorkflowDraftWhenPageClose)
|
document.addEventListener('visibilitychange', handleSyncWorkflowDraftWhenPageClose)
|
||||||
|
|
||||||
@ -412,30 +437,6 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
content={showConfirm.desc}
|
content={showConfirm.desc}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{pendingDeleteCommentId && (
|
|
||||||
<Confirm
|
|
||||||
isShow
|
|
||||||
title='Delete this thread?'
|
|
||||||
content='This action will permanently delete the thread and all its replies. This cannot be undone.'
|
|
||||||
onCancel={() => setPendingDeleteCommentId(null)}
|
|
||||||
onConfirm={async () => {
|
|
||||||
await handleCommentDelete(pendingDeleteCommentId)
|
|
||||||
setPendingDeleteCommentId(null)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{pendingDeleteReply && (
|
|
||||||
<Confirm
|
|
||||||
isShow
|
|
||||||
title='Delete this reply?'
|
|
||||||
content='This reply will be removed permanently.'
|
|
||||||
onCancel={() => setPendingDeleteReply(null)}
|
|
||||||
onConfirm={async () => {
|
|
||||||
await handleCommentReplyDelete(pendingDeleteReply.commentId, pendingDeleteReply.replyId)
|
|
||||||
setPendingDeleteReply(null)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<LimitTips />
|
<LimitTips />
|
||||||
{controlMode === ControlMode.Comment && isMouseOverCanvas && (
|
{controlMode === ControlMode.Comment && isMouseOverCanvas && (
|
||||||
<CommentCursor mousePosition={mousePosition} />
|
<CommentCursor mousePosition={mousePosition} />
|
||||||
@ -467,12 +468,12 @@ export const Workflow: FC<WorkflowProps> = memo(({
|
|||||||
loading={activeCommentLoading}
|
loading={activeCommentLoading}
|
||||||
onClose={handleActiveCommentClose}
|
onClose={handleActiveCommentClose}
|
||||||
onResolve={() => handleCommentResolve(comment.id)}
|
onResolve={() => handleCommentResolve(comment.id)}
|
||||||
onDelete={() => setPendingDeleteCommentId(comment.id)}
|
onDelete={() => handleCommentDeleteClick(comment.id)}
|
||||||
onPrev={canGoPrev ? () => handleCommentNavigate('prev') : undefined}
|
onPrev={canGoPrev ? () => handleCommentNavigate('prev') : undefined}
|
||||||
onNext={canGoNext ? () => handleCommentNavigate('next') : undefined}
|
onNext={canGoNext ? () => handleCommentNavigate('next') : undefined}
|
||||||
onReply={(content, ids) => handleCommentReply(comment.id, content, ids ?? [])}
|
onReply={(content, ids) => handleCommentReply(comment.id, content, ids ?? [])}
|
||||||
onReplyEdit={(replyId, content, ids) => handleCommentReplyUpdate(comment.id, replyId, content, ids ?? [])}
|
onReplyEdit={(replyId, content, ids) => handleCommentReplyUpdate(comment.id, replyId, content, ids ?? [])}
|
||||||
onReplyDelete={replyId => setPendingDeleteReply({ commentId: comment.id, replyId })}
|
onReplyDelete={replyId => handleCommentReplyDeleteClick(comment.id, replyId)}
|
||||||
canGoPrev={canGoPrev}
|
canGoPrev={canGoPrev}
|
||||||
canGoNext={canGoNext}
|
canGoNext={canGoNext}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user