Skip to content

Commit 12351b9

Browse files
committed
fix: reset initial data
Signed-off-by: Innei <[email protected]>
1 parent bcb3e5b commit 12351b9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/components/ui/editor/Milkdown/plugins/Excalidraw.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const ExcalidrawBoard: FC = () => {
179179
const nodeCtx = useNodeViewContext()
180180
const content = nodeCtx.node.attrs.value
181181

182-
const [initialContent] = useState(content)
182+
const [initialContent, resetInitialContent] = useState(content)
183183

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

207+
const alreadyUploadValueFileMap = useRef(
208+
{} as Record<string, string>,
209+
).current
210+
207211
const getFinalSaveValue = async (): Promise<string | undefined> => {
208212
if (editorOption.delta) {
209213
const currentData = valueRef.current
@@ -250,12 +254,19 @@ const ExcalidrawBoard: FC = () => {
250254
const currentData = valueRef.current
251255
if (!currentData) return
252256

257+
const hasUploaded = alreadyUploadValueFileMap[currentData]
258+
if (hasUploaded) {
259+
return hasUploaded
260+
}
261+
253262
const file = new File([currentData], 'file.excalidraw', {})
254263
toast.info('正在上传文件')
255264
const result = await uploadFileToServer(FileTypeEnum.File, file)
256265

257266
toast.success('上传成功')
258-
return `ref:file/${result.name}`
267+
const refName = `ref:file/${result.name}`
268+
alreadyUploadValueFileMap[currentData] = refName
269+
return refName
259270
}
260271
}
261272
return (
@@ -307,6 +318,7 @@ const ExcalidrawBoard: FC = () => {
307318
const value = await getFinalSaveValue()
308319
if (!value) return
309320
nodeCtx.setAttrs({ value })
321+
resetInitialContent(value)
310322
}}
311323
>
312324
<StyledButton

0 commit comments

Comments
 (0)