Improve project path construction

This commit is contained in:
Alexis Sellier
2021-06-12 10:28:44 +02:00
parent 4844f52823
commit 798f06f1ec
4 changed files with 36 additions and 12 deletions
+1 -1
View File
@@ -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}
+4 -10
View File
@@ -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();
+8 -1
View File
@@ -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>
+23
View File
@@ -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("/");
}