File tree Expand file tree Collapse file tree
routes/(console)/project-[region]-[project] Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Query } from '@appwrite.io/console' ;
2+
3+ const PAGE_SIZE = 100 ;
4+
5+ type ListResponse < Key extends string , Item > = {
6+ total : number ;
7+ } & {
8+ [ Property in Key ] : Item [ ] ;
9+ } ;
10+
11+ export async function listAllPages <
12+ Key extends string ,
13+ Item ,
14+ Response extends ListResponse < Key , Item >
15+ > (
16+ listPage : ( queries : string [ ] ) => Promise < Response > ,
17+ itemKey : Key ,
18+ pageSize = PAGE_SIZE
19+ ) : Promise < Response > {
20+ const firstPage = await listPage ( [ Query . limit ( pageSize ) , Query . offset ( 0 ) ] ) ;
21+ const items = [ ...firstPage [ itemKey ] ] ;
22+
23+ for ( let offset = items . length ; offset < firstPage . total ; offset += pageSize ) {
24+ const nextPage = await listPage ( [ Query . limit ( pageSize ) , Query . offset ( offset ) ] ) ;
25+ const nextItems = nextPage [ itemKey ] ;
26+
27+ if ( nextItems . length === 0 ) break ;
28+
29+ items . push ( ...nextItems ) ;
30+ }
31+
32+ return {
33+ ...firstPage ,
34+ [ itemKey ] : items
35+ } as Response ;
36+ }
Original file line number Diff line number Diff line change 33 import { CardGrid } from ' $lib/components' ;
44 import Confirm from ' $lib/components/confirm.svelte' ;
55 import { InputPhone , InputOTP , Button } from ' $lib/elements/forms' ;
6+ import { listAllPages } from ' $lib/helpers/pagination' ;
67 import { sdk } from ' $lib/stores/sdk' ;
78 import { getChangePlanUrl } from ' $lib/stores/billing' ;
89 import { addNotification } from ' $lib/stores/notifications' ;
7778 if (savedNumbers .length === 0 ) {
7879 isLoadingMockNumbers = true ;
7980 }
80- const response = await sdk
81- .forProject (project .region , project .$id )
82- .project .listMockPhones ({});
81+ const projectSdk = sdk .forProject (project .region , project .$id ).project ;
82+ const response = await listAllPages (
83+ (queries ) => projectSdk .listMockPhones ({ queries }),
84+ ' mockNumbers'
85+ );
8386 savedNumbers = getMockNumberRows (response .mockNumbers ?? []);
8487 } catch (error ) {
8588 addNotification ({ type: ' error' , message: error .message });
Original file line number Diff line number Diff line change 11import { Dependencies } from '$lib/constants' ;
2+ import { listAllPages } from '$lib/helpers/pagination' ;
23import { sdk } from '$lib/stores/sdk' ;
34import type { PageLoad } from './$types' ;
45
56export const load : PageLoad = async ( { params, depends } ) => {
67 depends ( Dependencies . PROJECT ) ;
78
8- const platformList = await sdk . forProject ( params . region , params . project ) . project . listPlatforms ( ) ;
9+ const projectSdk = sdk . forProject ( params . region , params . project ) . project ;
10+ const platformList = await listAllPages (
11+ ( queries ) => projectSdk . listPlatforms ( { queries } ) ,
12+ 'platforms'
13+ ) ;
914
1015 return {
1116 platforms : platformList . platforms
Original file line number Diff line number Diff line change 11import { Dependencies } from '$lib/constants' ;
2+ import { listAllPages } from '$lib/helpers/pagination' ;
23import { sdk } from '$lib/stores/sdk' ;
34import type { PageLoad } from './$types' ;
45
56export const load : PageLoad = async ( { params, depends } ) => {
67 depends ( Dependencies . KEYS ) ;
8+ const projectSdk = sdk . forProject ( params . region , params . project ) . project ;
9+
710 return {
8- keys : await sdk . forProject ( params . region , params . project ) . project . listKeys ( )
11+ keys : await listAllPages ( ( queries ) => projectSdk . listKeys ( { queries } ) , 'keys' )
912 } ;
1013} ;
Original file line number Diff line number Diff line change 11import { Dependencies } from '$lib/constants' ;
2+ import { listAllPages } from '$lib/helpers/pagination' ;
23import { sdk } from '$lib/stores/sdk' ;
34import type { PageLoad } from './$types' ;
45
56export const load : PageLoad = async ( { params, depends } ) => {
67 depends ( Dependencies . PROJECT ) ;
8+ const projectSdk = sdk . forProject ( params . region , params . project ) . project ;
79
810 return {
9- platforms : await sdk . forProject ( params . region , params . project ) . project . listPlatforms ( )
11+ platforms : await listAllPages (
12+ ( queries ) => projectSdk . listPlatforms ( { queries } ) ,
13+ 'platforms'
14+ )
1015 } ;
1116} ;
You can’t perform that action at this time.
0 commit comments