Skip to content

Commit

Permalink
Refactor deprecated blob download code
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Jan 20, 2025
1 parent ef70d7b commit 259b1e6
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,18 @@ const Navbar = ({
const questionnaire = generateQuestionnaire(state);
const filename = `${getFileName()}.${fileExtension}`;
const contentType = 'application/json;charset=utf-8;';

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
const blob = new Blob([decodeURIComponent(encodeURI(questionnaire))], {
type: contentType,
});
navigator.msSaveOrOpenBlob(blob, filename);
} else {
const a = document.createElement('a');
a.download = filename;
a.href = 'data:' + contentType + ',' + encodeURIComponent(questionnaire);
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}

const blob = new Blob([questionnaire], { type: contentType });
const url = URL.createObjectURL(blob);

const a = document.createElement('a');
a.download = filename;
a.href = url;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);

dispatch(saveAction());
}

Expand Down

0 comments on commit 259b1e6

Please sign in to comment.