Refactor org and user routes

Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
Sebastian Martinez
2022-02-08 10:16:45 +01:00
committed by Alexis Sellier
parent 82a2ac6f64
commit a43ac33ddc
24 changed files with 619 additions and 799 deletions
+3 -5
View File
@@ -23,7 +23,7 @@
export let revision: string;
export let path: string;
let { urn, org, user, seed, peer, project, config, branches } = source;
let { urn, addressOrName, seed, peer, project, config, branches } = source;
// This is reactive to respond to path changes that don't originate from this
// component, eg. when using the browser's "back" button.
@@ -70,10 +70,8 @@
// Replaces path with current path if none passed.
if (path === undefined) path = state.path;
if (org) {
navigate(proj.path({ peer, urn, org, revision, path }));
} else if (user) {
navigate(proj.path({ peer, urn, user, revision, path }));
if (addressOrName) {
navigate(proj.path({ peer, urn, addressOrName, revision, path }));
} else if (seed) {
navigate(proj.path({ peer, urn, seed, revision, path }));
} else {
+3 -5
View File
@@ -10,16 +10,14 @@
export let locator: string;
export let source: any;
const { org, user, peer, seed } = source;
const { addressOrName, peer, seed } = source;
const navigateCommit = (path: string, content?: proj.ProjectContent) => {
// Replaces path with current path if none passed.
if (path === undefined) path = "/";
if (org) {
navigate(proj.path({ content, peer, urn, org, revision, path }));
} else if (user) {
navigate(proj.path({ content, peer, urn, user, revision, path }));
if (addressOrName) {
navigate(proj.path({ content, peer, urn, addressOrName, revision, path }));
} else if (seed) {
navigate(proj.path({ content, peer, urn, seed, revision, path }));
} else {
+3 -5
View File
@@ -12,7 +12,7 @@
export let revision: string;
export let path: string;
let { urn, user, seed, org, peer, config, project, branches } = source;
let { urn, seed, addressOrName, peer, config, project, branches } = source;
// Bind content to commit history to trigger updates in parent components.
$: [revision_,] = splitPrefixFromPath(locator, branches, project.head);
@@ -23,10 +23,8 @@
// Replaces path with current path if none passed.
if (path === undefined) path = "/";
if (org) {
navigate(proj.path({ content, peer, urn, org, revision, path }));
} else if (user) {
navigate(proj.path({ content, peer, urn, user, revision, path }));
if (addressOrName) {
navigate(proj.path({ content, peer, urn, addressOrName, revision, path }));
} else if (seed) {
navigate(proj.path({ content, peer, urn, seed, revision, path }));
} else {
+12 -9
View File
@@ -2,6 +2,7 @@
import { Route } from "svelte-routing";
import View from '@app/base/projects/View.svelte';
import type { Config } from '@app/config';
import Redirect from "@app/Redirect.svelte";
export let config: Config;
@@ -9,22 +10,24 @@
<!-- With an Seed context -->
<Route path="/seeds/:seed/projects/:id/*" let:params>
<Route path="/seeds/:seed/:id/*" let:params>
<View {config} seed={params.seed} id={params.id} />
</Route>
<Route path="/seeds/:seed/projects/:id/remotes/:peer/*" let:params>
<Route path="/seeds/:seed/:id/remotes/:peer/*" let:params>
<View {config} seed={params.seed} peer={params.peer} id={params.id} />
</Route>
<!-- With an Org context -->
<Route path="/orgs/:org/projects/:id/*" let:params>
<View {config} org={params.org} id={params.id} />
<!-- Explicit user and org context, will at some point be replaced by the generic route -->
<Route path="/orgs/:addressOrName/projects/:id/*" let:params>
<Redirect to="/{params.addressOrName}/{params.id}/{params["*"]}" />
</Route>
<!-- With a User context -->
<Route path="/users/:addressOrName/projects/:id/*" let:params>
<Redirect to="/{params.addressOrName}/{params.id}/{params["*"]}" />
</Route>
<!-- End of eventual dropped routes -->
<Route path="/users/:user/projects/:id/*" let:params>
<View {config} user={params.user} id={params.id} />
<Route path="/:addressOrName/:id/*" let:params>
<View {config} addressOrName={params.addressOrName} id={params.id} />
</Route>
+13 -39
View File
@@ -3,7 +3,6 @@
import type { Config } from '@app/config';
import * as proj from '@app/project';
import Loading from '@app/Loading.svelte';
import Modal from '@app/Modal.svelte';
import Avatar from '@app/Avatar.svelte';
import { Profile, ProfileType } from '@app/profile';
import type { Info } from '@app/project';
@@ -14,27 +13,25 @@
import Header from '@app/base/projects/Header.svelte';
import ProjectContentRoutes from '@app/base/projects/ProjectContentRoutes.svelte';
import NotFound from '@app/NotFound.svelte';
export let id: string; // Project name or URN.
export let org = "";
export let user = "";
export let addressOrName = "";
export let seed = "";
export let peer = "";
export let config: Config;
let parentName = formatOrg(org || user, config);
let parentName = formatOrg(addressOrName, config);
let pageTitle = parentName ? `${parentName}/${id}` : id;
let projectInfo: Info | null = null;
let revision: string;
let content: proj.ProjectContent;
let path: string;
let getProject = new Promise<{ profile?: Profile; seed?: Seed } | null>(resolve => {
if (org) {
Profile.get(org, ProfileType.Project, config).then(p => resolve({ profile: p }));
} else if (user) {
Profile.get(user, ProfileType.Project, config).then(p => resolve({ profile: p }));
let getProject = new Promise<{ profile?: Profile | null; seed?: Seed } | null>((resolve, reject) => {
if (addressOrName) {
Profile.get(addressOrName, ProfileType.Project, config).then(p => resolve({ profile: p })).catch(err => reject(err.message));
} else if (seed) {
Seed.get(config.withSeed({ host: seed })).then(s => resolve({ seed: s }));
Seed.get(config.withSeed({ host: seed })).then(s => resolve({ seed: s })).catch(err => reject(err.message));
} else {
resolve(null);
}
@@ -44,16 +41,12 @@
const cfg = seedInstance && seedInstance.valid ? config.withSeed(seedInstance) : config;
const info = await proj.getInfo(id, cfg);
const urn = isRadicleId(id) ? id : info.meta.urn;
const anchors = await getAllAnchors(config, urn, profile?.anchorsAccount ?? org);
const anchors = await getAllAnchors(config, urn, profile?.anchorsAccount ?? addressOrName);
let branches = Array([info.meta.defaultBranch, info.head]) as [string, string][];
let peers: proj.Peer[] = [];
projectInfo = info;
// Replace project name with URN, in URL bar.
navigate(proj.path({ peer, urn, org, revision, path, seed }), { replace: true });
// Checks for delegates returned from seed node, as feature check of the seed node
if (info.meta.delegates) {
// Check for selected peer to override available branches.
@@ -63,15 +56,9 @@
}
peers = await proj.getPeers(urn, cfg);
}
return { urn, org, user, seed, peer, project: info, branches, peers, config: cfg, profile, anchors };
return { urn, addressOrName, seed, peer, project: info, branches, peers, config: cfg, profile, anchors };
});
const parentUrl = (profile: Profile) => {
return org
? `/orgs/${profile.nameOrAddress}`
: `/users/${profile.nameOrAddress}`;
};
$: if (projectInfo) {
const baseName = parentName
? `${parentName}/${projectInfo.meta.name}`
@@ -85,7 +72,7 @@
}
function updateRouteParams({ detail: newParams }: { detail: { urn: string; path: string; revision: string; peer: string; content: proj.ProjectContent } }) {
let newLocation = proj.path({ user, org, seed, urn: newParams.urn, content: newParams.content, peer: newParams.peer, revision: newParams.revision, path: newParams.path });
let newLocation = proj.path({ addressOrName, seed, urn: newParams.urn, content: newParams.content, peer: newParams.peer, revision: newParams.revision, path: newParams.path });
if (newLocation !== window.location.pathname) {
navigate(newLocation);
}
@@ -94,8 +81,6 @@
if (path !== newParams.path) path = newParams.path;
if (peer !== newParams.peer) peer = newParams.peer;
}
const back = () => window.history.back();
</script>
<style>
@@ -172,12 +157,12 @@
<header>
<div class="title bold">
{#if result.profile}
<a class="org-avatar" title={result.profile.nameOrAddress} href={parentUrl(result.profile)}>
<a class="org-avatar" title={result.profile.nameOrAddress} href="/{result.profile.nameOrAddress}">
<Avatar source={result.profile.avatar || result.profile.address} address={result.profile.address}/>
</a>
<span class="divider">/</span>
{/if}
<Link to={proj.path({ urn: result.urn, user, org, seed })}>{result.project.meta.name}</Link>
<Link to={proj.path({ urn: result.urn, addressOrName, seed })}>{result.project.meta.name}</Link>
{#if peer}
<span class="divider" title={peer}>/ {formatSeedId(peer)}</span>
{/if}
@@ -205,17 +190,6 @@
</div>
{/await}
{:catch}
<Modal subtle>
<span slot="title">🏜️</span>
<span slot="body">
<p class="highlight"><strong>{id}</strong></p>
<p>This project was not found.</p>
</span>
<span slot="actions">
<button on:click={back}>
Back
</button>
</span>
</Modal>
<NotFound title={id} subtitle="This project was not found." />
{/await}
</main>
+2 -4
View File
@@ -16,8 +16,7 @@
export let project: proj.Project;
export let config: Config;
export let org: string | undefined = undefined;
export let user: string | undefined = undefined;
export let addressOrName: string | undefined = undefined;
export let seed: string | undefined = undefined;
export let faded = false;
@@ -40,8 +39,7 @@
navigate(
proj.path({
urn: project.id,
org,
user,
addressOrName,
seed,
revision: project.anchor?.stateHash,
})