Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODLISTS-186: Stream export file during download
Browse files Browse the repository at this point in the history
UladzislauKutarkin committed Jan 21, 2025
1 parent 43d473e commit 5997896
Showing 2 changed files with 3 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/hooks/useCSVListExport/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const POLLING_DELAY = 3_000;
export const REQUEST_TIMEOUT = 30000;
17 changes: 3 additions & 14 deletions src/hooks/useCSVListExport/useCSVExportPolling.tsx
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { ListExport } from '../../interfaces';
import { useMessages } from '../useMessages';
import { t } from '../../services';
import { downloadCSV } from './downloadCSV';
import { POLLING_DELAY, REQUEST_TIMEOUT } from './constants';
import { POLLING_DELAY } from './constants';
import { isSuccess, isFailed, isCancelled } from './helpers';

export const useCSVExportPolling = (listName: string, clearStorage: () => void) => {
@@ -13,15 +13,8 @@ export const useCSVExportPolling = (listName: string, clearStorage: () => void)
const poll = (listID: string, exportId: string) => {
setTimeout(() => {
(async () => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT);

try {
const { listId, status }: ListExport = await ky
.get(`lists/${listID}/exports/${exportId}`, { signal: controller.signal })
.json();

clearTimeout(timeoutId);
const { listId, status }: ListExport = await ky.get(`lists/${listID}/exports/${exportId}`).json();

if (isFailed(status)) {
showErrorMessage({
@@ -60,18 +53,14 @@ export const useCSVExportPolling = (listName: string, clearStorage: () => void)
poll(listId, exportId);
}
} catch (error: any) {
clearTimeout(timeoutId);

if (error.name === 'AbortError') {
if (error.name === 'TimeoutError') {
poll(listID, exportId);
} else {
showErrorMessage({
message: t('callout.list.csv-export.error', {
listName,
}),
});

clearStorage();
}
}
})();

0 comments on commit 5997896

Please sign in to comment.