dify/web/app/components/workflow/operator/hooks.ts
Cocoon-Break e530e84772
refactor(web): migrate NOTE_SHOW_AUTHOR_STORAGE_KEY to useLocalStorage/useSetLocalStorage (#36915)
Signed-off-by: Cocoon-Break <54054995+kuishou68@users.noreply.github.com>
Co-authored-by: lingxiu58 <86288566+lingxiu58@users.noreply.github.com>
Co-authored-by: pojian68 <232320289+pojian68@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-06-02 03:44:47 +00:00

47 lines
1.3 KiB
TypeScript

import type { NoteNodeType } from '../note-node/types'
import { useCallback } from 'react'
import { useAppContext } from '@/context/app-context'
import { useLocalStorage } from '@/hooks/use-local-storage'
import {
CUSTOM_NOTE_NODE,
NOTE_SHOW_AUTHOR_STORAGE_KEY,
} from '../note-node/constants'
import { NoteTheme } from '../note-node/types'
import { useWorkflowStore } from '../store'
import { generateNewNode } from '../utils'
export const useOperator = () => {
const workflowStore = useWorkflowStore()
const { userProfile } = useAppContext()
const [showAuthorStorage] = useLocalStorage<string>(NOTE_SHOW_AUTHOR_STORAGE_KEY, 'true', { raw: true })
const handleAddNote = useCallback(() => {
const { newNode } = generateNewNode({
type: CUSTOM_NOTE_NODE,
data: {
title: '',
desc: '',
type: '' as any,
text: '',
theme: NoteTheme.blue,
author: userProfile?.name || '',
showAuthor: showAuthorStorage !== 'false',
width: 240,
height: 88,
_isCandidate: true,
} as NoteNodeType,
position: {
x: 0,
y: 0,
},
})
workflowStore.setState({
candidateNode: newNode,
})
}, [workflowStore, userProfile, showAuthorStorage])
return {
handleAddNote,
}
}