kopia lustrzana https://github.com/Tldraw/Tldraw
Update useFileSystem.tsx (#3371)
This PR makes a small change to how useFileSystem reports errors, so that legitimate errors may be caught. ### Change Type - [x] `sdk` — Changes the tldraw SDK - [x] `feature` — New featurepull/3291/head^2
rodzic
e8de70ec85
commit
4a494a2eaf
|
@ -108,34 +108,33 @@ export function getSaveFileCopyAction(
|
|||
readonlyOk: true,
|
||||
kbd: '$s',
|
||||
async onSelect(source) {
|
||||
handleUiEvent('save-project-to-file', { source })
|
||||
const documentName =
|
||||
editor.getDocumentSettings().name === ''
|
||||
? defaultDocumentName
|
||||
: editor.getDocumentSettings().name
|
||||
const defaultName =
|
||||
saveFileNames.get(editor.store) || `${documentName}${TLDRAW_FILE_EXTENSION}`
|
||||
|
||||
const blobToSave = serializeTldrawJsonBlob(editor.store)
|
||||
let handle
|
||||
try {
|
||||
handleUiEvent('save-project-to-file', { source })
|
||||
const documentName =
|
||||
editor.getDocumentSettings().name === ''
|
||||
? defaultDocumentName
|
||||
: editor.getDocumentSettings().name
|
||||
const defaultName =
|
||||
saveFileNames.get(editor.store) || `${documentName}${TLDRAW_FILE_EXTENSION}`
|
||||
|
||||
const blobToSave = serializeTldrawJsonBlob(editor.store)
|
||||
|
||||
const handle = await fileSave(blobToSave, {
|
||||
handle = await fileSave(blobToSave, {
|
||||
fileName: defaultName,
|
||||
extensions: [TLDRAW_FILE_EXTENSION],
|
||||
description: 'tldraw project',
|
||||
})
|
||||
|
||||
if (handle) {
|
||||
// we deliberately don't store the handle for re-use
|
||||
// next time. we always want to save a copy, but to
|
||||
// help the user out we'll remember the last name
|
||||
// they used
|
||||
saveFileNames.set(editor.store, handle.name)
|
||||
} else {
|
||||
throw Error('Could not save file.')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
// user cancelled
|
||||
return
|
||||
}
|
||||
|
||||
if (handle) {
|
||||
// we deliberately don't store the handle for re-use
|
||||
// next time. we always want to save a copy, but to
|
||||
// help the user out we'll remember the last name
|
||||
// they used
|
||||
saveFileNames.set(editor.store, handle.name)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue