Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/component/fileBrowser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@ const LocalFileBrowser = ({ superState, dispatcher }) => {
multiple: false,
};

const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
const fileObj = await fileHandle.getFile();
readFile(superState, dispatcher, fileObj, fileHandle);
try {
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
const fileObj = await fileHandle.getFile();
readFile(superState, dispatcher, fileObj, fileHandle);
} catch (error) {
if (error.name !== 'AbortError') {
console.error(error);
}
}
};

return (
Expand Down
34 changes: 20 additions & 14 deletions src/component/modals/FileEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,26 @@ const FileEditModal = ({ superState, dispatcher }) => {
}

async function saveAsSubmit() {
const handle = await window.showSaveFilePicker();
const stream = await handle.createWritable();
await stream.write(codeStuff);
await stream.close();
const fileData = await handle.getFile();
let fS = superState.fileState;
fS = fS.concat([{
key: `${superState.uploadedDirName}/${handle.name}`,
modified: fileData.lastModified,
size: fileData.size,
fileObj: fileData,
fileHandle: handle,
}]);
dispatcher({ type: T.SET_FILE_STATE, payload: fS });
try {
const handle = await window.showSaveFilePicker();
const stream = await handle.createWritable();
await stream.write(codeStuff);
await stream.close();
const fileData = await handle.getFile();
let fS = superState.fileState;
fS = fS.concat([{
key: `${superState.uploadedDirName}/${handle.name}`,
modified: fileData.lastModified,
size: fileData.size,
fileObj: fileData,
fileHandle: handle,
}]);
dispatcher({ type: T.SET_FILE_STATE, payload: fS });
} catch (error) {
if (error.name !== 'AbortError') {
console.error(error);
}
}
}

function handleSaveAsClick() {
Expand Down
61 changes: 37 additions & 24 deletions src/graph-builder/graph-core/5-load-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,33 @@ class GraphLoadSave extends GraphUndoRedo {
},
],
};
const handle = await window.showSaveFilePicker(options);
const stream = await handle.createWritable();
await stream.write(blob);
await stream.close();
const fileData = await handle.getFile();
let fS = this.superState.fileState;
fS = fS.concat([{
key: `${this.superState.uploadedDirName}/${handle.name}`,
modified: fileData.lastModified,
size: fileData.size,
fileObj: fileData,
fileHandle: handle,
}]);
this.dispatcher({ type: T.SET_FILE_STATE, payload: fS });
try {
const handle = await window.showSaveFilePicker(options);
const stream = await handle.createWritable();
await stream.write(blob);
await stream.close();
const fileData = await handle.getFile();
let fS = this.superState.fileState;
fS = fS.concat([{
key: `${this.superState.uploadedDirName}/${handle.name}`,
modified: fileData.lastModified,
size: fileData.size,
fileObj: fileData,
fileHandle: handle,
}]);
this.dispatcher({ type: T.SET_FILE_STATE, payload: fS });
toast.success('File saved Successfully');
} catch (error) {
if (error.name !== 'AbortError') {
console.error(error);
}
}
} else {
// eslint-disable-next-line no-alert
const fileName = prompt('Filename:');
saveAs(blob, `${fileName || `${this.getName()}-concore`}.graphml`);
toast.success('File saved Successfully');
}
toast.success('File saved Successfully');
}

async saveWithoutFileHandle() {
Expand All @@ -158,15 +165,21 @@ class GraphLoadSave extends GraphUndoRedo {
},
],
};
const handle = await window.showSaveFilePicker(options);
this.dispatcher({
type: T.SET_FILE_HANDLE,
payload: { curGraphIndex: this.superState.curGraphIndex, fileHandle: handle },
});
const stream = await handle.createWritable();
await stream.write(blob);
await stream.close();
toast.success('File saved Successfully');
try {
const handle = await window.showSaveFilePicker(options);
this.dispatcher({
type: T.SET_FILE_HANDLE,
payload: { curGraphIndex: this.superState.curGraphIndex, fileHandle: handle },
});
const stream = await handle.createWritable();
await stream.write(blob);
await stream.close();
toast.success('File saved Successfully');
} catch (error) {
if (error.name !== 'AbortError') {
console.error(error);
}
}
}

saveToFolder() {
Expand Down