Skip to content

Commit

Permalink
zip file before download
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Mar 15, 2024
1 parent cd8a1fd commit 9eca166
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 30 deletions.
34 changes: 21 additions & 13 deletions components/datasets/DownloadDataset.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import { event } from '../../utils/ga';
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTrigger,
DialogTitle,
DialogTrigger,
} from 'components/_shared/Dialog';
import { Download } from 'lucide-react';
import { download_data } from 'utils/download_data';
import React from 'react';
import { toast } from 'sonner';
import { downloadAsBlob } from 'utils/download_data';
import { event } from '../../utils/ga';

export const DownloadDataset = ({ filters }: { filters?: string | string[] }) => {
const [modalIsOpen, setModalIsOpen] = React.useState(false);
Expand All @@ -27,21 +27,29 @@ export const DownloadDataset = ({ filters }: { filters?: string | string[] }) =>
duration: 60000,
});

const data = await fetch(`/api/datasets`, {
const res = await fetch(`/api/datasets`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ filters }),
}).then((res) => {
return res.json();
});
if (res.ok) {
downloadAsBlob(res);
toast.dismiss('fetching-data');
toast.success('Downloaded started successfully!', {
closeButton: true,
});
} else {
console.error('Failed to download file');

download_data(data.data);
toast.dismiss('fetching-data');
toast.success('Downloaded started successfully!', {
duration: 4000,
});
toast.dismiss('fetching-data');
toast.error('Failed to download file', {
closeButton: true,
});
}
} else {
toast.success('Downloaded started successfully!', {
duration: 4000,
closeButton: true,
});
window.open(
Expand Down
Loading

0 comments on commit 9eca166

Please sign in to comment.