Skip to content

Commit edc9770

Browse files
committed
feat: add loading notifcation and waitTime promise to exportRecords
1 parent 81d97e8 commit edc9770

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

apps/web/src/routes/_app/datahub/index.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { PageHeader } from '@/components/PageHeader';
1717
import { subjectsQueryOptions, useSubjectsQuery } from '@/hooks/useSubjectsQuery';
1818
import { useAppStore } from '@/store';
1919
import { downloadExcel } from '@/utils/excel';
20+
import { promise } from 'zod';
2021

2122
type MasterDataTableProps = {
2223
data: Subject[];
@@ -60,6 +61,17 @@ const Toggles: React.FC<{ table: TanstackTable.Table<Subject> }> = ({ table }) =
6061

6162
const handleExportSelection = (option: 'CSV' | 'Excel' | 'JSON') => {
6263
const baseFilename = `${currentUser!.username}_${new Date().toISOString()}`;
64+
addNotification({
65+
message: t({
66+
en: 'Exporting entries, please wait...',
67+
fr: 'Téléchargement des entrées, veuillez patienter...'
68+
}),
69+
type: 'info'
70+
});
71+
const waitTime = new Promise((resolve) => {
72+
setTimeout(resolve, 350);
73+
});
74+
6375
getExportRecords()
6476
.then((data): any => {
6577
const listedSubjects = table
@@ -74,14 +86,6 @@ const Toggles: React.FC<{ table: TanstackTable.Table<Subject> }> = ({ table }) =
7486
);
7587
}
7688

77-
addNotification({
78-
message: t({
79-
en: 'Exporting entries, please wait...',
80-
fr: 'Téléchargement des entrées, veuillez patienter...'
81-
}),
82-
type: 'info'
83-
});
84-
8589
switch (option) {
8690
case 'CSV':
8791
void download('README.txt', t('datahub.index.table.exportHelpText'));
@@ -93,6 +97,9 @@ const Toggles: React.FC<{ table: TanstackTable.Table<Subject> }> = ({ table }) =
9397
return download(`${baseFilename}.json`, JSON.stringify(filteredData, null, 2));
9498
}
9599
})
100+
.then(() => {
101+
return waitTime;
102+
})
96103
.then(() => {
97104
addNotification({
98105
message: t({ en: 'Export successful', fr: 'Exportation réussie' }),

0 commit comments

Comments
 (0)