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>
This commit is contained in:
Cocoon-Break
2026-06-02 11:44:47 +08:00
committed by GitHub
parent 2257a4f1ef
commit e530e84772
3 changed files with 8 additions and 12 deletions
@@ -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,
@@ -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,