From f09253f6312048dcd7e5841808fe3e0dbed25934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Mon, 9 Sep 2024 17:22:08 +0200 Subject: [PATCH] Add repo issues and patches routes --- src/App.svelte | 6 ++ src/components/RepoCard.svelte | 7 +- src/lib/router.ts | 17 +++-- src/lib/router/definitions.ts | 18 +++++- src/views/Home.svelte | 28 ++++---- src/views/repo/Issues.svelte | 20 ++++++ src/views/repo/Layout.svelte | 38 +++++++++++ src/views/repo/Patches.svelte | 20 ++++++ src/views/repo/router.ts | 114 +++++++++++++++++++++++++++++++++ 9 files changed, 243 insertions(+), 25 deletions(-) create mode 100644 src/views/repo/Issues.svelte create mode 100644 src/views/repo/Layout.svelte create mode 100644 src/views/repo/Patches.svelte create mode 100644 src/views/repo/router.ts diff --git a/src/App.svelte b/src/App.svelte index 7ad7ddd..bd6c735 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -9,6 +9,8 @@ import AuthenticationError from "@app/views/AuthenticationError.svelte"; import Home from "@app/views/Home.svelte"; + import Issues from "@app/views/repo/Issues.svelte"; + import Patches from "@app/views/repo/Patches.svelte"; const activeRouteStore = router.activeRouteStore; @@ -40,6 +42,10 @@ {:else if $activeRouteStore.resource === "home"} +{:else if $activeRouteStore.resource === "repo.issues"} + +{:else if $activeRouteStore.resource === "repo.patches"} + {:else if $activeRouteStore.resource === "authenticationError"} {:else} diff --git a/src/components/RepoCard.svelte b/src/components/RepoCard.svelte index fa9255f..c5de7e3 100644 --- a/src/components/RepoCard.svelte +++ b/src/components/RepoCard.svelte @@ -31,7 +31,12 @@ } - +
diff --git a/src/lib/router.ts b/src/lib/router.ts index deaa1a8..ac23ece 100644 --- a/src/lib/router.ts +++ b/src/lib/router.ts @@ -5,6 +5,7 @@ import { get, writable } from "svelte/store"; import * as mutexExecutor from "@app/lib/mutexExecutor"; import * as utils from "@app/lib/utils"; import { loadRoute } from "@app/lib/router/definitions"; +import { repoRouteToPath, repoUrlToRoute } from "@app/views/repo/router"; export { type Route }; @@ -45,10 +46,8 @@ async function navigateToUrl( if (route) { await navigate(action, route); } else { - await navigate(action, { - // On 404 we redirect to the Home page, shouldn't happen. - resource: "home", - }); + console.error("Could not resolve route for URL: ", url); + await navigate(action, { resource: "home" }); } } @@ -95,12 +94,15 @@ export async function replace(newRoute: Route): Promise { function urlToRoute(url: URL): Route | null { const segments = url.pathname.substring(1).split("/"); - const resource = segments.shift(); + switch (resource) { case "": { return { resource: "home" }; } + case "repos": { + return repoUrlToRoute(segments, url.searchParams); + } case "authenticationError": { return { resource: "authenticationError", params: { error: "" } }; } @@ -115,6 +117,11 @@ export function routeToPath(route: Route): string { return "/"; } else if (route.resource === "authenticationError") { return "/authenticationError"; + } else if ( + route.resource === "repo.issues" || + route.resource === "repo.patches" + ) { + return repoRouteToPath(route); } else if (route.resource === "booting") { return ""; } else { diff --git a/src/lib/router/definitions.ts b/src/lib/router/definitions.ts index 381cc52..baff4e2 100644 --- a/src/lib/router/definitions.ts +++ b/src/lib/router/definitions.ts @@ -1,8 +1,11 @@ -import type { RepoInfo } from "@bindings/RepoInfo"; import type { Config } from "@bindings/Config"; +import type { RepoInfo } from "@bindings/RepoInfo"; +import type { LoadedRepoRoute, RepoRoute } from "@app/views/repo/router"; import { invoke } from "@tauri-apps/api/core"; +import { loadIssues, loadPatches } from "@app/views/repo/router"; + interface BootingRoute { resource: "booting"; } @@ -24,12 +27,17 @@ interface LoadedHomeRoute { params: { repos: RepoInfo[]; config: Config }; } -export type Route = BootingRoute | HomeRoute | AuthenticationErrorRoute; +export type Route = + | AuthenticationErrorRoute + | BootingRoute + | HomeRoute + | RepoRoute; export type LoadedRoute = + | AuthenticationErrorRoute | BootingRoute | LoadedHomeRoute - | AuthenticationErrorRoute; + | LoadedRepoRoute; export async function loadRoute( route: Route, @@ -39,6 +47,10 @@ export async function loadRoute( const repos: RepoInfo[] = await invoke("list_repos"); const config: Config = await invoke("config"); return { resource: "home", params: { repos, config } }; + } else if (route.resource === "repo.issues") { + return loadIssues(route); + } else if (route.resource === "repo.patches") { + return loadPatches(route); } return route; } diff --git a/src/views/Home.svelte b/src/views/Home.svelte index f33770a..13142a6 100644 --- a/src/views/Home.svelte +++ b/src/views/Home.svelte @@ -2,26 +2,13 @@ import type { Config } from "@bindings/Config"; import type { RepoInfo } from "@bindings/RepoInfo"; + import * as router from "@app/lib/router"; + import Header from "@app/components/Header.svelte"; import RepoCard from "@app/components/RepoCard.svelte"; - import { onMount } from "svelte"; - import { invoke } from "@tauri-apps/api/core"; export let repos: RepoInfo[]; export let config: Config; - - onMount(async () => { - const patches = await invoke("list_patches", { - rid: "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5", - status: "open", - }); - const issues = await invoke("list_issues", { - rid: "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5", - status: "open", - }); - - console.log(patches, issues); - });