mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 18:20:30 +08:00
Remove svelte-routing and add custom routing
Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org> Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org> Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
co-authored by
Rūdolfs Ošiņš
parent
955ec7f240
commit
f8ddbbf5da
@@ -1,24 +1,33 @@
|
||||
<script lang="ts">
|
||||
import type { Blob } from "@app/project";
|
||||
|
||||
import { onMount } from "svelte";
|
||||
|
||||
import { scrollIntoView } from "@app/utils";
|
||||
import ProjectLink from "@app/router/ProjectLink.svelte";
|
||||
|
||||
export let blob: Blob;
|
||||
export let line: number | null;
|
||||
export let line: string | null;
|
||||
|
||||
$: lineNumber = line ? parseInt(line.substring(1)) : null;
|
||||
|
||||
const lastCommit = blob.info.lastCommit;
|
||||
const lines = blob.binary ? 0 : (blob.content.match(/\n/g) || []).length;
|
||||
const lineNumbers = Array(lines)
|
||||
.fill(0)
|
||||
.map((_, index) => index + 1);
|
||||
.map((_, index) => (index + 1).toString());
|
||||
const parentDir = blob.path
|
||||
.match(/^.*\/|/)
|
||||
?.values()
|
||||
.next().value;
|
||||
|
||||
$: if (line) {
|
||||
scrollIntoView(line);
|
||||
}
|
||||
|
||||
// Waiting onMount, due to the line numbers still loading.
|
||||
onMount(() => {
|
||||
const lineElement = document.getElementById(`L${line}`);
|
||||
if (lineElement) lineElement.scrollIntoView();
|
||||
if (line) scrollIntoView(line);
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -154,20 +163,21 @@
|
||||
<span class="txt-tiny">Binary content</span>
|
||||
</div>
|
||||
{:else}
|
||||
{#if line}
|
||||
{#if lineNumber}
|
||||
<div
|
||||
class="highlight"
|
||||
style="top: {line === 1 ? 1 : 1.5 * line - 0.5}rem" />
|
||||
style="top: {lineNumber === 1 ? 1 : 1.5 * lineNumber - 0.5}rem" />
|
||||
{/if}
|
||||
<div class="line-numbers">
|
||||
{#each lineNumbers as lineNumber}
|
||||
<a
|
||||
href="#L{lineNumber}"
|
||||
class="line-number"
|
||||
class:highlighted={lineNumber === line}
|
||||
<ProjectLink
|
||||
projectParams={{ hash: `L${lineNumber}` }}
|
||||
id="L{lineNumber}">
|
||||
<span
|
||||
class="line-number"
|
||||
class:highlighted={lineNumber === line} />
|
||||
{lineNumber}
|
||||
</a>
|
||||
</ProjectLink>
|
||||
{/each}
|
||||
</div>
|
||||
{#if blob.html}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<script lang="ts">
|
||||
import type { Readable } from "svelte/store";
|
||||
import type * as proj from "@app/project";
|
||||
import type { Theme } from "@app/ThemeToggle.svelte";
|
||||
import type { ProjectRoute } from "@app/router/definitions";
|
||||
import type * as proj from "@app/project";
|
||||
|
||||
import Loading from "@app/Loading.svelte";
|
||||
import Placeholder from "@app/Placeholder.svelte";
|
||||
import * as utils from "@app/utils";
|
||||
import Button from "@app/Button.svelte";
|
||||
import { theme } from "@app/ThemeToggle.svelte";
|
||||
import * as router from "@app/router";
|
||||
|
||||
import Tree from "./Tree.svelte";
|
||||
import Blob from "./Blob.svelte";
|
||||
@@ -24,12 +25,11 @@
|
||||
|
||||
export let project: proj.Project;
|
||||
export let tree: proj.Tree;
|
||||
export let browserStore: Readable<proj.Browser>;
|
||||
export let commit: string;
|
||||
export let activeRoute: ProjectRoute;
|
||||
|
||||
$: browser = $browserStore;
|
||||
$: path = browser.path || "/";
|
||||
$: revision = browser.revision;
|
||||
$: path = activeRoute.params.path || "/";
|
||||
$: line = activeRoute.params.hash || null;
|
||||
|
||||
// When the component is loaded the first time, the blob is yet to be loaded.
|
||||
let state: State = { status: Status.Loading, path };
|
||||
@@ -79,9 +79,10 @@
|
||||
// Close mobile tree if user navigates to other file
|
||||
mobileFileTree = false;
|
||||
|
||||
if (path) {
|
||||
project.navigateTo({ path: newPath, revision, line: null });
|
||||
}
|
||||
router.updateProjectRoute({
|
||||
view: { resource: "tree" },
|
||||
path: newPath,
|
||||
});
|
||||
};
|
||||
|
||||
const fetchTree = async (path: string) => {
|
||||
@@ -207,9 +208,9 @@
|
||||
<Loading small center />
|
||||
{:then blob}
|
||||
{#if utils.isMarkdownPath(blob.path)}
|
||||
<Readme content={blob.content} {getImage} />
|
||||
<Readme {activeRoute} content={blob.content} {getImage} />
|
||||
{:else}
|
||||
<Blob line={browser.line} {blob} />
|
||||
<Blob {line} {blob} />
|
||||
{/if}
|
||||
{:catch}
|
||||
<Placeholder icon="🍂">
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<script lang="ts">
|
||||
import * as proj from "@app/project";
|
||||
import { formatCommit } from "@app/utils";
|
||||
import type { Commit } from "@app/commit";
|
||||
|
||||
import { formatCommit } from "@app/utils";
|
||||
|
||||
import Changeset from "@app/base/projects/SourceBrowser/Changeset.svelte";
|
||||
import CommitAuthorship from "@app/base/projects/Commit/CommitAuthorship.svelte";
|
||||
import CommitVerifiedBadge from "@app/base/projects/Commit/CommitVerifiedBadge.svelte";
|
||||
import * as router from "@app/router";
|
||||
|
||||
export let project: proj.Project;
|
||||
export let commit: Commit;
|
||||
|
||||
const onBrowse = (event: { detail: string }) => {
|
||||
project.navigateTo({
|
||||
content: proj.ProjectContent.Tree,
|
||||
revision: commit.header.sha1,
|
||||
router.updateProjectRoute({
|
||||
view: { resource: "tree" },
|
||||
path: event.detail,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -44,7 +44,8 @@
|
||||
src={gravatarURL(commit.header.committer.email)} />
|
||||
{#if commit.context?.committer}
|
||||
<span class="txt-bold committer">
|
||||
{commit.context?.committer.peer.person.name}
|
||||
{commit.context.committer.peer.person?.name ||
|
||||
commit.context.committer.peer.id}
|
||||
</span>
|
||||
{#if !noDelegate && commit.context?.committer.peer.delegate}
|
||||
<Badge variant="tertiary">delegate</Badge>
|
||||
@@ -73,7 +74,8 @@
|
||||
src={gravatarURL(commit.header.committer.email)} />
|
||||
{#if commit.context?.committer}
|
||||
<span class="txt-bold committer">
|
||||
{commit.context?.committer.peer.person.name}
|
||||
{commit.context.committer.peer.person?.name ||
|
||||
commit.context.committer.peer.id}
|
||||
</span>
|
||||
{#if !noDelegate && commit.context?.committer.peer.delegate}
|
||||
<Badge variant="tertiary">delegate</Badge>
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div
|
||||
class="browse"
|
||||
title="View file"
|
||||
title="Browse the repository at this point in the history"
|
||||
on:click|stopPropagation={() => browseCommit(commit.header.sha1)}>
|
||||
<Icon name="browse" />
|
||||
</div>
|
||||
|
||||
@@ -1,47 +1,61 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import { navigate } from "svelte-routing";
|
||||
import type { Browser } from "@app/project";
|
||||
import { ProjectContent, Project } from "@app/project";
|
||||
import type { Project } from "@app/project";
|
||||
import type { Tree } from "@app/project";
|
||||
import type { ProjectRoute } from "@app/router/definitions";
|
||||
|
||||
import * as router from "@app/router";
|
||||
import BranchSelector from "@app/base/projects/BranchSelector.svelte";
|
||||
import CloneButton from "@app/base/projects/CloneButton.svelte";
|
||||
import PeerSelector from "@app/base/projects/PeerSelector.svelte";
|
||||
import type { Tree } from "@app/project";
|
||||
import { closeFocused } from "@app/Floating.svelte";
|
||||
|
||||
export let activeRoute: ProjectRoute;
|
||||
export let project: Project;
|
||||
export let tree: Tree;
|
||||
export let commit: string;
|
||||
export let browserStore: Writable<Browser>;
|
||||
|
||||
const { urn, peers, branches, seed } = project;
|
||||
|
||||
$: browser = $browserStore;
|
||||
$: revision = browser.revision || commit;
|
||||
$: content = browser.content;
|
||||
$: revision = activeRoute.params.revision ?? commit;
|
||||
|
||||
// Switches between project views.
|
||||
const toggleContent = (input: ProjectContent, keepSourceInPath: boolean) => {
|
||||
project.navigateTo({
|
||||
content: content === input ? ProjectContent.Tree : input,
|
||||
issue: null, // Removing issue here from browserStore to not contaminate path on navigation.
|
||||
patch: null, // Removing patch here from browserStore to not contaminate path on navigation.
|
||||
...(keepSourceInPath ? null : { revision: null, path: null }),
|
||||
const toggleContent = (
|
||||
input: "patches" | "issues" | "history",
|
||||
keepSourceInPath: boolean,
|
||||
) => {
|
||||
router.updateProjectRoute({
|
||||
view: {
|
||||
resource: activeRoute.params.view.resource === input ? "tree" : input,
|
||||
},
|
||||
urn: project.urn,
|
||||
revision: revision,
|
||||
...(keepSourceInPath ? null : { revision: undefined, path: undefined }),
|
||||
});
|
||||
};
|
||||
|
||||
const updatePeer = (peer: string) => {
|
||||
project.navigateTo({ peer, revision: null });
|
||||
router.updateProjectRoute({
|
||||
peer,
|
||||
revision: undefined,
|
||||
});
|
||||
closeFocused();
|
||||
};
|
||||
|
||||
const updateRevision = (revision: string) => {
|
||||
project.navigateTo({ revision });
|
||||
router.updateProjectRoute({
|
||||
revision,
|
||||
});
|
||||
closeFocused();
|
||||
};
|
||||
|
||||
function goToSeed() {
|
||||
if (seed.api.port) {
|
||||
navigate(`/seeds/${seed.api.host}:${seed.api.port}`);
|
||||
router.push({
|
||||
resource: "seeds",
|
||||
params: { host: `${seed.api.host}:${seed.api.port}` },
|
||||
});
|
||||
} else {
|
||||
navigate(`/seeds/${seed.api.host}`);
|
||||
router.push({ resource: "seeds", params: { host: seed.api.host } });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -99,7 +113,7 @@
|
||||
{#if peers.length > 0}
|
||||
<PeerSelector
|
||||
{peers}
|
||||
peer={browser.peer}
|
||||
peer={activeRoute.params.peer}
|
||||
on:peerChanged={event => updatePeer(event.detail)} />
|
||||
{/if}
|
||||
|
||||
@@ -126,8 +140,8 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div
|
||||
class="stat commit-count clickable widget"
|
||||
class:active={content === ProjectContent.History}
|
||||
on:click={() => toggleContent(ProjectContent.History, true)}>
|
||||
class:active={activeRoute.params.view.resource === "history"}
|
||||
on:click={() => toggleContent("history", true)}>
|
||||
<span class="txt-bold">{tree.stats.commits}</span>
|
||||
commit(s)
|
||||
</div>
|
||||
@@ -135,10 +149,10 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div
|
||||
class="stat issue-count clickable widget"
|
||||
class:active={content === ProjectContent.Issues}
|
||||
class:active={activeRoute.params.view.resource === "issues"}
|
||||
class:not-allowed={project.issues === 0}
|
||||
class:clickable={project.issues > 0}
|
||||
on:click={() => toggleContent(ProjectContent.Issues, false)}>
|
||||
on:click={() => toggleContent("issues", false)}>
|
||||
<span class="txt-bold">{project.issues}</span>
|
||||
issue(s)
|
||||
</div>
|
||||
@@ -147,10 +161,10 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div
|
||||
class="stat patch-count clickable widget"
|
||||
class:active={content === ProjectContent.Patches}
|
||||
class:active={activeRoute.params.view.resource === "patches"}
|
||||
class:not-allowed={project.patches === 0}
|
||||
class:clickable={project.patches > 0}
|
||||
on:click={() => toggleContent(ProjectContent.Patches, false)}>
|
||||
on:click={() => toggleContent("patches", false)}>
|
||||
<span class="txt-bold">{project.patches}</span>
|
||||
patch(es)
|
||||
</div>
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
<script lang="ts">
|
||||
import CommitTeaser from "./Commit/CommitTeaser.svelte";
|
||||
import { Project, ProjectContent } from "@app/project";
|
||||
import type { CommitMetadata, CommitsHistory } from "@app/commit";
|
||||
|
||||
import CommitTeaser from "./Commit/CommitTeaser.svelte";
|
||||
import { Project } from "@app/project";
|
||||
import { groupCommits } from "@app/commit";
|
||||
import List from "@app/List.svelte";
|
||||
import * as router from "@app/router";
|
||||
|
||||
export let project: Project;
|
||||
export let history: CommitsHistory;
|
||||
|
||||
const navigateHistory = (revision: string, content?: ProjectContent) => {
|
||||
project.navigateTo({
|
||||
content,
|
||||
revision,
|
||||
issue: null,
|
||||
patch: null,
|
||||
path: null,
|
||||
});
|
||||
};
|
||||
|
||||
const fetchMoreCommits = async (): Promise<CommitMetadata[]> => {
|
||||
const response = await Project.getCommits(project.urn, project.seed.api, {
|
||||
// Fetching 31 elements since we remove the first one
|
||||
@@ -30,11 +22,9 @@
|
||||
};
|
||||
|
||||
const browseCommit = (event: { detail: string }) => {
|
||||
project.navigateTo({
|
||||
content: ProjectContent.Tree,
|
||||
router.updateProjectRoute({
|
||||
view: { resource: "tree" },
|
||||
revision: event.detail,
|
||||
issue: null,
|
||||
path: null,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
@@ -91,8 +81,12 @@
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<div
|
||||
class="commit"
|
||||
on:click={() =>
|
||||
navigateHistory(commit.header.sha1, ProjectContent.Commit)}>
|
||||
on:click={() => {
|
||||
router.updateProjectRoute({
|
||||
view: { resource: "commits" },
|
||||
revision: commit.header.sha1,
|
||||
});
|
||||
}}>
|
||||
<CommitTeaser {commit} on:browseCommit={browseCommit} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
import type { Issue } from "@app/issue";
|
||||
import type { ToggleButtonOption } from "@app/ToggleButton.svelte";
|
||||
|
||||
import { Project, ProjectContent } from "@app/project";
|
||||
import { capitalize } from "@app/utils";
|
||||
import { groupIssues } from "@app/issue";
|
||||
import { navigate } from "svelte-routing";
|
||||
import * as router from "@app/router";
|
||||
|
||||
import IssueTeaser from "@app/base/projects/Issue/IssueTeaser.svelte";
|
||||
import Placeholder from "@app/Placeholder.svelte";
|
||||
@@ -18,7 +17,6 @@
|
||||
|
||||
export let wallet: Wallet;
|
||||
export let issues: Issue[];
|
||||
export let project: Project;
|
||||
export let state: State;
|
||||
|
||||
let options: ToggleButtonOption<State>[];
|
||||
@@ -66,7 +64,9 @@
|
||||
<ToggleButton
|
||||
{options}
|
||||
on:select={e => {
|
||||
navigate(`?state=${e.detail}`);
|
||||
router.updateProjectRoute({
|
||||
search: e.detail,
|
||||
});
|
||||
}}
|
||||
active={state} />
|
||||
</div>
|
||||
@@ -78,12 +78,11 @@
|
||||
<div
|
||||
class="teaser"
|
||||
on:click={() => {
|
||||
project.navigateTo({
|
||||
content: ProjectContent.Issue,
|
||||
issue: issue.id,
|
||||
patch: null,
|
||||
revision: null,
|
||||
path: null,
|
||||
router.updateProjectRoute({
|
||||
view: {
|
||||
resource: "issue",
|
||||
params: { issue: issue.id },
|
||||
},
|
||||
});
|
||||
}}>
|
||||
<IssueTeaser {wallet} {issue} />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { Wallet } from "@app/wallet";
|
||||
import { Project, ProjectContent } from "@app/project";
|
||||
import type { Project } from "@app/project";
|
||||
|
||||
import { capitalize } from "@app/utils";
|
||||
import { Patch, PatchTab } from "@app/patch";
|
||||
import { formatObjectId } from "@app/cobs";
|
||||
@@ -11,6 +12,7 @@
|
||||
import PatchTabBar from "./Patch/PatchTabBar.svelte";
|
||||
import PatchTimeline from "./Patch/PatchTimeline.svelte";
|
||||
import Placeholder from "@app/Placeholder.svelte";
|
||||
import * as router from "@app/router";
|
||||
|
||||
export let patch: Patch;
|
||||
export let project: Project;
|
||||
@@ -25,10 +27,9 @@
|
||||
};
|
||||
|
||||
const onBrowse = (event: { detail: string }, revision: string) => {
|
||||
project.navigateTo({
|
||||
content: ProjectContent.Tree,
|
||||
router.updateProjectRoute({
|
||||
view: { resource: "tree" },
|
||||
revision,
|
||||
patch: null,
|
||||
path: event.detail,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
type State = "proposed" | "draft" | "archived";
|
||||
<script lang="ts" context="module">
|
||||
export type State = "proposed" | "draft" | "archived";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { Wallet } from "@app/wallet";
|
||||
import type { Patch } from "@app/patch";
|
||||
import type { ToggleButtonOption } from "@app/ToggleButton.svelte";
|
||||
@@ -9,14 +11,13 @@
|
||||
import Placeholder from "@app/Placeholder.svelte";
|
||||
import ToggleButton from "@app/ToggleButton.svelte";
|
||||
|
||||
import { Project, ProjectContent } from "@app/project";
|
||||
import { capitalize } from "@app/utils";
|
||||
import { groupPatches } from "@app/patch";
|
||||
import * as router from "@app/router";
|
||||
|
||||
export let state: State = "proposed";
|
||||
export let state: State;
|
||||
export let wallet: Wallet;
|
||||
export let patches: Patch[];
|
||||
export let project: Project;
|
||||
|
||||
let options: ToggleButtonOption<State>[];
|
||||
const sortedPatches = groupPatches(patches);
|
||||
@@ -63,7 +64,9 @@
|
||||
<ToggleButton
|
||||
{options}
|
||||
on:select={e => {
|
||||
state = e.detail;
|
||||
router.updateProjectRoute({
|
||||
search: e.detail,
|
||||
});
|
||||
}}
|
||||
active={state} />
|
||||
</div>
|
||||
@@ -75,12 +78,8 @@
|
||||
<div
|
||||
class="teaser"
|
||||
on:click={() => {
|
||||
project.navigateTo({
|
||||
content: ProjectContent.Patch,
|
||||
patch: patch.id,
|
||||
issue: null,
|
||||
revision: null,
|
||||
path: null,
|
||||
router.updateProjectRoute({
|
||||
view: { resource: "patch", params: { patch: patch.id } },
|
||||
});
|
||||
}}>
|
||||
<PatchTeaser {wallet} {patch} />
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { Wallet } from "@app/wallet";
|
||||
import type { State as IssueState } from "./Issues.svelte";
|
||||
|
||||
import * as proj from "@app/project";
|
||||
import Placeholder from "@app/Placeholder.svelte";
|
||||
import Loading from "@app/Loading.svelte";
|
||||
import { formatProfile, formatSeedId, setOpenGraphMetaTag } from "@app/utils";
|
||||
import { browserStore } from "@app/project";
|
||||
import * as patch from "@app/patch";
|
||||
import * as issue from "@app/issue";
|
||||
|
||||
import Header from "@app/base/projects/Header.svelte";
|
||||
import Async from "@app/Async.svelte";
|
||||
|
||||
import Browser from "./Browser.svelte";
|
||||
import Commit from "./Commit.svelte";
|
||||
import History from "./History.svelte";
|
||||
import Issues from "./Issues.svelte";
|
||||
import Issue from "./Issue.svelte";
|
||||
import ProjectMeta from "./ProjectMeta.svelte";
|
||||
import Patches from "./Patches.svelte";
|
||||
import Patch from "./Patch.svelte";
|
||||
|
||||
export let peer: string | null = null;
|
||||
export let wallet: Wallet;
|
||||
export let project: proj.Project;
|
||||
export let content: proj.ProjectContent;
|
||||
export let revision: string | null;
|
||||
|
||||
const parentName = project.profile
|
||||
? formatProfile(project.profile.nameOrAddress, wallet)
|
||||
: null;
|
||||
let pageTitle = parentName ? `${parentName}/${project.name}` : project.name;
|
||||
|
||||
$: issueFilter = ($browserStore.search?.get("state") as IssueState) ?? "open";
|
||||
|
||||
const baseName = parentName ? `${parentName}/${project.name}` : project.name;
|
||||
|
||||
if (project.description) {
|
||||
pageTitle = `${baseName}: ${project.description}`;
|
||||
} else {
|
||||
pageTitle = baseName;
|
||||
}
|
||||
|
||||
setOpenGraphMetaTag([
|
||||
{ prop: "og:title", content: project.name },
|
||||
{ prop: "og:description", content: project.description },
|
||||
{ prop: "og:url", content: window.location.href },
|
||||
]);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.error {
|
||||
color: var(--color-negative);
|
||||
background-color: var(--color-negative-2);
|
||||
word-wrap: break-word;
|
||||
text-overflow: ellipsis;
|
||||
overflow-x: hidden;
|
||||
padding: 1rem;
|
||||
}
|
||||
.error::selection,
|
||||
.error ::selection {
|
||||
background-color: var(--color-negative);
|
||||
}
|
||||
.content {
|
||||
padding: 0 2rem 0 8rem;
|
||||
}
|
||||
@media (max-width: 960px) {
|
||||
.content {
|
||||
padding-left: 2rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<svelte:head>
|
||||
<title>{pageTitle}</title>
|
||||
</svelte:head>
|
||||
|
||||
<ProjectMeta
|
||||
noDescription={content !== proj.ProjectContent.Tree}
|
||||
{project}
|
||||
{peer} />
|
||||
|
||||
{#if revision}
|
||||
{#await project.getRoot(revision)}
|
||||
<Loading center />
|
||||
{:then { tree, commit }}
|
||||
<Header {tree} {commit} {browserStore} {project} />
|
||||
|
||||
{#if content === proj.ProjectContent.Tree}
|
||||
<Browser {project} {commit} {tree} {browserStore} />
|
||||
{:else if content === proj.ProjectContent.History}
|
||||
<Async
|
||||
fetch={proj.Project.getCommits(project.urn, project.seed.api, {
|
||||
parent: commit,
|
||||
verified: true,
|
||||
})}
|
||||
let:result>
|
||||
<History {project} history={result} />
|
||||
</Async>
|
||||
{:else if content === proj.ProjectContent.Commit}
|
||||
<Async fetch={project.getCommit(commit)} let:result>
|
||||
<Commit {project} commit={result} />
|
||||
</Async>
|
||||
{/if}
|
||||
{:catch err}
|
||||
<div class="content">
|
||||
<div class="error txt-tiny">
|
||||
<!-- TODO: Differentiate between (1) commit doesn't exist and (2) failed
|
||||
to fetch - this needs a change to the backend. -->
|
||||
API request to
|
||||
<span class="txt-monospace">{err.url}</span>
|
||||
failed
|
||||
</div>
|
||||
</div>
|
||||
{/await}
|
||||
|
||||
{#if content === proj.ProjectContent.Issues}
|
||||
<Async
|
||||
fetch={issue.Issue.getIssues(project.urn, project.seed.api)}
|
||||
let:result>
|
||||
<Issues {project} state={issueFilter} {wallet} issues={result} />
|
||||
</Async>
|
||||
{:else if content === proj.ProjectContent.Issue && $browserStore.issue}
|
||||
<Async
|
||||
fetch={issue.Issue.getIssue(
|
||||
project.urn,
|
||||
$browserStore.issue,
|
||||
project.seed.api,
|
||||
)}
|
||||
let:result>
|
||||
<Issue {project} {wallet} issue={result} />
|
||||
</Async>
|
||||
{:else if content === proj.ProjectContent.Patches}
|
||||
<Async
|
||||
fetch={patch.Patch.getPatches(project.urn, project.seed.api)}
|
||||
let:result>
|
||||
<Patches {project} {wallet} patches={result} />
|
||||
</Async>
|
||||
{:else if content === proj.ProjectContent.Patch && $browserStore.patch}
|
||||
<Async
|
||||
fetch={patch.Patch.getPatch(
|
||||
project.urn,
|
||||
$browserStore.patch,
|
||||
project.seed.api,
|
||||
)}
|
||||
let:result>
|
||||
<Patch {project} {wallet} patch={result} />
|
||||
</Async>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="content">
|
||||
{#if peer}
|
||||
<Placeholder icon="🍂">
|
||||
<span slot="title">
|
||||
<span class="txt-monospace">{formatSeedId(peer)}</span>
|
||||
</span>
|
||||
<span slot="body">Couldn't load remote source tree.</span>
|
||||
</Placeholder>
|
||||
{:else}
|
||||
<Placeholder icon="🍂">
|
||||
<span slot="body">Couldn't load source tree.</span>
|
||||
</Placeholder>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,24 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { link } from "svelte-routing";
|
||||
import type { PeerId, Project } from "@app/project";
|
||||
|
||||
import Avatar from "@app/Avatar.svelte";
|
||||
import Clipboard from "@app/Clipboard.svelte";
|
||||
import Link from "@app/router/Link.svelte";
|
||||
import ProjectLink from "@app/router/ProjectLink.svelte";
|
||||
import { formatSeedId } from "@app/utils";
|
||||
import { type PeerId, type Project, ProjectContent } from "@app/project";
|
||||
|
||||
export let project: Project;
|
||||
export let peer: PeerId | null = null;
|
||||
export let noDescription = false;
|
||||
|
||||
function rootPath(): string {
|
||||
return project.pathTo({
|
||||
content: ProjectContent.Tree,
|
||||
peer: null,
|
||||
path: "/",
|
||||
revision: null,
|
||||
issue: null,
|
||||
patch: null,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -61,9 +51,6 @@
|
||||
.description {
|
||||
margin: 1rem 0 1.5rem 0;
|
||||
}
|
||||
.placeholder {
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 0 2rem 0 8rem;
|
||||
@@ -85,18 +72,33 @@
|
||||
<header class="content">
|
||||
<div class="title txt-bold txt-title">
|
||||
{#if project.profile}
|
||||
<a
|
||||
class="org-avatar"
|
||||
title={project.profile.nameOrAddress}
|
||||
href="/{project.profile.nameOrAddress}">
|
||||
<Avatar
|
||||
source={project.profile.avatar || project.profile.address}
|
||||
title={project.profile.address} />
|
||||
</a>
|
||||
<Link
|
||||
route={{
|
||||
resource: "profile",
|
||||
params: { addressOrName: project.profile.addressOrName },
|
||||
}}
|
||||
title={project.profile.addressOrName}>
|
||||
<span class="org-avatar">
|
||||
<Avatar
|
||||
source={project.profile.avatar || project.profile.address}
|
||||
title={project.profile.address} />
|
||||
</span>
|
||||
</Link>
|
||||
<span class="divider">/</span>
|
||||
{/if}
|
||||
<span class="truncate">
|
||||
<a use:link class="project-name" href={rootPath()}>{project.name}</a>
|
||||
<ProjectLink
|
||||
projectParams={{
|
||||
view: { resource: "tree" },
|
||||
path: "/",
|
||||
peer: undefined,
|
||||
route: undefined,
|
||||
revision: undefined,
|
||||
}}>
|
||||
<span class="project-name">
|
||||
{project.name}
|
||||
</span>
|
||||
</ProjectLink>
|
||||
</span>
|
||||
{#if peer}
|
||||
<span class="peer-id">
|
||||
@@ -110,9 +112,5 @@
|
||||
<span class="truncate">{project.urn}</span>
|
||||
<Clipboard small text={project.urn} />
|
||||
</div>
|
||||
{#if !noDescription}
|
||||
<div class="description">{project.description}</div>
|
||||
{:else}
|
||||
<div class="placeholder" />
|
||||
{/if}
|
||||
<div class="description">{project.description}</div>
|
||||
</header>
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from "svelte/store";
|
||||
import type { Wallet } from "@app/wallet";
|
||||
import { formatLocationHash } from "@app/utils";
|
||||
import * as proj from "@app/project";
|
||||
import type { RouteLocation } from "@app/index";
|
||||
|
||||
import Project from "@app/base/projects/Project.svelte";
|
||||
|
||||
export let browserStore: Writable<proj.Browser> = proj.browserStore;
|
||||
export let route: string | null = null;
|
||||
export let revision: string | null = null;
|
||||
export let issue: string | null = null;
|
||||
export let patch: string | null = null;
|
||||
export let peer: string | null;
|
||||
export let content: proj.ProjectContent = proj.ProjectContent.Tree;
|
||||
export let project: proj.Project;
|
||||
export let wallet: Wallet;
|
||||
export let location: RouteLocation | null = null;
|
||||
|
||||
const browse: proj.BrowseTo = { content, peer, path: "/" };
|
||||
const head = project.branches[project.defaultBranch] || null;
|
||||
|
||||
// If line-number hash changes, we update the browser.
|
||||
$: browse.line = formatLocationHash(location?.hash || null);
|
||||
|
||||
// `route` includes any unmatched path segments.
|
||||
$: if (route) {
|
||||
const { path, revision } = proj.parseRoute(route, project.branches);
|
||||
|
||||
if (path) browse.path = path;
|
||||
if (revision) browse.revision = revision;
|
||||
} else if (revision) {
|
||||
browse.revision = revision;
|
||||
} else if (issue) {
|
||||
browse.issue = issue;
|
||||
} else if (location) {
|
||||
browse.search = new URLSearchParams(location.search);
|
||||
} else if (patch) {
|
||||
browse.patch = patch;
|
||||
} else if (head) {
|
||||
browse.revision = head;
|
||||
} else {
|
||||
const branchNames = Object.keys(project.branches);
|
||||
const firstBranch = branchNames.length >= 1 ? branchNames[0] : null;
|
||||
|
||||
browse.revision = firstBranch;
|
||||
}
|
||||
|
||||
$: proj.browse({ ...browse, peer });
|
||||
$: browser = $browserStore;
|
||||
</script>
|
||||
|
||||
<Project
|
||||
peer={browser.peer}
|
||||
revision={browser.revision || head}
|
||||
content={browser.content}
|
||||
{project}
|
||||
{wallet} />
|
||||
@@ -1,9 +1,14 @@
|
||||
<script lang="ts">
|
||||
import Markdown from "@app/Markdown.svelte";
|
||||
import type * as proj from "@app/project";
|
||||
import type { ProjectRoute } from "@app/router/definitions";
|
||||
|
||||
import Markdown from "@app/Markdown.svelte";
|
||||
|
||||
export let content: string;
|
||||
export let getImage: (path: string) => Promise<proj.Blob>;
|
||||
export let activeRoute: ProjectRoute;
|
||||
|
||||
$: hash = activeRoute.params.hash || null;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -16,5 +21,5 @@
|
||||
</style>
|
||||
|
||||
<article>
|
||||
<Markdown {content} {getImage} />
|
||||
<Markdown {content} {getImage} {hash} />
|
||||
</article>
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { Route } from "svelte-routing";
|
||||
import View from "@app/base/projects/View.svelte";
|
||||
import type { Wallet } from "@app/wallet";
|
||||
import Redirect from "@app/Redirect.svelte";
|
||||
|
||||
export let wallet: Wallet;
|
||||
</script>
|
||||
|
||||
<!-- With a seed context -->
|
||||
|
||||
<Route path="/seeds/:seed/:id/*" let:params>
|
||||
<View {wallet} seedHost={params.seed} id={params.id} />
|
||||
</Route>
|
||||
|
||||
<Route path="/seeds/:seed/:id/remotes/:peer/*" let:params>
|
||||
<View {wallet} seedHost={params.seed} peer={params.peer} id={params.id} />
|
||||
</Route>
|
||||
|
||||
<!-- 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>
|
||||
|
||||
<Route path="/users/:addressOrName/projects/:id/*" let:params>
|
||||
<Redirect to="/{params.addressOrName}/{params.id}/{params['*']}" />
|
||||
</Route>
|
||||
<!-- End of eventual dropped routes -->
|
||||
|
||||
<Route path="/:profile/:id/remotes/:peer/*" let:params>
|
||||
<View
|
||||
{wallet}
|
||||
profileName={params.profile}
|
||||
id={params.id}
|
||||
peer={params.peer} />
|
||||
</Route>
|
||||
|
||||
<Route path="/:profile/:id/*" let:params>
|
||||
<View {wallet} profileName={params.profile} id={params.id} />
|
||||
</Route>
|
||||
+162
-95
@@ -1,17 +1,70 @@
|
||||
<script lang="ts">
|
||||
import type { Wallet } from "@app/wallet";
|
||||
import { Route, Router } from "svelte-routing";
|
||||
import { Project, ProjectContent } from "@app/project";
|
||||
import type { ProjectRoute, ProjectsParams } from "@app/router/definitions";
|
||||
import type { State as IssueState } from "./Issues.svelte";
|
||||
import type { State as PatchState } from "./Patches.svelte";
|
||||
|
||||
import * as issue from "@app/issue";
|
||||
import * as patch from "@app/patch";
|
||||
import * as proj from "@app/project";
|
||||
import * as router from "@app/router";
|
||||
import Loading from "@app/Loading.svelte";
|
||||
import NotFound from "@app/NotFound.svelte";
|
||||
import { formatSeedId, unreachable } from "@app/utils";
|
||||
|
||||
import ProjectRoute from "./ProjectRoute.svelte";
|
||||
import Header from "./Header.svelte";
|
||||
import Browser from "./Browser.svelte";
|
||||
import History from "./History.svelte";
|
||||
import Commit from "./Commit.svelte";
|
||||
import Issues from "./Issues.svelte";
|
||||
import Issue from "./Issue.svelte";
|
||||
import Patches from "./Patches.svelte";
|
||||
import Patch from "./Patch.svelte";
|
||||
import ProjectMeta from "./ProjectMeta.svelte";
|
||||
import Message from "@app/Message.svelte";
|
||||
import Placeholder from "@app/Placeholder.svelte";
|
||||
|
||||
export let id: string; // Project name or URN.
|
||||
export let seedHost: string | null = null;
|
||||
export let profileName: string | null = null; // Address or name of parent profile.
|
||||
export let peer: string | null = null;
|
||||
export let wallet: Wallet;
|
||||
export let activeRoute: ProjectRoute;
|
||||
|
||||
$: urn = activeRoute.params.urn;
|
||||
$: peer = activeRoute.params.peer ?? null;
|
||||
|
||||
$: searchParams = new URLSearchParams(activeRoute.params.search || "");
|
||||
$: issueFilter = (searchParams.get("state") as IssueState) || "open";
|
||||
$: patchFilter = (searchParams.get("state") as PatchState) || "proposed";
|
||||
|
||||
const getProject = async (params: ProjectsParams) => {
|
||||
const project = await proj.Project.get(
|
||||
params.urn,
|
||||
params.peer ?? null,
|
||||
params.profile ?? null,
|
||||
params.seed ?? null,
|
||||
wallet,
|
||||
);
|
||||
if (params.route) {
|
||||
const { revision, path } = proj.parseRoute(
|
||||
params.route,
|
||||
project.branches,
|
||||
);
|
||||
router.updateProjectRoute({
|
||||
revision,
|
||||
path,
|
||||
hash: params.hash,
|
||||
route: undefined,
|
||||
});
|
||||
}
|
||||
if (!params.revision) {
|
||||
// We need a revision to fetch `getRoot`.
|
||||
// Don't use router.updateProjectRoute, to avoid changing the URL.
|
||||
params.revision = project.defaultBranch;
|
||||
}
|
||||
|
||||
return project;
|
||||
};
|
||||
|
||||
// Content can be altered in child components.
|
||||
$: revision = activeRoute.params.revision || null;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -24,11 +77,17 @@
|
||||
main > header {
|
||||
padding: 0 2rem 0 8rem;
|
||||
}
|
||||
main > .message {
|
||||
padding: 0 2rem 0 8rem;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
main > header {
|
||||
padding-left: 2rem;
|
||||
}
|
||||
main > .message {
|
||||
padding-left: 2rem;
|
||||
}
|
||||
main {
|
||||
padding-top: 2rem;
|
||||
min-width: 0;
|
||||
@@ -37,99 +96,107 @@
|
||||
</style>
|
||||
|
||||
<main>
|
||||
{#await Project.get(id, peer, profileName, seedHost, wallet)}
|
||||
{#await getProject(activeRoute.params)}
|
||||
<header>
|
||||
<Loading center />
|
||||
</header>
|
||||
{:then project}
|
||||
<Router>
|
||||
<!-- The default action is to render Browser with the default branch head -->
|
||||
<Route path="/">
|
||||
<ProjectRoute content={ProjectContent.Tree} {peer} {project} {wallet} />
|
||||
</Route>
|
||||
<Route path="/tree">
|
||||
<ProjectRoute content={ProjectContent.Tree} {peer} {project} {wallet} />
|
||||
</Route>
|
||||
<Route path="/tree/*" let:params let:location>
|
||||
<ProjectRoute
|
||||
route={params["*"]}
|
||||
content={ProjectContent.Tree}
|
||||
{location}
|
||||
{peer}
|
||||
{project}
|
||||
{wallet} />
|
||||
</Route>
|
||||
<ProjectMeta {project} {peer} />
|
||||
{#await project.getRoot(revision)}
|
||||
<Loading center />
|
||||
{:then { tree, commit }}
|
||||
<Header {tree} {commit} {project} {activeRoute} />
|
||||
|
||||
<Route path="/history">
|
||||
<ProjectRoute
|
||||
content={ProjectContent.History}
|
||||
{peer}
|
||||
{project}
|
||||
{wallet} />
|
||||
</Route>
|
||||
<Route path="/history/*" let:params let:location>
|
||||
<ProjectRoute
|
||||
route={params["*"]}
|
||||
content={ProjectContent.History}
|
||||
{location}
|
||||
{peer}
|
||||
{project}
|
||||
{wallet} />
|
||||
</Route>
|
||||
|
||||
<Route path="/commits/:commit" let:params>
|
||||
<ProjectRoute
|
||||
revision={params.commit}
|
||||
content={ProjectContent.Commit}
|
||||
{peer}
|
||||
{project}
|
||||
{wallet} />
|
||||
</Route>
|
||||
<Route path="/commits/*" let:params let:location>
|
||||
<ProjectRoute
|
||||
route={params["*"]}
|
||||
content={ProjectContent.Commit}
|
||||
{location}
|
||||
{peer}
|
||||
{project}
|
||||
{wallet} />
|
||||
</Route>
|
||||
|
||||
<Route path="/issues" let:location>
|
||||
<ProjectRoute
|
||||
content={ProjectContent.Issues}
|
||||
{peer}
|
||||
{project}
|
||||
{location}
|
||||
{wallet} />
|
||||
</Route>
|
||||
<Route path="/issues/:issue" let:params let:location>
|
||||
<ProjectRoute
|
||||
content={ProjectContent.Issue}
|
||||
issue={params.issue}
|
||||
{peer}
|
||||
{project}
|
||||
{location}
|
||||
{wallet} />
|
||||
</Route>
|
||||
|
||||
<Route path="/patches">
|
||||
<ProjectRoute
|
||||
content={ProjectContent.Patches}
|
||||
{peer}
|
||||
{project}
|
||||
{wallet} />
|
||||
</Route>
|
||||
<Route path="/patches/:patch" let:params>
|
||||
<ProjectRoute
|
||||
content={ProjectContent.Patch}
|
||||
patch={params.patch}
|
||||
{peer}
|
||||
{project}
|
||||
{wallet} />
|
||||
</Route>
|
||||
</Router>
|
||||
{#if activeRoute.params.view.resource === "tree"}
|
||||
<Browser {project} {commit} {tree} {activeRoute} />
|
||||
{:else if activeRoute.params.view.resource === "history"}
|
||||
{#await proj.Project.getCommits( project.urn, project.seed.api, { parent: commit, verified: true }, )}
|
||||
<Loading center />
|
||||
{:then history}
|
||||
<History {project} {history} />
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
<Message error>{e.message}</Message>
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "commits"}
|
||||
{#await project.getCommit(commit)}
|
||||
<Loading center />
|
||||
{:then commit}
|
||||
<Commit {commit} />
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
<Message error>{e.message}</Message>
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "issues"}
|
||||
{#await issue.Issue.getIssues(project.urn, project.seed.api)}
|
||||
<Loading center />
|
||||
{:then issues}
|
||||
<Issues state={issueFilter} {wallet} {issues} />
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
<Message error>{e.message}</Message>
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "issue"}
|
||||
{#await issue.Issue.getIssue(project.urn, activeRoute.params.view.params.issue, project.seed.api)}
|
||||
<Loading center />
|
||||
{:then issue}
|
||||
<Issue {project} {wallet} {issue} />
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
<Message error>{e.message}</Message>
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "patches"}
|
||||
{#await patch.Patch.getPatches(project.urn, project.seed.api)}
|
||||
<Loading center />
|
||||
{:then patches}
|
||||
<Patches {wallet} state={patchFilter} {patches} />
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
<Message error>{e.message}</Message>
|
||||
</div>
|
||||
{/await}
|
||||
{:else if activeRoute.params.view.resource === "patch"}
|
||||
{#await patch.Patch.getPatch(project.urn, activeRoute.params.view.params.patch, project.seed.api)}
|
||||
<Loading center />
|
||||
{:then patch}
|
||||
<Patch {project} {wallet} {patch} />
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
<Message error>{e.message}</Message>
|
||||
</div>
|
||||
{/await}
|
||||
{:else}
|
||||
{unreachable(activeRoute.params.view)}
|
||||
{/if}
|
||||
{:catch e}
|
||||
<div class="message">
|
||||
{#if peer}
|
||||
<Placeholder icon="🍂">
|
||||
<span slot="title">
|
||||
<span class="txt-monospace">{formatSeedId(peer)}</span>
|
||||
</span>
|
||||
<span slot="body">
|
||||
<span style="display: block">
|
||||
Couldn't load remote source tree.
|
||||
</span>
|
||||
<span>{e.message}</span>
|
||||
</span>
|
||||
</Placeholder>
|
||||
{:else}
|
||||
<Placeholder icon="🍂">
|
||||
<span slot="body">
|
||||
<span style="display: block">Couldn't load source tree.</span>
|
||||
<span>{e.message}</span>
|
||||
</span>
|
||||
</Placeholder>
|
||||
{/if}
|
||||
</div>
|
||||
{/await}
|
||||
{:catch}
|
||||
<NotFound title={id} subtitle="This project was not found." />
|
||||
<NotFound title={urn} subtitle="This project was not found." />
|
||||
{/await}
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user