Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Improve project path construction
Alexis Sellier committed 4 years ago
commit 798f06f1ecef3a9a27309a528f507d739566996d
parent 4844f52823ee142103c024ca5b5ef120af9abe6f
4 files changed +36 -12
modified src/base/orgs/View.svelte
@@ -215,7 +215,7 @@
        {:then projects}
          {#each projects as project}
            <div class="project">
-
              <Project {project} {config} />
+
              <Project {project} org={org.address} {config} />
            </div>
          {/each}
        {:catch err}
modified src/base/projects/View.svelte
@@ -13,22 +13,16 @@
  };

  export let urn: string;
-
  export let org: string | null = null;
-
  export let commit: string | null = null;
+
  export let org: string | undefined;
+
  export let commit: string | undefined;
  export let config: Config;
  export let path: string;

  let project: State.Loading | proj.Info | null = null;
-
  let projectRoot = commit
-
    ? `/projects/${urn}/${commit}`
-
    : `/projects/${urn}`;
+
  let projectRoot = proj.path({ urn, org, commit });

  const onSelect = ({ detail: path }: { detail: string }) => {
-
    if (commit) {
-
      navigate(`/projects/${urn}/${commit}/${path}`);
-
    } else {
-
      navigate(`/projects/${urn}/head/${path}`);
-
    }
+
    navigate(proj.path({ urn, org, commit, path }));
  };
  const back = () => window.history.back();

modified src/base/projects/Widget.svelte
@@ -15,6 +15,7 @@

  export let project: proj.Project;
  export let config: Config;
+
  export let org: string | undefined;

  let state: State = { status: Status.Loading };
  let info: proj.Info | null = null;
@@ -31,7 +32,13 @@

  const onClick = () => {
    if (info) {
-
      navigate(`/projects/${project.id}/${project.anchor.stateHash}`);
+
      navigate(
+
        proj.path({
+
          urn: project.id,
+
          org,
+
          commit: project.anchor.stateHash,
+
        })
+
      );
    }
  };
</script>
modified src/project.ts
@@ -98,3 +98,26 @@ export async function getReadme(
): Promise<Blob | null> {
  return api.get(`projects/${urn}/readme/${commit}`, config);
}
+

+
export function path(
+
  opts: { urn: string, org?: string, commit?: string, path?: string }
+
): string {
+
  let { urn, org, commit, path } = opts;
+
  let result = [];
+

+
  if (org) {
+
    result.push("orgs", org);
+
  }
+
  result.push("projects", urn);
+

+
  if (commit) {
+
    result.push(commit);
+
  } else if (path) {
+
    result.push("head");
+
  }
+

+
  if (path) {
+
    result.push(path);
+
  }
+
  return "/" + result.join("/");
+
}