From b15871aaa814ba604ddc0e960f49cdce206e6d68 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 17 Dec 2022 20:15:03 -0600 Subject: [PATCH] utils/download: take a string instead of AxiosResponse --- app/soapbox/features/admin/tabs/dashboard.tsx | 12 ++++++------ .../features/event/components/event-header.tsx | 4 ++-- app/soapbox/utils/download.ts | 6 ++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/soapbox/features/admin/tabs/dashboard.tsx b/app/soapbox/features/admin/tabs/dashboard.tsx index dd0f9f1bd..aa127f5a1 100644 --- a/app/soapbox/features/admin/tabs/dashboard.tsx +++ b/app/soapbox/features/admin/tabs/dashboard.tsx @@ -21,22 +21,22 @@ const Dashboard: React.FC = () => { const account = useOwnAccount(); const handleSubscribersClick: React.MouseEventHandler = e => { - dispatch(getSubscribersCsv()).then((response) => { - download(response, 'subscribers.csv'); + dispatch(getSubscribersCsv()).then(({ data }) => { + download(data, 'subscribers.csv'); }).catch(() => {}); e.preventDefault(); }; const handleUnsubscribersClick: React.MouseEventHandler = e => { - dispatch(getUnsubscribersCsv()).then((response) => { - download(response, 'unsubscribers.csv'); + dispatch(getUnsubscribersCsv()).then(({ data }) => { + download(data, 'unsubscribers.csv'); }).catch(() => {}); e.preventDefault(); }; const handleCombinedClick: React.MouseEventHandler = e => { - dispatch(getCombinedCsv()).then((response) => { - download(response, 'combined.csv'); + dispatch(getCombinedCsv()).then(({ data }) => { + download(data, 'combined.csv'); }).catch(() => {}); e.preventDefault(); }; diff --git a/app/soapbox/features/event/components/event-header.tsx b/app/soapbox/features/event/components/event-header.tsx index adfb2dc32..5e0226e2c 100644 --- a/app/soapbox/features/event/components/event-header.tsx +++ b/app/soapbox/features/event/components/event-header.tsx @@ -102,8 +102,8 @@ const EventHeader: React.FC = ({ status }) => { }; const handleExportClick = () => { - dispatch(fetchEventIcs(status.id)).then((response) => { - download(response, 'calendar.ics'); + dispatch(fetchEventIcs(status.id)).then(({ data }) => { + download(data, 'calendar.ics'); }).catch(() => {}); }; diff --git a/app/soapbox/utils/download.ts b/app/soapbox/utils/download.ts index c877bee25..f756490c9 100644 --- a/app/soapbox/utils/download.ts +++ b/app/soapbox/utils/download.ts @@ -1,9 +1,7 @@ -import type { AxiosResponse } from 'axios'; - /** Download the file from the response instead of opening it in a tab. */ // https://stackoverflow.com/a/53230807 -export const download = (response: AxiosResponse, filename: string) => { - const url = URL.createObjectURL(new Blob([response.data])); +export const download = (data: string, filename: string): void => { + const url = URL.createObjectURL(new Blob([data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', filename);