diff --git a/src/base/projects/Browser.svelte b/src/base/projects/Browser.svelte index a4072464c..f58257d7d 100644 --- a/src/base/projects/Browser.svelte +++ b/src/base/projects/Browser.svelte @@ -12,14 +12,11 @@ import Readme from './Readme.svelte'; enum Status { - Idle, Loading, Loaded, } - type State = - { status: Status.Idle } - | { status: Status.Loading; path: string } + type State = { status: Status.Loading; path: string } | { status: Status.Loaded; path: string; blob: proj.Blob }; export let urn: string; @@ -30,9 +27,10 @@ export let anchors: string | null = null; export let org: string | null = null; export let user: string | null = null; + export let project: proj.Info; // When the component is loaded the first time, the blob is yet to be loaded. - let state: State = { status: Status.Idle }; + let state: State = { status: Status.Loading, path }; // Whether the clone dropdown is visible. let cloneDropdown = false; // Whether the seed dropdown is visible. @@ -61,6 +59,12 @@ const blob = await loadBlob(path); getBlob = new Promise(resolve => resolve(blob)); + navigateBrowser(commit, path); + }; + + const navigateBrowser = (commit: string, path?: string) => { + // Replaces path with current path if none passed. + if (path === undefined) path = state.path; if (org) { navigate(proj.path({ urn, org, commit, path })); } else if (user) { @@ -115,7 +119,10 @@ border-radius: 0.25rem; color: var(--color-tertiary); background-color: var(--color-tertiary-background); - cursor: help; + cursor: pointer; + } + .anchor-widget.not-allowed { + cursor: not-allowed; } .anchor-widget.not-anchored { color: var(--color-foreground-faded); @@ -258,11 +265,15 @@ {:then anchor} {#if anchor === commit} - + navigateBrowser(project.head)}> anchored 🔒 + {:else if anchor} + navigateBrowser(anchor)}> + not anchored 🔓 + {:else} - + not anchored 🔓 {/if} diff --git a/src/base/projects/View.svelte b/src/base/projects/View.svelte index a4d185d9c..3a26b8b95 100644 --- a/src/base/projects/View.svelte +++ b/src/base/projects/View.svelte @@ -133,6 +133,7 @@ {:catch} diff --git a/src/project.ts b/src/project.ts index 85ecbc738..d29757731 100644 --- a/src/project.ts +++ b/src/project.ts @@ -125,7 +125,8 @@ export function path( result.push("head"); } - if (path) { + // Avoids appending a slash when the path is the root directory. + if (path && path !== "/") { result.push(path); } return "/" + result.join("/");