diff --git a/httpd-client/index.ts b/httpd-client/index.ts index 902b821bf..ae2e520ba 100644 --- a/httpd-client/index.ts +++ b/httpd-client/index.ts @@ -61,7 +61,7 @@ const nodeSchema = strictObject({ id: string(), }) satisfies ZodSchema; -export interface Root { +export interface NodeInfo { message: string; service: string; version: string; @@ -70,7 +70,7 @@ export interface Root { links: { href: string; rel: string; type: Method }[]; } -const rootSchema = strictObject({ +const nodeInfoSchema = strictObject({ message: string(), service: string(), version: string(), @@ -88,7 +88,7 @@ const rootSchema = strictObject({ ]), }), ), -}) satisfies ZodSchema; +}) satisfies ZodSchema; export interface NodeStats { projects: { count: number }; @@ -115,14 +115,14 @@ export class HttpdClient { this.session = new session.Client(this.#fetcher); } - public async getRoot(options?: RequestOptions): Promise { + public async getNodeInfo(options?: RequestOptions): Promise { return this.#fetcher.fetchOk( { method: "GET", path: "", options, }, - rootSchema, + nodeInfoSchema, ); } diff --git a/httpd-client/tests/client.test.ts b/httpd-client/tests/client.test.ts index 92071ba9a..3beff76d6 100644 --- a/httpd-client/tests/client.test.ts +++ b/httpd-client/tests/client.test.ts @@ -8,8 +8,8 @@ const api = new HttpdClient({ }); describe("client", () => { - test("#getRoot()", async () => { - await api.getRoot(); + test("#getNodeInfo()", async () => { + await api.getNodeInfo(); }); test("#getStats()", async () => { diff --git a/src/App.svelte b/src/App.svelte index e43a000c1..db8c0de14 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -6,18 +6,22 @@ import { unreachable } from "@app/lib/utils"; import Header from "./App/Header.svelte"; - import ModalPortal from "./App/ModalPortal.svelte"; import Hotkeys from "./App/Hotkeys.svelte"; + import LoadingBar from "./App/LoadingBar.svelte"; + import ModalPortal from "./App/ModalPortal.svelte"; - import NotFound from "@app/components/NotFound.svelte"; import Home from "@app/views/home/Index.svelte"; - import Session from "@app/views/session/Index.svelte"; import Projects from "@app/views/projects/View.svelte"; import Seeds from "@app/views/seeds/View.svelte"; + import Session from "@app/views/session/Index.svelte"; + + import LoadError from "@app/components/LoadError.svelte"; + import Loading from "@app/components/Loading.svelte"; + import NotFound from "@app/components/NotFound.svelte"; const activeRouteStore = router.activeRouteStore; - router.initialize(); + router.loadFromLocation(); session.initialize(); if (!window.VITEST && !window.PLAYWRIGHT && import.meta.env.PROD) { @@ -51,6 +55,10 @@ Radicle +{#if $activeRouteStore.resource !== "booting"} + +{/if} + @@ -58,16 +66,22 @@
{#if $activeRouteStore.resource === "home"} - + {:else if $activeRouteStore.resource === "seeds"} - + {:else if $activeRouteStore.resource === "session"} {:else if $activeRouteStore.resource === "projects"} - {:else if $activeRouteStore.resource === "404"} + {:else if $activeRouteStore.resource === "booting"} + + {:else if $activeRouteStore.resource === "loadError"} + + {:else if $activeRouteStore.resource === "notFound"}
- +
{:else} {unreachable($activeRouteStore)} diff --git a/src/App/Header/Search.svelte b/src/App/Header/Search.svelte index 6b8d0d04b..46fbe1aba 100644 --- a/src/App/Header/Search.svelte +++ b/src/App/Header/Search.svelte @@ -23,7 +23,7 @@ let expanded = false; // Clears search input on user navigation. - router.historyStore.subscribe(() => (input = "")); + router.activeRouteStore.subscribe(() => (input = "")); function shake() { shaking = true; diff --git a/src/App/Header/SearchResultsModal.svelte b/src/App/Header/SearchResultsModal.svelte index 62fd40b07..f058e0d13 100644 --- a/src/App/Header/SearchResultsModal.svelte +++ b/src/App/Header/SearchResultsModal.svelte @@ -1,5 +1,5 @@ + +
diff --git a/src/components/LoadError.svelte b/src/components/LoadError.svelte new file mode 100644 index 000000000..45d868dad --- /dev/null +++ b/src/components/LoadError.svelte @@ -0,0 +1,36 @@ + + + + +
+
🏜️
+ {#if title} +
+ {title} +
+ {/if} + +
+ +
+
diff --git a/src/components/Markdown.svelte b/src/components/Markdown.svelte index 826288d9e..826950184 100644 --- a/src/components/Markdown.svelte +++ b/src/components/Markdown.svelte @@ -6,13 +6,14 @@ import { toDom } from "hast-util-to-dom"; import * as utils from "@app/lib/utils"; - import { base, updateProjectRoute, activeRouteStore } from "@app/lib/router"; - import { isUrl, twemoji, scrollIntoView, canonicalize } from "@app/lib/utils"; + import { base, activeRouteStore } from "@app/lib/router"; import { highlight } from "@app/lib/syntax"; + import { isUrl, twemoji, scrollIntoView, canonicalize } from "@app/lib/utils"; import { markdownExtensions as extensions, renderer, } from "@app/lib/markdown"; + import { updateProjectRoute } from "@app/views/projects/router"; export let content: string; export let hash: string | null = null; diff --git a/src/components/NotFound.svelte b/src/components/NotFound.svelte index 4a62e7f48..bf63aac38 100644 --- a/src/components/NotFound.svelte +++ b/src/components/NotFound.svelte @@ -1,5 +1,4 @@ - {hostName} + {hostname}
- {hostName} + {hostname}
- {#await api.getRoot()} - - {:then nodeInfo} - - - - - - - - - -
Address -
- {truncateId(nodeInfo.node.id)}@{baseUrl.hostname} - -
-
Version - {nodeInfo.version} -
- {:catch error} -
- -
- {/await} + + + + + + + + + +
Address +
+ {truncateId(nid)}@{baseUrl.hostname} + +
+
Version + {version} +
- {#if projects} -
- {#each projectsWithActivity as { project, activity }} -
- - - -
- {/each} +
+ {#each projects as { project, activity }} +
+ + + +
+ {/each} +
+ {#if loadingProjects} +
+ +
+ {/if} + {#if showMoreButton} +
+
- {#if loadingProjects} -
- -
- {/if} - {#if showMoreButton} -
- -
- {/if} {/if} {#if error} {/if}
diff --git a/src/views/seeds/router.ts b/src/views/seeds/router.ts new file mode 100644 index 000000000..d25cc1605 --- /dev/null +++ b/src/views/seeds/router.ts @@ -0,0 +1,100 @@ +import type { BaseUrl, Project } from "@httpd-client"; +import type { LoadError } from "@app/lib/router/definitions"; +import type { WeeklyActivity } from "@app/lib/commit"; + +import { HttpdClient } from "@httpd-client"; +import { extractBaseUrl } from "@app/lib/utils"; +import { loadProjectActivity } from "@app/lib/commit"; + +interface SeedsRouteParams { + hostnamePort: string; + projectPageIndex: number; +} + +export interface ProjectActivity { + project: Project; + activity: WeeklyActivity[]; +} + +export interface SeedsRoute { + resource: "seeds"; + params: SeedsRouteParams; +} + +export interface SeedsLoadedRoute { + resource: "seeds"; + params: { + baseUrl: BaseUrl; + projectPageIndex: number; + version: string; + nid: string; + projects: ProjectActivity[]; + projectCount: number; + }; +} + +const PROJECTS_PER_PAGE = 10; + +export async function loadProjects( + page: number, + baseUrl: BaseUrl, +): Promise<{ + total: number; + projects: ProjectActivity[]; +}> { + const api = new HttpdClient(baseUrl); + + const [nodeStats, projects] = await Promise.all([ + api.getStats(), + api.project.getAll({ page, perPage: PROJECTS_PER_PAGE }), + ]); + + const results = await Promise.all( + projects.map(async project => { + const activity = await loadProjectActivity(project.id, baseUrl); + return { + project, + activity, + }; + }), + ); + + return { + total: nodeStats.projects.count, + projects: results, + }; +} + +export async function loadSeedRoute( + params: SeedsRouteParams, +): Promise { + const baseUrl = extractBaseUrl(params.hostnamePort); + const api = new HttpdClient(baseUrl); + try { + const projectPageIndex = 0; + const [nodeInfo, { projects, total }] = await Promise.all([ + api.getNodeInfo(), + loadProjects(projectPageIndex, baseUrl), + ]); + return { + resource: "seeds", + params: { + projectPageIndex: projectPageIndex + 1, + baseUrl, + nid: nodeInfo.node.id, + version: nodeInfo.version, + projects: projects, + projectCount: total, + }, + }; + } catch (error: any) { + return { + resource: "loadError", + params: { + title: params.hostnamePort, + errorMessage: "Not able to query this seed.", + stackTrace: error.stack, + }, + }; + } +} diff --git a/src/views/session/Index.svelte b/src/views/session/Index.svelte index b3b949e58..ebeddc702 100644 --- a/src/views/session/Index.svelte +++ b/src/views/session/Index.svelte @@ -20,7 +20,7 @@ modal.show({ component: AuthenticatedModal, props: {} }); router.push({ resource: "seeds", - params: { hostnamePort: "radicle.local" }, + params: { hostnamePort: "radicle.local", projectPageIndex: 0 }, }); } else { modal.show({ diff --git a/tests/support/router.ts b/tests/support/router.ts index fe0101c28..a1eaf85a4 100644 --- a/tests/support/router.ts +++ b/tests/support/router.ts @@ -14,8 +14,16 @@ export const expectBackAndForwardNavigationWorks = async ( page: Page, ) => { const currentURL = page.url(); + await page.goBack(); + await page + .locator("role=progressbar[name='Page loading']") + .waitFor({ state: "hidden" }); await expect(page).toHaveURL(beforeURL); await page.goForward(); + + await page + .locator("role=progressbar[name='Page loading']") + .waitFor({ state: "hidden" }); await expect(page).toHaveURL(currentURL); }; diff --git a/tests/unit/router.test.ts b/tests/unit/router.test.ts index 0500a86a4..82013593c 100644 --- a/tests/unit/router.test.ts +++ b/tests/unit/router.test.ts @@ -35,18 +35,18 @@ describe("routeToPath", () => { describe("pathToRoute", () => { test.each([ - { input: "", output: null, description: "Empty 404 Route" }, + { input: "", output: null, description: "Empty not found Route" }, { input: "/foo/baz/bar", output: null, - description: "Non existant 404 Route", + description: "Non existant not found route", }, { input: "/", output: { resource: "home" }, description: "Home Route" }, { input: "/seeds/willow.radicle.garden", output: { resource: "seeds", - params: { hostnamePort: "willow.radicle.garden" }, + params: { hostnamePort: "willow.radicle.garden", projectPageIndex: 0 }, }, description: "Seed View Route", },