From e530e84772435b9ca19e6ae2d2423847900dfa7e Mon Sep 17 00:00:00 2001 From: Cocoon-Break <54054995+kuishou68@users.noreply.github.com> Date: Tue, 2 Jun 2026 11:44:47 +0800 Subject: [PATCH] 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> --- eslint-suppressions.json | 8 -------- web/app/components/workflow/note-node/hooks.ts | 6 ++++-- web/app/components/workflow/operator/hooks.ts | 6 ++++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/eslint-suppressions.json b/eslint-suppressions.json index fd2418701e..a8d3bf9b1e 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 6248e7670d..82d13e09bc 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(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 dcdfa4f629..adf2befd80 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(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,