Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- suffix '.edt' only gets attached to the saved file name when changes were made (change/deletion of a file)
  • Loading branch information
siri_yu committed Jun 6, 2024
1 parent 566d7ce commit f69cd2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/FileExplorer/FileExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default function FileExplorer({ handleFileItemClick }) {
backgroundColor: 'darkblue',
}
}}
onClick={() => downloadFiles(fileDataset)}
onClick={() => downloadFiles(fileDataset, sessionData)}
>
Save all files
</SaveButton>
Expand Down
9 changes: 6 additions & 3 deletions src/components/FileExplorer/FileExplorerFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function downloadFile(fileData, sessionData) {
blob = new Blob([JSON.stringify(fileData, null, 4)], { type: 'application/json' }),
url = window.URL.createObjectURL(blob),
a = document.createElement('a');

a.href = url;
a.download = `file_${fileData.key ?? 'unregistered'}${sessionData?.changedFiles?.includes(fileData.key) ? '.edt' : ''}.json`;
document.body.appendChild(a);
Expand All @@ -101,12 +102,14 @@ export function downloadFile(fileData, sessionData) {
* @param {JSON} sessionData
*/
export function downloadFiles(fileDataset, sessionData) {
let
blob = new Blob([JSON.stringify(fileDataset.filter(file => file), null, 4)], { type: 'application/json' }),
let
newFileDataset = fileDataset.filter(file => file),
blob = new Blob([JSON.stringify(newFileDataset, null, 4)], { type: 'application/json' }),
url = window.URL.createObjectURL(blob),
a = document.createElement('a');

a.href = url;
a.download = `files${sessionData?.changedFiles?.length ? '.edt' : ''}.json`;
a.download = `files${newFileDataset.length !== fileDataset.length || sessionData?.changedFiles ? '.edt' : ''}.json`;
document.body.appendChild(a);
a.click();
a.remove();
Expand Down

0 comments on commit f69cd2a

Please sign in to comment.