Refactor projects

Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
Sebastian Martinez
2022-02-21 22:42:52 -03:00
parent 935044ac4c
commit ee507215fb
10 changed files with 217 additions and 217 deletions
+1
View File
@@ -5,6 +5,7 @@ import { styles } from "@test/support/index";
const defaultProps = {
project: {
head: "e678629cd37c770c640a2cd997fc76303c815772",
urn: "rad:git:hnrkqdpm9ub19oc8dccx44echy76hzfsezyio",
name: "nakamoto",
description: "Privacy-preserving Bitcoin light-client implementation in Rust",
defaultBranch: "master",
+7 -9
View File
@@ -17,15 +17,13 @@
{ status: Status.Loading; path: string }
| { status: Status.Loaded; path: string; blob: proj.Blob };
export let source: proj.Source;
export let project: proj.Project;
export let tree: proj.Tree;
export let browserStore: Readable<proj.Browser>;
const { urn, project } = source;
$: browser = $browserStore;
$: path = browser.path || "/";
$: revision = browser.revision || source.branches[project.head];
$: revision = browser.revision || project.branches[project.head];
// When the component is loaded the first time, the blob is yet to be loaded.
let state: State = { status: Status.Loading, path };
@@ -39,8 +37,8 @@
const isMarkdownPath = utils.isMarkdownPath(path);
const promise = path === "/"
? proj.getReadme(urn, commit, source.seed.api)
: proj.getBlob(urn, commit, path, { highlight: !isMarkdownPath }, source.seed.api);
? project.getReadme(commit)
: project.getBlob(commit, path, { highlight: !isMarkdownPath });
state = { status: Status.Loading, path };
state = { status: Status.Loaded, path, blob: await promise };
@@ -59,19 +57,19 @@
mobileFileTree = false;
if (path) {
proj.navigateTo({ path: newPath, revision }, source);
project.navigateTo({ path: newPath, revision });
}
};
const fetchTree = async (path: string) => {
return proj.getTree(urn, commit, path, source.seed.api);
return project.getTree(commit, path);
};
const toggleMobileFileTree = () => {
mobileFileTree = !mobileFileTree;
};
$: commit = proj.getOid(revision, source.branches) || project.head;
$: commit = proj.getOid(revision, project.branches) || project.head;
$: getBlob = loadBlob(path);
$: loadingPath = state.status == Status.Loading ? state.path : null;
</script>
+4 -5
View File
@@ -4,16 +4,15 @@
import { formatCommitTime } from "@app/commit";
import { formatCommit } from "@app/utils";
export let source: proj.Source;
export let project: proj.Project;
export let commit: string;
const { seed, urn } = source;
const onBrowse = (event: { detail: string }) => {
proj.navigateTo({
project.navigateTo({
content: proj.ProjectContent.Tree,
revision: commit,
path: event.detail
}, source);
});
};
</script>
@@ -61,7 +60,7 @@
}
</style>
{#await proj.getCommit(urn, commit, seed.api) then commit}
{#await project.getCommit(commit) then commit}
<div class="commit">
<header>
<div class="summary">
+8 -9
View File
@@ -2,20 +2,19 @@
import type { Writable } from 'svelte/store';
import { navigate } from 'svelte-routing';
import * as utils from '@app/utils';
import * as proj from '@app/project';
import { Browser, ProjectContent, Source } from '@app/project';
import { Browser, ProjectContent, Project } from '@app/project';
import AnchorBadge from '@app/base/profiles/AnchorBadge.svelte';
import type { Tree } from "@app/project";
import BranchSelector from './BranchSelector.svelte';
import PeerSelector from './PeerSelector.svelte';
export let source: Source;
export let project: Project;
export let tree: Tree;
export let commit: string;
export let browserStore: Writable<Browser>;
export let peerSelector: boolean; // If peerSelector should be showed.
let { urn, project, peers, seed, anchors } = source;
let { urn, peers, branches, seed, anchors } = project;
$: browser = $browserStore;
$: revision = browser.revision || commit;
@@ -31,19 +30,19 @@
// Switches between the browser and commit view.
const toggleContent = (input: ProjectContent) => {
proj.navigateTo({
project.navigateTo({
content: content === input ? ProjectContent.Tree : input
}, source);
});
};
const updatePeer = (peer: string) => {
dropdownState.peer = false;
proj.navigateTo({ peer, revision: null }, source);
project.navigateTo({ peer, revision: null });
};
const updateRevision = (revision: string) => {
dropdownState.branch = false;
proj.navigateTo({ revision }, source);
project.navigateTo({ revision });
};
</script>
@@ -157,7 +156,7 @@
bind:peersDropdown={dropdownState.peer}
on:peerChanged={(event) => updatePeer(event.detail)} />
{/if}
<BranchSelector branches={source.branches} {project} {revision} {toggleDropdown}
<BranchSelector {branches} {project} {revision} {toggleDropdown}
bind:branchesDropdown={dropdownState.branch}
on:branchChanged={(event) => updateRevision(event.detail)} />
<div class="anchor">
+5 -7
View File
@@ -1,20 +1,18 @@
<script lang="ts">
import CommitTeaser from "./Commit/CommitTeaser.svelte";
import { getCommits, Source, ProjectContent } from "@app/project";
import * as proj from "@app/project";
import type { Project } from "@app/project";
import { ProjectContent } from "@app/project";
import Loading from "@app/Loading.svelte";
import { groupCommitHistory, GroupedCommitsHistory } from "@app/commit";
export let source: Source;
export let project: Project;
export let commit: string;
let { urn, seed } = source;
const navigateHistory = (revision: string, content?: ProjectContent) => {
proj.navigateTo({ content, revision, path: null }, source);
project.navigateTo({ content, revision, path: null });
};
const fetchCommits = async (parentCommit: string): Promise<GroupedCommitsHistory> => {
const commitsQuery = await getCommits(urn, parentCommit, seed.api);
const commitsQuery = await project.getCommits(parentCommit);
return groupCommitHistory(commitsQuery);
};
</script>
+16 -18
View File
@@ -14,22 +14,20 @@
export let peer: string | null = null;
export let config: Config;
export let source: proj.Source;
export let project: proj.Project;
export let content: proj.ProjectContent;
export let revision: string;
const project = source.project;
let parentName = source.profile ? formatProfile(source.profile.nameOrAddress, config) : null;
let parentName = project.profile ? formatProfile(project.profile.nameOrAddress, config) : null;
let pageTitle = parentName ? `${parentName}/${project.name}` : project.name;
function rootPath(source: proj.Source): string {
return proj.pathTo({
function rootPath(): string {
return project.pathTo({
content: proj.ProjectContent.Tree,
peer: null,
path: "/",
revision: null,
}, source);
});
}
const baseName = parentName
@@ -107,30 +105,30 @@
<header>
<div class="title bold">
{#if source.profile}
<a class="org-avatar" title={source.profile.nameOrAddress} href="/{source.profile.nameOrAddress}">
<Avatar source={source.profile.avatar || source.profile.address} address={source.profile.address}/>
{#if project.profile}
<a class="org-avatar" title={project.profile.nameOrAddress} href="/{project.profile.nameOrAddress}">
<Avatar source={project.profile.avatar || project.profile.address} address={project.profile.address}/>
</a>
<span class="divider">/</span>
{/if}
<Link to={rootPath(source)}>{source.project.name}</Link>
<Link to={rootPath()}>{project.name}</Link>
{#if peer}
<span class="divider" title={peer}>/ {formatSeedId(peer)}</span>
{/if}
</div>
<div class="urn">{source.urn}</div>
<div class="description">{source.project.description}</div>
<div class="urn">{project.urn}</div>
<div class="description">{project.description}</div>
</header>
{#await proj.getRoot(source.project, revision, source.branches, source.seed.api) then { tree, commit }}
<Header {tree} {commit} {browserStore} {source} peerSelector={! source.profile} />
{#await project.getRoot(revision) then { tree, commit }}
<Header {tree} {commit} {browserStore} {project} peerSelector={! project.profile} />
{#if content == proj.ProjectContent.Tree}
<Browser {source} {tree} {browserStore} />
<Browser {project} {tree} {browserStore} />
{:else if content == proj.ProjectContent.History}
<History {source} {commit} />
<History {project} {commit} />
{:else if content == proj.ProjectContent.Commit}
<Commit {source} {commit} />
<Commit {project} {commit} />
{/if}
{:catch err}
<div class="container center-content">
+4 -4
View File
@@ -10,15 +10,15 @@
export let revision: string | null = null;
export let peer: string | null;
export let content: proj.ProjectContent = proj.ProjectContent.Tree;
export let source: proj.Source;
export let project: proj.Project;
export let config: Config;
const browse: proj.BrowseTo = { content, peer, path: "/" };
const head = source.branches[source.project.defaultBranch];
const head = project.branches[project.defaultBranch];
// route is passed when the URL has more params after e.g. /tree or /history
$: if (route) {
const { path, revision } = proj.parseRoute(route, source.branches);
const { path, revision } = proj.parseRoute(route, project.branches);
if (path) browse.path = path;
if (revision) browse.revision = revision;
@@ -36,6 +36,6 @@
peer={browser.peer}
revision={browser.revision || head}
content={browser.content}
{source}
{project}
{config}
/>
+10 -45
View File
@@ -1,11 +1,8 @@
<script lang="ts">
import type { Config } from '@app/config';
import { Route, Router } from "svelte-routing";
import * as proj from '@app/project';
import { Project, ProjectContent } from '@app/project';
import Loading from '@app/Loading.svelte';
import { Profile, ProfileType } from '@app/profile';
import { isRadicleId } from '@app/utils';
import { Seed } from '@app/base/seeds/Seed';
import NotFound from '@app/NotFound.svelte';
import ProjectRoute from "./ProjectRoute.svelte";
@@ -15,38 +12,6 @@
export let profileName: string | null = null; // Address or name of parent profile.
export let peer: string | null = null;
export let config: Config;
const getProject = async (peer: string | null): Promise<proj.Source> => {
const profile = profileName ? await Profile.get(profileName, ProfileType.Project, config) : null;
const seed = profile ? profile.seed : seedHost ? await Seed.lookup(seedHost, config) : null;
if (!profile && !seed) {
throw new Error("Couldn't load project");
}
if (! seed?.valid) {
throw new Error("Couldn't load project: invalid seed");
}
const project = await proj.getInfo(id, seed.api);
const urn = isRadicleId(id) ? id : project.urn;
const anchors = profile ? await profile.confirmedProjectAnchors(urn, config) : [];
// Older versions of http-api don't include the URN.
if (! project.urn) project.urn = urn;
const peers: proj.PeerId[] = project.delegates
? await proj.getRemotes(urn, seed.api)
: [];
let remote: proj.Remote = {
heads: { [project.defaultBranch]: project.head }
};
if (peer) {
remote = await proj.getRemote(urn, peer, seed.api);
}
return { urn, seed, project, peers, branches: remote.heads, profile, anchors };
};
</script>
<style>
@@ -72,35 +37,35 @@
</style>
<main>
{#await getProject(peer)}
{#await Project.get(id, peer, profileName, seedHost, config)}
<header>
<Loading center />
</header>
{:then source}
{:then project}
<Router>
<!-- The default action is to render Browser with the default branch head -->
<Route path="/">
<ProjectRoute content={proj.ProjectContent.Tree} {peer} {source} {config} />
<ProjectRoute content={ProjectContent.Tree} {peer} {project} {config} />
</Route>
<Route path="/tree">
<ProjectRoute content={proj.ProjectContent.Tree} {peer} {source} {config} />
<ProjectRoute content={ProjectContent.Tree} {peer} {project} {config} />
</Route>
<Route path="/tree/*" let:params>
<ProjectRoute route={params["*"]} content={proj.ProjectContent.Tree} {peer} {source} {config} />
<ProjectRoute route={params["*"]} content={ProjectContent.Tree} {peer} {project} {config} />
</Route>
<Route path="/history">
<ProjectRoute content={proj.ProjectContent.History} {peer} {source} {config} />
<ProjectRoute content={ProjectContent.History} {peer} {project} {config} />
</Route>
<Route path="/history/*" let:params>
<ProjectRoute route={params["*"]} content={proj.ProjectContent.History} {peer} {source} {config} />
<ProjectRoute route={params["*"]} content={ProjectContent.History} {peer} {project} {config} />
</Route>
<Route path="/commits/:commit" let:params>
<ProjectRoute revision={params.commit} content={proj.ProjectContent.Commit} {peer} {source} {config} />
<ProjectRoute revision={params.commit} content={ProjectContent.Commit} {peer} {project} {config} />
</Route>
<Route path="/commits/*" let:params>
<ProjectRoute route={params["*"]} content={proj.ProjectContent.Commit} {peer} {source} {config} />
<ProjectRoute route={params["*"]} content={ProjectContent.Commit} {peer} {project} {config} />
</Route>
</Router>
{:catch}