diff --git a/src/base/projects/BranchSelector.svelte b/src/base/projects/BranchSelector.svelte new file mode 100644 index 000000000..5b84785d6 --- /dev/null +++ b/src/base/projects/BranchSelector.svelte @@ -0,0 +1,139 @@ + + + + +
+ + {#if branches.length > 0} + +
branchesDropdown = !branchesDropdown} class="stat branch" class:not-allowed={!branches}> + {#if commit === project.head} + {project.meta.defaultBranch} + + {:else if !isOid(revision)} + {revision} + {:else} + Browse... + {/if} +
+ +
+ {#if commit === project.head || !isOid(revision)} +
+ {formatCommit(commit)} +
+ {:else} +
+ {commit} +
+
+ {formatCommit(commit)} +
+ {/if} + + {:else if commit === project.head} +
+ {project.meta.defaultBranch} +
+
+ {formatCommit(commit)} +
+ {:else} +
+ {commit} +
+
+ {formatCommit(commit)} +
+ {/if} +
diff --git a/src/base/projects/Browser.svelte b/src/base/projects/Browser.svelte index 9c2dee169..b9fa85084 100644 --- a/src/base/projects/Browser.svelte +++ b/src/base/projects/Browser.svelte @@ -1,4 +1,5 @@ diff --git a/src/base/projects/Commit/History.svelte b/src/base/projects/Commit/History.svelte index a57359d8d..85112d163 100644 --- a/src/base/projects/Commit/History.svelte +++ b/src/base/projects/Commit/History.svelte @@ -1,18 +1,26 @@
-
- {#if commit === project.head} -
- {project.meta.defaultBranch} -
-
- {utils.formatCommit(commit)} -
- {:else} -
- {commit} -
-
- {utils.formatCommit(commit)} -
- {/if} -
-
- {#if anchors} - {#await getAnchor} - - {:then anchor} - {#if anchor} - - {#if commit == anchor[0] && commit === project.head} - - latest 🔐 - - - {:else if commit == anchor[0] && commit !== project.head} - commit = project.head}> - latest 🔐 - - - {:else if anchor?.includes(commit)} - commit = anchor[0]}> - stale 🔒 - - + {#if revision} + updateRevision(event.detail)} /> +
+ {#if anchors} + {#await getAnchor} + + {:then anchor} + {#if anchor} + + {#if commit == anchor[0] && commit === project.head} + + latest 🔐 + + + {:else if commit == anchor[0] && commit !== project.head} + updateRevision(project.head)}> + latest 🔐 + + + {:else if anchor?.includes(commit)} + updateRevision(anchor[0])}> + stale 🔒 + + + {:else} + updateRevision(anchor[0])}> + not anchored 🔓 + + {/if} {:else} - commit = anchor[0]}> + + not anchored 🔓 {/if} - {:else} - - - not anchored 🔓 + {:catch} + + ❌ - {/if} - {:catch} - - ❌ - - {/await} - {/if} -
+ {/await} + {/if} +
+ {/if} {#if config.seed.git.host}
(cloneDropdown = !cloneDropdown)}> @@ -330,7 +301,7 @@ {/if}
-
+
toggleContent(ProjectContent.History)}> {tree.stats.commits} commit(s)
diff --git a/src/base/projects/ProjectContentRoutes.svelte b/src/base/projects/ProjectContentRoutes.svelte new file mode 100644 index 000000000..b17e7f1fe --- /dev/null +++ b/src/base/projects/ProjectContentRoutes.svelte @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/base/projects/Routes.svelte b/src/base/projects/Routes.svelte index 83edcfdf2..9df76d60a 100644 --- a/src/base/projects/Routes.svelte +++ b/src/base/projects/Routes.svelte @@ -4,44 +4,21 @@ import type { Config } from '@app/config'; export let config: Config; + - - - - - - - - - - + + - - - - - - - - - - + + - - - - - - - - - - + + diff --git a/src/base/projects/View.svelte b/src/base/projects/View.svelte index 46e9ce98f..a087de25b 100644 --- a/src/base/projects/View.svelte +++ b/src/base/projects/View.svelte @@ -8,22 +8,22 @@ import { Profile, ProfileType } from '@app/profile'; import type { Info } from '@app/project'; import { formatOrg } from '@app/utils'; + import { getOid } from '@app/project'; - import Browser from './Browser.svelte'; - import Header from './Header.svelte'; - import History from "./Commit/History.svelte"; + import Header from '@app/base/projects/Header.svelte'; + import ProjectContentRoutes from '@app/base/projects/ProjectContentRoutes.svelte'; export let urn: string; export let org = ""; export let user = ""; - export let commit = ""; export let config: Config; - export let path: string; - let content = proj.ProjectContent.Browser; let parentName = formatOrg(org || user, config); let pageTitle = parentName ? `${parentName}/${urn}` : urn; let projectInfo: Info | null = null; + let revision: string; + let content: proj.ProjectContent; + let path: string; let getProject = new Promise(resolve => { if (org) { Profile.get(org, ProfileType.Project, config).then(p => resolve(p)); @@ -36,11 +36,14 @@ const seed = profile?.seed; const cfg = seed ? config.withSeed(seed) : config; const info = await proj.getInfo(urn, cfg); - commit = commit ? commit : info.head; - projectInfo = info; - return { project: info, config: cfg, profile }; + // Checks for delegates returned from seed node, as feature check of the seed node + if (info.meta.delegates) { + const branches = await proj.getBranchesByPeer(urn, info.meta.delegates[0], cfg); + return { project: info, branches: [...Object.entries(branches.heads)], peer: info.meta.delegates[0], config: cfg, profile }; + } + return { project: info, branches: Array([info.meta.defaultBranch, info.head]) as [string, string][], config: cfg, profile }; }); const parentUrl = (profile: Profile) => { @@ -61,11 +64,20 @@ } } + function updateRouteParams({ detail: newParams }: { detail: { path: string; revision: string; content: proj.ProjectContent } }) { + let newLocation = proj.path({ urn, user, org, content: newParams.content, revision: newParams.revision, path: newParams.path }); + if (newLocation !== window.location.pathname) { + navigate(newLocation); + } + if (content !== newParams.content) content = newParams.content; + if (revision !== newParams.revision) revision = newParams.revision; + if (path !== newParams.path) path = newParams.path; + } + const back = () => window.history.back(); // React to changes to the project commit. We have to manually // set the URL as well, to match the current commit. - $: projectRoot = proj.path({ urn, user, org, commit }); - $: navigate(proj.path({ urn, user, org, commit, path })); + $: projectRoot = proj.path({ urn, user, org });