Skip to content

Commit

Permalink
Refactor download-svg.business.ts and index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
brauliodiez committed Jan 18, 2024
1 parent d08a371 commit 2dcf431
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
18 changes: 18 additions & 0 deletions src/common/export/classic-download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const initiateDownload = (url: string, name: string) => {
const link = document.createElement('a');
link.href = url;
link.download = name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};

export const downloadFile = (
filename: string,
content: string,
contentType: string
) => {
const blob = new Blob([content], { type: contentType });
const contentUrl = URL.createObjectURL(blob);
initiateDownload(contentUrl, filename);
};
20 changes: 1 addition & 19 deletions src/common/export/download-svg.business.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import ReactDOMServer from 'react-dom/server';
import { Size } from '@/core/model';

const initiateDownload = (url: string, name: string) => {
const link = document.createElement('a');
link.href = url;
link.download = name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};

export const downloadFile = (
filename: string,
content: string,
contentType: string
) => {
const blob = new Blob([content], { type: contentType });
const svgUrl = URL.createObjectURL(blob);
initiateDownload(svgUrl, filename);
};
import { downloadFile, initiateDownload } from './classic-download';

export const downloadSvg = (svg: JSX.Element) => {
const svgString = ReactDOMServer.renderToStaticMarkup(svg);
Expand Down
1 change: 1 addition & 0 deletions src/common/export/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './download-svg.business';
export * from './save-file-modern';
export * from './classic-download';

0 comments on commit 2dcf431

Please sign in to comment.