Skip to content

Commit

Permalink
fix: reset initial data
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Feb 3, 2024
1 parent bcb3e5b commit 12351b9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/ui/editor/Milkdown/plugins/Excalidraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const ExcalidrawBoard: FC = () => {
const nodeCtx = useNodeViewContext()
const content = nodeCtx.node.attrs.value

const [initialContent] = useState(content)
const [initialContent, resetInitialContent] = useState(content)

const [forceUpdate, key] = useForceUpdate()
useEffect(() => {
Expand All @@ -204,6 +204,10 @@ const ExcalidrawBoard: FC = () => {
const [editorOption, setEditorOption] = useAtom(excalidrawOptionAtom)
const excalidrawRef = useRef<ExcalidrawRefObject>(null)

const alreadyUploadValueFileMap = useRef(
{} as Record<string, string>,
).current

const getFinalSaveValue = async (): Promise<string | undefined> => {
if (editorOption.delta) {
const currentData = valueRef.current
Expand Down Expand Up @@ -250,12 +254,19 @@ const ExcalidrawBoard: FC = () => {
const currentData = valueRef.current
if (!currentData) return

const hasUploaded = alreadyUploadValueFileMap[currentData]
if (hasUploaded) {
return hasUploaded
}

const file = new File([currentData], 'file.excalidraw', {})
toast.info('正在上传文件')
const result = await uploadFileToServer(FileTypeEnum.File, file)

toast.success('上传成功')
return `ref:file/${result.name}`
const refName = `ref:file/${result.name}`
alreadyUploadValueFileMap[currentData] = refName
return refName
}
}
return (
Expand Down Expand Up @@ -307,6 +318,7 @@ const ExcalidrawBoard: FC = () => {
const value = await getFinalSaveValue()
if (!value) return
nodeCtx.setAttrs({ value })
resetInitialContent(value)
}}
>
<StyledButton
Expand Down

0 comments on commit 12351b9

Please sign in to comment.