Skip to content

Commit 9c8b88e

Browse files
authored
Merge pull request #2786 from appwrite/remove-hacky-pagination
2 parents b7e0284 + e8ff2a1 commit 9c8b88e

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/routes/(console)/organization-[organization]/billing/paymentHistory.svelte

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
IconExternalLink,
2929
IconRefresh
3030
} from '@appwrite.io/pink-icons-svelte';
31+
import { addNotification } from '$lib/stores/notifications';
3132
3233
let limit = $state(5);
3334
let offset = $state(0);
@@ -40,29 +41,24 @@
4041
const endpoint = getApiEndpoint();
4142
const hasPaymentError = $derived(invoiceList?.invoices.some((invoice) => invoice?.lastError));
4243
43-
/**
44-
* Special case handling for the first page!
45-
*
46-
* As per Damodar - `there is some logic to **hide current cycle invoice** in the endpoint`.
47-
*
48-
* Due to this, the first page always loads `limit - 1` invoices which is inconsistent!
49-
* Therefore, we load `limit + 1` to counter that so the returned invoices are consistent.
50-
*/
51-
onMount(() => request(true));
44+
onMount(loadInvoices);
5245
53-
async function request(patchQuery: boolean = false) {
46+
async function loadInvoices() {
5447
isLoadingInvoices = true;
55-
invoiceList = await sdk.forConsole.billing.listInvoices(page.params.organization, [
56-
Query.orderDesc('$createdAt'),
57-
58-
// first page extra must have an extra limit!
59-
Query.limit(patchQuery ? limit + 1 : limit),
60-
61-
// so an invoice isn't repeated on 2nd page!
62-
Query.offset(patchQuery ? offset : offset + 1)
63-
]);
64-
65-
isLoadingInvoices = false;
48+
try {
49+
invoiceList = await sdk.forConsole.billing.listInvoices(page.params.organization, [
50+
Query.orderDesc('$createdAt'),
51+
Query.limit(limit),
52+
Query.offset(offset)
53+
]);
54+
} catch (error) {
55+
addNotification({
56+
type: 'error',
57+
message: error.message
58+
});
59+
} finally {
60+
isLoadingInvoices = false;
61+
}
6662
}
6763
6864
function retryPayment(invoice: Invoice) {
@@ -73,7 +69,7 @@
7369
$effect(() => {
7470
if (page.url.searchParams.get('type') === 'validate-invoice') {
7571
window.history.replaceState({}, '', page.url.pathname);
76-
request();
72+
loadInvoices();
7773
}
7874
});
7975
@@ -197,7 +193,7 @@
197193
hidePages
198194
bind:offset
199195
total={invoiceList.total}
200-
on:change={() => request()} />
196+
on:change={loadInvoices} />
201197
</Layout.Stack>
202198
{/if}
203199
{:else}

0 commit comments

Comments
 (0)