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 feature
pull/3291/head^2
Steve Ruiz 2024-04-05 12:40:28 +01:00 zatwierdzone przez GitHub
rodzic e8de70ec85
commit 4a494a2eaf
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
1 zmienionych plików z 21 dodań i 22 usunięć

Wyświetl plik

@ -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)
}
},
}