kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
utils/download: take a string instead of AxiosResponse
rodzic
69a9748b3d
commit
b15871aaa8
|
@ -21,22 +21,22 @@ const Dashboard: React.FC = () => {
|
||||||
const account = useOwnAccount();
|
const account = useOwnAccount();
|
||||||
|
|
||||||
const handleSubscribersClick: React.MouseEventHandler = e => {
|
const handleSubscribersClick: React.MouseEventHandler = e => {
|
||||||
dispatch(getSubscribersCsv()).then((response) => {
|
dispatch(getSubscribersCsv()).then(({ data }) => {
|
||||||
download(response, 'subscribers.csv');
|
download(data, 'subscribers.csv');
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUnsubscribersClick: React.MouseEventHandler = e => {
|
const handleUnsubscribersClick: React.MouseEventHandler = e => {
|
||||||
dispatch(getUnsubscribersCsv()).then((response) => {
|
dispatch(getUnsubscribersCsv()).then(({ data }) => {
|
||||||
download(response, 'unsubscribers.csv');
|
download(data, 'unsubscribers.csv');
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCombinedClick: React.MouseEventHandler = e => {
|
const handleCombinedClick: React.MouseEventHandler = e => {
|
||||||
dispatch(getCombinedCsv()).then((response) => {
|
dispatch(getCombinedCsv()).then(({ data }) => {
|
||||||
download(response, 'combined.csv');
|
download(data, 'combined.csv');
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
|
@ -102,8 +102,8 @@ const EventHeader: React.FC<IEventHeader> = ({ status }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleExportClick = () => {
|
const handleExportClick = () => {
|
||||||
dispatch(fetchEventIcs(status.id)).then((response) => {
|
dispatch(fetchEventIcs(status.id)).then(({ data }) => {
|
||||||
download(response, 'calendar.ics');
|
download(data, 'calendar.ics');
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import type { AxiosResponse } from 'axios';
|
|
||||||
|
|
||||||
/** Download the file from the response instead of opening it in a tab. */
|
/** Download the file from the response instead of opening it in a tab. */
|
||||||
// https://stackoverflow.com/a/53230807
|
// https://stackoverflow.com/a/53230807
|
||||||
export const download = (response: AxiosResponse, filename: string) => {
|
export const download = (data: string, filename: string): void => {
|
||||||
const url = URL.createObjectURL(new Blob([response.data]));
|
const url = URL.createObjectURL(new Blob([data]));
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.setAttribute('download', filename);
|
link.setAttribute('download', filename);
|
||||||
|
|
Ładowanie…
Reference in New Issue