Skip to content

Commit f2ca021

Browse files
committed
Separate organization project platforms
1 parent 1e23d57 commit f2ca021

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/routes/(console)/organization-[organization]/+page.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,7 @@
250250
offset={data.offset}
251251
on:click={handleCreateProject}>
252252
{#each data.projects.projects as project}
253-
{@const projectPlatforms =
254-
(project as Models.Project & { platforms: Array<{ type: string }> })
255-
.platforms ?? []}
253+
{@const projectPlatforms = data.platformsByProjectId[project.$id] ?? []}
256254
{@const platforms = filterPlatforms(
257255
projectPlatforms.map((platform) => getPlatformInfo(platform.type))
258256
)}

src/routes/(console)/organization-[organization]/+page.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { Query, type Models } from '@appwrite.io/console';
22
import { isCloud } from '$lib/system';
33
import { sdk } from '$lib/stores/sdk';
44
import { getLimit, getPage, getSearch, pageToOffset } from '$lib/helpers/load';
5+
import { listAllPages } from '$lib/helpers/pagination';
56
import { CARD_LIMIT, Dependencies } from '$lib/constants';
67
import type { PageLoad } from './$types';
78
import { redirect } from '@sveltejs/kit';
89
import { resolve } from '$app/paths';
910

11+
type Platform = Models.PlatformList['platforms'][number];
12+
1013
export const load: PageLoad = async ({ params, url, route, depends, parent }) => {
1114
const { scopes } = await parent();
1215
if (!scopes.includes('projects.read') && scopes.includes('billing.read')) {
@@ -43,18 +46,30 @@ export const load: PageLoad = async ({ params, url, route, depends, parent }) =>
4346
]
4447
});
4548

49+
const platformsByProjectId: Record<string, Platform[]> = {};
50+
51+
await Promise.all(
52+
activeProjects.projects.map(async (project) => {
53+
const projectSdk = sdk.forProject(project.region ?? 'default', project.$id).project;
54+
const platformList = await listAllPages(
55+
(queries) => projectSdk.listPlatforms({ queries }),
56+
'platforms'
57+
);
58+
59+
platformsByProjectId[project.$id] = platformList.platforms;
60+
})
61+
);
62+
4663
// set `default` if no region!
4764
for (const project of activeProjects.projects) {
4865
project.region ??= 'default';
49-
(project as Models.Project & { platforms: Array<{ type: string }> }).platforms = (
50-
await sdk.forProject(project.region, project.$id).project.listPlatforms()
51-
).platforms;
5266
}
5367

5468
return {
5569
limit,
5670
offset,
5771
search,
58-
projects: activeProjects
72+
projects: activeProjects,
73+
platformsByProjectId
5974
};
6075
};

0 commit comments

Comments
 (0)