Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(web): migrate NOTE_SHOW_AUTHOR_STORAGE_KEY to useLocalStorage/useSetLocalStorage (#36915)

Cocoon-Breake530e8477243
diff --git a/eslint-suppressions.json b/eslint-suppressions.json
index fd2418701e5..a8d3bf9b1e7 100644
--- a/eslint-suppressions.json
+++ b/eslint-suppressions.json
@@ -4621,11 +4621,6 @@
"count": 5
}
},
- "web/app/components/workflow/note-node/hooks.ts": {
- "no-restricted-globals": {
- "count": 1
- }
- },
"web/app/components/workflow/note-node/note-editor/index.tsx": {
"no-barrel-files/no-barrel-files": {
"count": 3
@@ -4653,9 +4648,6 @@
}
},
"web/app/components/workflow/operator/hooks.ts": {
- "no-restricted-globals": {
- "count": 1
- },
"ts/no-explicit-any": {
"count": 1
}
diff --git a/web/app/components/workflow/note-node/hooks.ts b/web/app/components/workflow/note-node/hooks.ts
index 6248e7670d6..82d13e09bca 100644
--- a/web/app/components/workflow/note-node/hooks.ts
+++ b/web/app/components/workflow/note-node/hooks.ts
@@ -1,12 +1,14 @@
import type { EditorState } from 'lexical'
import type { NoteTheme } from './types'
import { useCallback } from 'react'
+import { useSetLocalStorage } from '@/hooks/use-local-storage'
import { useNodeDataUpdate, useWorkflowHistory, WorkflowHistoryEvent } from '../hooks'
import { NOTE_SHOW_AUTHOR_STORAGE_KEY } from './constants'
export const useNote = (id: string) => {
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
const { saveStateToHistory } = useWorkflowHistory()
+ const setShowAuthorStorage = useSetLocalStorage<string>(NOTE_SHOW_AUTHOR_STORAGE_KEY, { raw: true })
const handleThemeChange = useCallback((theme: NoteTheme) => {
handleNodeDataUpdateWithSyncDraft({ id, data: { theme } })
@@ -21,10 +23,10 @@ export const useNote = (id: string) => {
}, [handleNodeDataUpdateWithSyncDraft, id])
const handleShowAuthorChange = useCallback((showAuthor: boolean) => {
- localStorage.setItem(NOTE_SHOW_AUTHOR_STORAGE_KEY, String(showAuthor))
+ setShowAuthorStorage(String(showAuthor))
handleNodeDataUpdateWithSyncDraft({ id, data: { showAuthor } })
saveStateToHistory(WorkflowHistoryEvent.NoteChange, { nodeId: id })
- }, [handleNodeDataUpdateWithSyncDraft, id, saveStateToHistory])
+ }, [handleNodeDataUpdateWithSyncDraft, id, saveStateToHistory, setShowAuthorStorage])
return {
handleThemeChange,
diff --git a/web/app/components/workflow/operator/hooks.ts b/web/app/components/workflow/operator/hooks.ts
index dcdfa4f6299..adf2befd800 100644
--- a/web/app/components/workflow/operator/hooks.ts
+++ b/web/app/components/workflow/operator/hooks.ts
@@ -1,6 +1,7 @@
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,
@@ -12,6 +13,7 @@ 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({
@@ -23,7 +25,7 @@ export const useOperator = () => {
text: '',
theme: NoteTheme.blue,
author: userProfile?.name || '',
- showAuthor: localStorage.getItem(NOTE_SHOW_AUTHOR_STORAGE_KEY) !== 'false',
+ showAuthor: showAuthorStorage !== 'false',
width: 240,
height: 88,
_isCandidate: true,
@@ -36,7 +38,7 @@ export const useOperator = () => {
workflowStore.setState({
candidateNode: newNode,
})
- }, [workflowStore, userProfile])
+ }, [workflowStore, userProfile, showAuthorStorage])
return {
handleAddNote,