diff --git a/src/Profile.svelte b/src/Profile.svelte index 85130764d..16a90059f 100644 --- a/src/Profile.svelte +++ b/src/Profile.svelte @@ -20,6 +20,7 @@ import { MissingReverseRecord, NotFoundError } from "@app/error"; import NotFound from "@app/NotFound.svelte"; import RadicleUrn from "@app/RadicleUrn.svelte"; + import Async from "@app/Async.svelte"; import Badge from "@app/Badge.svelte"; import Button from "@app/Button.svelte"; @@ -446,7 +447,14 @@ {/await} {/if} {#if profile.seed?.valid} - + + + {/if} diff --git a/src/base/orgs/View/Projects.svelte b/src/base/orgs/View/Projects.svelte index 5e24140c5..961433ee6 100644 --- a/src/base/orgs/View/Projects.svelte +++ b/src/base/orgs/View/Projects.svelte @@ -3,21 +3,23 @@ import { onMount } from "svelte"; import type { Config } from "@app/config"; import * as proj from "@app/project"; - import Loading from "@app/Loading.svelte"; - import Message from "@app/Message.svelte"; import Widget from "@app/base/projects/Widget.svelte"; import type { Profile } from "@app/profile"; import type { ProjectInfo, Anchor, PendingAnchor } from "@app/project"; import type { Seed } from "@app/base/seeds/Seed"; import AnchorActions from "@app/base/profiles/AnchorActions.svelte"; + import List from "@app/List.svelte"; export let seed: Seed; export let profile: Profile | null = null; export let account: string | null = null; + export let projects: proj.ProjectInfo[]; export let config: Config; let anchors: Record = {}; let pendingAnchors: Record = {}; + // A pointer to the current page of projects added to the listing + let page = 0; const loadAnchors = async () => { if (profile) { @@ -31,6 +33,19 @@ } }; + const fetchMoreProjects = async (): Promise => { + const projects = await proj.Project.getProjects(seed.api, { + perPage: 10, + page: (page += 1), + }); + if (projects.length > 0) { + return projects; + } + + // We return an empty array, for when no more projects are found, since List is looking for an iterable. + return []; + }; + const onClick = (project: ProjectInfo) => { navigate( proj.path({ @@ -59,36 +74,31 @@
- {#await seed.getProjects(profile?.id)} - - {:then projects} - {#each projects as project} - {@const anchor = anchors[project.urn]} - {@const pendingAnchor = pendingAnchors[project.urn]} - {#if project.head} -
- onClick(project)}> - - {#if profile?.org?.safe && account && anchor} - {#if pendingAnchor} - - loadAnchors()} /> + + + {#each items as project} + {@const anchor = anchors[project.urn]} + {@const pendingAnchor = pendingAnchors[project.urn]} + {#if project.head} +
+ onClick(project)}> + + {#if profile?.org?.safe && account && anchor} + {#if pendingAnchor} + + loadAnchors()} /> + {/if} {/if} - {/if} - - -
- {/if} - {/each} - {:catch err} - - Error: - failed to load projects: {err.message}. - - {/await} +
+
+
+ {/if} + {/each} + +
diff --git a/src/base/seeds/Seed.ts b/src/base/seeds/Seed.ts index 31fb440cd..9c1feab6f 100644 --- a/src/base/seeds/Seed.ts +++ b/src/base/seeds/Seed.ts @@ -105,10 +105,10 @@ export class Seed { return proj.Project.getInfo(urn, this.api); } - async getProjects(id?: string): Promise { + async getProjects(perPage: number, id?: string): Promise { const result = id - ? await proj.Project.getDelegateProjects(id, this.api) - : await proj.Project.getProjects(this.api); + ? await proj.Project.getDelegateProjects(id, this.api, { perPage }) + : await proj.Project.getProjects(this.api, { perPage }); return result.map((project: proj.ProjectInfo) => ({ ...project, diff --git a/src/base/seeds/View.svelte b/src/base/seeds/View.svelte index a96dad92e..e7721b0b5 100644 --- a/src/base/seeds/View.svelte +++ b/src/base/seeds/View.svelte @@ -11,12 +11,16 @@ import Address from "@app/Address.svelte"; import SiweConnect from "@app/SiweConnect.svelte"; import type { SeedSession } from "@app/siwe"; + import Async from "@app/Async.svelte"; + import { Project } from "@app/project"; + import type { Host } from "@app/api"; export let config: Config; export let session: Session | null; export let host: string; const hostName = formatSeedHost(host); + const seedHost: Host = { host, port: null }; let siweSession: SeedSession | null = null; $: if (session?.siwe) { @@ -153,7 +157,9 @@
- + + + {:catch} { - return new Request("projects", host).get(); + static async getProjects( + host: Host, + opts?: { + perPage?: number; + page?: number; + }, + ): Promise { + const params: Record = { + "per-page": opts?.perPage, + page: opts?.page, + }; + return new Request("projects", host).get(params); } static async getDelegateProjects( delegate: string, host: Host, + opts?: { + perPage?: number; + page?: number; + }, ): Promise { - return new Request(`delegates/${delegate}/projects`, host).get(); + const params: Record = { + "per-page": opts?.perPage, + page: opts?.page, + }; + return new Request(`delegates/${delegate}/projects`, host).get(params); } static async getRemote(