Skip to content

Commit a9385fb

Browse files
committed
Simplify notification
1 parent b354f45 commit a9385fb

1 file changed

Lines changed: 9 additions & 51 deletions

File tree

src/lib/components/csvExportBox.svelte

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<script lang="ts">
22
import { onMount } from 'svelte';
3-
import { base } from '$app/paths';
43
import { page } from '$app/state';
54
import { realtime, sdk } from '$lib/stores/sdk';
6-
import { goto } from '$app/navigation';
75
import { getProjectId } from '$lib/helpers/project';
86
import { addNotification } from '$lib/stores/notifications';
97
import { Layout, Typography, Code } from '@appwrite.io/pink-svelte';
@@ -33,62 +31,27 @@
3331
window.open(downloadUrl, '_blank');
3432
}
3533
36-
async function showCompletionNotification(
37-
table: string,
38-
bucketId: string,
39-
downloadUrl: string,
40-
payload: Payload
41-
) {
42-
const isSuccess = payload.status === 'completed';
43-
const isError = !isSuccess && !!payload.errors;
44-
45-
if (!isSuccess && !isError) return;
46-
34+
async function showErrorNotification(payload: Payload) {
4735
let errorMessage = 'Export failed. Please try again.';
48-
if (isError && Array.isArray(payload.errors) && payload.errors.length > 0) {
49-
try {
50-
const parsed = JSON.parse(payload.errors[0]);
51-
errorMessage = parsed?.message || errorMessage;
52-
} catch {
53-
errorMessage = payload.errors[0] || errorMessage;
54-
}
36+
try {
37+
const parsed = JSON.parse(payload.errors[0]);
38+
errorMessage = parsed?.message || errorMessage;
39+
} catch {
40+
errorMessage = payload.errors[0] || errorMessage;
5541
}
5642
57-
const type = isSuccess ? 'success' : 'error';
58-
const message = isError ? errorMessage : `"${table}" has been exported`;
59-
const region = page.params.region;
60-
const project = page.params.project;
61-
6243
addNotification({
63-
type,
64-
message,
44+
type: 'error',
45+
message: errorMessage,
6546
isHtml: true,
6647
timeout: 10000,
67-
buttons: isSuccess
68-
? [
69-
{
70-
name: 'View bucket',
71-
method: () =>
72-
goto(
73-
`${base}/project-${region}-${project}/storage/bucket-${bucketId}`
74-
)
75-
},
76-
{
77-
name: 'Download',
78-
method: () => downloadExportedFile(downloadUrl)
79-
}
80-
]
81-
: undefined
8248
});
8349
}
8450
8551
async function updateOrAddItem(exportData: Payload | Models.Migration) {
8652
if (exportData.destination?.toLowerCase() !== 'csv') return;
8753
8854
const status = exportData.status;
89-
const resourceId = exportData.resourceId ?? '';
90-
const [_, tableId] = resourceId.split(':') ?? [];
91-
9255
const current = exportItems.get(exportData.$id);
9356
let tableName = current?.table;
9457
@@ -132,12 +95,7 @@
13295
}
13396
break;
13497
case 'failed':
135-
await showCompletionNotification(
136-
tableName ?? tableId,
137-
bucketId,
138-
downloadUrl,
139-
exportData
140-
);
98+
await showErrorNotification(exportData);
14199
break;
142100
}
143101
}

0 commit comments

Comments
 (0)