Decouple project route types from loaded types

We remove the requirement that `LoadedSourceBrowsingView` needs to be
assignable to `ProjectParams["view"]`. This decouples `ProjectRoute` and
`ProjectLoadedRoute` and lets us modify them independently.

I did not use a common `routeParamsView` function because I prefer the
flexibility of being able to modify them independently while this area
of code changes a lot.

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
This commit is contained in:
Thomas Scholtes
2023-07-11 14:22:41 +02:00
committed by Rūdolfs Ošiņš
parent f09e3f6edf
commit 829532fe94
3 changed files with 53 additions and 8 deletions
+26 -2
View File
@@ -1,6 +1,9 @@
<script lang="ts">
import type { BaseUrl } from "@httpd-client";
import type { LoadedSourceBrowsingView } from "@app/views/projects/router";
import type {
LoadedSourceBrowsingView,
ProjectsParams,
} from "@app/views/projects/router";
import * as utils from "@app/lib/utils";
import { closeFocused } from "@app/components/Floating.svelte";
@@ -23,6 +26,27 @@
.map(b => ({ key: b, value: b, title: `Switch to ${b}`, badge: null }));
$: showSelector = branchList.length > 1;
$: selectedCommitShortId = utils.formatCommit(selectedCommitId);
function routeParamsView(
view: LoadedSourceBrowsingView,
): ProjectsParams["view"] {
if (view.resource === "tree") {
return {
resource: "tree",
};
} else if (view.resource === "history") {
return {
resource: "history",
};
} else if (view.resource === "commits") {
return {
resource: "commits",
commitId: view.commit.commit.id,
};
} else {
return utils.unreachable(view);
}
}
</script>
<style>
@@ -88,7 +112,7 @@
baseUrl,
peer,
revision: item.value,
view,
view: routeParamsView(view),
},
}}
on:afterNavigate={() => closeFocused()}>
+27 -3
View File
@@ -1,9 +1,12 @@
<script lang="ts">
import type { BaseUrl, Remote } from "@httpd-client";
import type { LoadedSourceBrowsingView } from "@app/views/projects/router";
import type {
LoadedSourceBrowsingView,
ProjectsParams,
} from "@app/views/projects/router";
import { closeFocused } from "@app/components/Floating.svelte";
import { formatNodeId, truncateId } from "@app/lib/utils";
import { formatNodeId, truncateId, unreachable } from "@app/lib/utils";
import { pluralize } from "@app/lib/pluralize";
import Avatar from "@app/components/Avatar.svelte";
@@ -28,6 +31,27 @@
? `${nodeId} is a delegate of this project`
: `${nodeId} is a peer tracked by this node`;
}
function routeParamsView(
view: LoadedSourceBrowsingView,
): ProjectsParams["view"] {
if (view.resource === "tree") {
return {
resource: "tree",
};
} else if (view.resource === "history") {
return {
resource: "history",
};
} else if (view.resource === "commits") {
return {
resource: "commits",
commitId: view.commit.commit.id,
};
} else {
return unreachable(view);
}
}
</script>
<style>
@@ -116,7 +140,7 @@
baseUrl,
peer: item.id,
revision: undefined,
view,
view: routeParamsView(view),
},
}}>
<DropdownItem
-3
View File
@@ -91,8 +91,6 @@ export type LoadedSourceBrowsingView =
| {
resource: "commits";
params: LoadedSourceBrowsingParams;
// FIXME: We need the ID so that `updateProjectRoute()` type checks.
commitId: string;
commit: Commit;
}
| {
@@ -308,7 +306,6 @@ export async function loadProjectRoute(
view: {
resource: params.view.resource,
params: viewParams,
commitId: params.view.commitId,
commit: loadedCommit,
},
},