From 4a494a2eaff3d4e5bbf082e59836cf62fc9372f2 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Fri, 5 Apr 2024 12:40:28 +0100 Subject: [PATCH] Update useFileSystem.tsx (#3371) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- apps/dotcom/src/utils/useFileSystem.tsx | 43 ++++++++++++------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/apps/dotcom/src/utils/useFileSystem.tsx b/apps/dotcom/src/utils/useFileSystem.tsx index c76e1934d..c328bb138 100644 --- a/apps/dotcom/src/utils/useFileSystem.tsx +++ b/apps/dotcom/src/utils/useFileSystem.tsx @@ -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) } }, }