Skip to content

Commit d37a063

Browse files
committed
fix: Abort error in Open, Save, Save as on pressing cancel button
1 parent bb1a501 commit d37a063

3 files changed

Lines changed: 66 additions & 41 deletions

File tree

src/component/fileBrowser.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,15 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
121121
multiple: false,
122122
};
123123

124-
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
125-
const fileObj = await fileHandle.getFile();
126-
readFile(superState, dispatcher, fileObj, fileHandle);
124+
try {
125+
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
126+
const fileObj = await fileHandle.getFile();
127+
readFile(superState, dispatcher, fileObj, fileHandle);
128+
} catch (error) {
129+
if (error.name !== 'AbortError') {
130+
console.error(error);
131+
}
132+
}
127133
};
128134

129135
return (

src/component/modals/FileEdit.jsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,26 @@ const FileEditModal = ({ superState, dispatcher }) => {
3939
}
4040

4141
async function saveAsSubmit() {
42-
const handle = await window.showSaveFilePicker();
43-
const stream = await handle.createWritable();
44-
await stream.write(codeStuff);
45-
await stream.close();
46-
const fileData = await handle.getFile();
47-
let fS = superState.fileState;
48-
fS = fS.concat([{
49-
key: `${superState.uploadedDirName}/${handle.name}`,
50-
modified: fileData.lastModified,
51-
size: fileData.size,
52-
fileObj: fileData,
53-
fileHandle: handle,
54-
}]);
55-
dispatcher({ type: T.SET_FILE_STATE, payload: fS });
42+
try {
43+
const handle = await window.showSaveFilePicker();
44+
const stream = await handle.createWritable();
45+
await stream.write(codeStuff);
46+
await stream.close();
47+
const fileData = await handle.getFile();
48+
let fS = superState.fileState;
49+
fS = fS.concat([{
50+
key: `${superState.uploadedDirName}/${handle.name}`,
51+
modified: fileData.lastModified,
52+
size: fileData.size,
53+
fileObj: fileData,
54+
fileHandle: handle,
55+
}]);
56+
dispatcher({ type: T.SET_FILE_STATE, payload: fS });
57+
} catch (error) {
58+
if (error.name !== 'AbortError') {
59+
console.error(error);
60+
}
61+
}
5662
}
5763

5864
function handleSaveAsClick() {

src/graph-builder/graph-core/5-load-save.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,33 @@ class GraphLoadSave extends GraphUndoRedo {
117117
},
118118
],
119119
};
120-
const handle = await window.showSaveFilePicker(options);
121-
const stream = await handle.createWritable();
122-
await stream.write(blob);
123-
await stream.close();
124-
const fileData = await handle.getFile();
125-
let fS = this.superState.fileState;
126-
fS = fS.concat([{
127-
key: `${this.superState.uploadedDirName}/${handle.name}`,
128-
modified: fileData.lastModified,
129-
size: fileData.size,
130-
fileObj: fileData,
131-
fileHandle: handle,
132-
}]);
133-
this.dispatcher({ type: T.SET_FILE_STATE, payload: fS });
120+
try {
121+
const handle = await window.showSaveFilePicker(options);
122+
const stream = await handle.createWritable();
123+
await stream.write(blob);
124+
await stream.close();
125+
const fileData = await handle.getFile();
126+
let fS = this.superState.fileState;
127+
fS = fS.concat([{
128+
key: `${this.superState.uploadedDirName}/${handle.name}`,
129+
modified: fileData.lastModified,
130+
size: fileData.size,
131+
fileObj: fileData,
132+
fileHandle: handle,
133+
}]);
134+
this.dispatcher({ type: T.SET_FILE_STATE, payload: fS });
135+
toast.success('File saved Successfully');
136+
} catch (error) {
137+
if (error.name !== 'AbortError') {
138+
console.error(error);
139+
}
140+
}
134141
} else {
135142
// eslint-disable-next-line no-alert
136143
const fileName = prompt('Filename:');
137144
saveAs(blob, `${fileName || `${this.getName()}-concore`}.graphml`);
145+
toast.success('File saved Successfully');
138146
}
139-
toast.success('File saved Successfully');
140147
}
141148

142149
async saveWithoutFileHandle() {
@@ -158,15 +165,21 @@ class GraphLoadSave extends GraphUndoRedo {
158165
},
159166
],
160167
};
161-
const handle = await window.showSaveFilePicker(options);
162-
this.dispatcher({
163-
type: T.SET_FILE_HANDLE,
164-
payload: { curGraphIndex: this.superState.curGraphIndex, fileHandle: handle },
165-
});
166-
const stream = await handle.createWritable();
167-
await stream.write(blob);
168-
await stream.close();
169-
toast.success('File saved Successfully');
168+
try {
169+
const handle = await window.showSaveFilePicker(options);
170+
this.dispatcher({
171+
type: T.SET_FILE_HANDLE,
172+
payload: { curGraphIndex: this.superState.curGraphIndex, fileHandle: handle },
173+
});
174+
const stream = await handle.createWritable();
175+
await stream.write(blob);
176+
await stream.close();
177+
toast.success('File saved Successfully');
178+
} catch (error) {
179+
if (error.name !== 'AbortError') {
180+
console.error(error);
181+
}
182+
}
170183
}
171184

172185
saveToFolder() {

0 commit comments

Comments
 (0)