feat: workflow add note node (#5164)

This commit is contained in:
zxhlyh
2024-06-14 17:08:11 +08:00
committed by GitHub
parent d7fbae286a
commit c28d709d7f
69 changed files with 2375 additions and 169 deletions

View File

@@ -0,0 +1,29 @@
import { useCallback } from 'react'
import type { EditorState } from 'lexical'
import { useNodeDataUpdate } from '../hooks'
import type { NoteTheme } from './types'
export const useNote = (id: string) => {
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
const handleThemeChange = useCallback((theme: NoteTheme) => {
handleNodeDataUpdateWithSyncDraft({ id, data: { theme } })
}, [handleNodeDataUpdateWithSyncDraft, id])
const handleEditorChange = useCallback((editorState: EditorState) => {
if (!editorState?.isEmpty())
handleNodeDataUpdateWithSyncDraft({ id, data: { text: JSON.stringify(editorState) } })
else
handleNodeDataUpdateWithSyncDraft({ id, data: { text: '' } })
}, [handleNodeDataUpdateWithSyncDraft, id])
const handleShowAuthorChange = useCallback((showAuthor: boolean) => {
handleNodeDataUpdateWithSyncDraft({ id, data: { showAuthor } })
}, [handleNodeDataUpdateWithSyncDraft, id])
return {
handleThemeChange,
handleEditorChange,
handleShowAuthorChange,
}
}