diff --git a/src/App.svelte b/src/App.svelte index 7ad7dddf3..bd6c73517 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 fa9255f7e..c5de7e3fa 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 deaa1a82a..ac23ece8d 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 381cc521b..baff4e23b 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 f33770a60..13142a681 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); - });