Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Decouple project route types from loaded types
Thomas Scholtes committed 2 years ago
commit 829532fe941d64ba983343c96fd0bfa52747f309
parent f09e3f6edfc6bf0feb9109667d7e9a98eb847755
3 files changed +53 -8
modified src/views/projects/BranchSelector.svelte
@@ -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()}>
modified src/views/projects/PeerSelector.svelte
@@ -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
modified src/views/projects/router.ts
@@ -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,
          },
        },