@@ -179,7 +179,7 @@ const ExcalidrawBoard: FC = () => {
179
179
const nodeCtx = useNodeViewContext ( )
180
180
const content = nodeCtx . node . attrs . value
181
181
182
- const [ initialContent ] = useState ( content )
182
+ const [ initialContent , resetInitialContent ] = useState ( content )
183
183
184
184
const [ forceUpdate , key ] = useForceUpdate ( )
185
185
useEffect ( ( ) => {
@@ -204,6 +204,10 @@ const ExcalidrawBoard: FC = () => {
204
204
const [ editorOption , setEditorOption ] = useAtom ( excalidrawOptionAtom )
205
205
const excalidrawRef = useRef < ExcalidrawRefObject > ( null )
206
206
207
+ const alreadyUploadValueFileMap = useRef (
208
+ { } as Record < string , string > ,
209
+ ) . current
210
+
207
211
const getFinalSaveValue = async ( ) : Promise < string | undefined > => {
208
212
if ( editorOption . delta ) {
209
213
const currentData = valueRef . current
@@ -250,12 +254,19 @@ const ExcalidrawBoard: FC = () => {
250
254
const currentData = valueRef . current
251
255
if ( ! currentData ) return
252
256
257
+ const hasUploaded = alreadyUploadValueFileMap [ currentData ]
258
+ if ( hasUploaded ) {
259
+ return hasUploaded
260
+ }
261
+
253
262
const file = new File ( [ currentData ] , 'file.excalidraw' , { } )
254
263
toast . info ( '正在上传文件' )
255
264
const result = await uploadFileToServer ( FileTypeEnum . File , file )
256
265
257
266
toast . success ( '上传成功' )
258
- return `ref:file/${ result . name } `
267
+ const refName = `ref:file/${ result . name } `
268
+ alreadyUploadValueFileMap [ currentData ] = refName
269
+ return refName
259
270
}
260
271
}
261
272
return (
@@ -307,6 +318,7 @@ const ExcalidrawBoard: FC = () => {
307
318
const value = await getFinalSaveValue ( )
308
319
if ( ! value ) return
309
320
nodeCtx . setAttrs ( { value } )
321
+ resetInitialContent ( value )
310
322
} }
311
323
>
312
324
< StyledButton
0 commit comments