mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Improve project path construction
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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("/");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user