mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-15 11:20:36 +08:00
Introduce TreeView and HistoryView
Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
This commit is contained in:
@@ -14,16 +14,13 @@
|
||||
import TreeComponent from "./Tree.svelte";
|
||||
|
||||
export let baseUrl: BaseUrl;
|
||||
export let branches: Record<string, string> | undefined;
|
||||
export let commitCount: number;
|
||||
export let contributorCount: number;
|
||||
export let branches: string[];
|
||||
export let path: string;
|
||||
export let peer: string | undefined;
|
||||
export let peers: Remote[];
|
||||
export let project: Project;
|
||||
export let revision: string | undefined;
|
||||
export let tree: Tree;
|
||||
|
||||
export let blobResult: BlobResult;
|
||||
|
||||
// Whether the mobile file tree is visible.
|
||||
@@ -57,7 +54,7 @@
|
||||
} as Route,
|
||||
}));
|
||||
|
||||
$: branchesWithRoute = Object.keys(branches || {}).map(name => ({
|
||||
$: branchesWithRoute = branches.map(name => ({
|
||||
name,
|
||||
route: {
|
||||
resource: "project.tree",
|
||||
@@ -154,8 +151,8 @@
|
||||
projectId={project.id}
|
||||
{baseUrl}
|
||||
branches={branchesWithRoute}
|
||||
{commitCount}
|
||||
{contributorCount}
|
||||
commitCount={tree.stats.commits}
|
||||
contributorCount={tree.stats.contributors}
|
||||
peers={peersWithRoute}
|
||||
{revision}
|
||||
historyLinkActive={false} />
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl, CommitHeader, Project, Remote } from "@httpd-client";
|
||||
import type {
|
||||
BaseUrl,
|
||||
CommitHeader,
|
||||
Project,
|
||||
Remote,
|
||||
Tree,
|
||||
} from "@httpd-client";
|
||||
import type { Route } from "@app/lib/router";
|
||||
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
@@ -13,15 +19,14 @@
|
||||
import { COMMITS_PER_PAGE } from "./router";
|
||||
|
||||
export let baseUrl: BaseUrl;
|
||||
export let branches: Record<string, string> | undefined;
|
||||
export let commitCount: number;
|
||||
export let branches: string[];
|
||||
export let commitHeaders: CommitHeader[];
|
||||
export let contributorCount: number;
|
||||
export let peer: string | undefined;
|
||||
export let peers: Remote[];
|
||||
export let project: Project;
|
||||
export let revision: string | undefined;
|
||||
export let totalCommitCount: number;
|
||||
export let tree: Tree;
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
@@ -66,7 +71,7 @@
|
||||
} as Route,
|
||||
}));
|
||||
|
||||
$: branchesWithRoute = Object.keys(branches || {}).map(name => ({
|
||||
$: branchesWithRoute = branches.map(name => ({
|
||||
name,
|
||||
route: {
|
||||
resource: "project.history",
|
||||
@@ -109,8 +114,8 @@
|
||||
commitId={commitHeaders[0].id}
|
||||
{baseUrl}
|
||||
branches={branchesWithRoute}
|
||||
{commitCount}
|
||||
{contributorCount}
|
||||
commitCount={tree.stats.commits}
|
||||
contributorCount={tree.stats.contributors}
|
||||
peers={peersWithRoute}
|
||||
{revision}
|
||||
historyLinkActive={true} />
|
||||
|
||||
@@ -62,30 +62,9 @@
|
||||
|
||||
<main>
|
||||
{#if view.resource === "tree"}
|
||||
<Browser
|
||||
blobResult={view.blobResult}
|
||||
branches={view.params.loadedBranches}
|
||||
commitCount={view.params.loadedTree.stats.commits}
|
||||
contributorCount={view.params.loadedTree.stats.contributors}
|
||||
path={view.path}
|
||||
peers={view.params.loadedPeers}
|
||||
tree={view.params.loadedTree}
|
||||
{baseUrl}
|
||||
{peer}
|
||||
{project}
|
||||
revision={view.revision} />
|
||||
<Browser {...view} {baseUrl} {project} />
|
||||
{:else if view.resource === "history"}
|
||||
<History
|
||||
branches={view.params.loadedBranches}
|
||||
commitCount={view.params.loadedTree.stats.commits}
|
||||
commitHeaders={view.commitHeaders}
|
||||
contributorCount={view.params.loadedTree.stats.contributors}
|
||||
peers={view.params.loadedPeers}
|
||||
totalCommitCount={view.totalCommitCount}
|
||||
{baseUrl}
|
||||
{peer}
|
||||
{project}
|
||||
revision={view.revision} />
|
||||
<History {...view} {baseUrl} {project} />
|
||||
{:else if view.resource === "commit"}
|
||||
<Commit commit={view.commit} {baseUrl} {project} />
|
||||
{:else if view.resource === "issues"}
|
||||
|
||||
@@ -108,22 +108,8 @@ export interface ProjectLoadedParams {
|
||||
}
|
||||
|
||||
export type ProjectLoadedView =
|
||||
| {
|
||||
resource: "tree";
|
||||
peer: string | undefined;
|
||||
revision: string | undefined;
|
||||
params: LoadedSourceBrowsingParams;
|
||||
path: string;
|
||||
blobResult: BlobResult;
|
||||
}
|
||||
| {
|
||||
resource: "history";
|
||||
peer: string | undefined;
|
||||
revision: string | undefined;
|
||||
params: LoadedSourceBrowsingParams;
|
||||
commitHeaders: CommitHeader[];
|
||||
totalCommitCount: number;
|
||||
}
|
||||
| TreeView
|
||||
| HistoryView
|
||||
| {
|
||||
resource: "commit";
|
||||
commit: Commit;
|
||||
@@ -134,16 +120,32 @@ export type ProjectLoadedView =
|
||||
| { resource: "patches"; patches: Patch[]; state: PatchState["status"] }
|
||||
| PatchView;
|
||||
|
||||
interface LoadedSourceBrowsingParams {
|
||||
loadedBranches: Record<string, string> | undefined;
|
||||
loadedPeers: Remote[];
|
||||
loadedTree: Tree;
|
||||
export interface TreeView {
|
||||
resource: "tree";
|
||||
peers: Remote[];
|
||||
peer: string | undefined;
|
||||
branches: string[];
|
||||
revision: string | undefined;
|
||||
tree: Tree;
|
||||
path: string;
|
||||
blobResult: BlobResult;
|
||||
}
|
||||
|
||||
export type BlobResult =
|
||||
| { ok: true; blob: Blob; highlighted: Syntax.Root | undefined }
|
||||
| { ok: false; error: { message: string; path: string } };
|
||||
|
||||
export interface HistoryView {
|
||||
resource: "history";
|
||||
peers: Remote[];
|
||||
peer: string | undefined;
|
||||
branches: string[];
|
||||
revision: string | undefined;
|
||||
tree: Tree;
|
||||
commitHeaders: CommitHeader[];
|
||||
totalCommitCount: number;
|
||||
}
|
||||
|
||||
export interface PatchView {
|
||||
resource: "patch";
|
||||
patch: Patch;
|
||||
@@ -347,7 +349,7 @@ async function loadTreeView(
|
||||
): Promise<ProjectLoadedRoute> {
|
||||
const api = new HttpdClient(route.seed);
|
||||
|
||||
const [project, peers, branches] = await Promise.all([
|
||||
const [project, peers, branchMap] = await Promise.all([
|
||||
api.project.getById(route.project),
|
||||
api.project.getAllRemotes(route.project),
|
||||
getPeerBranches(api, route.project, route.peer),
|
||||
@@ -356,7 +358,7 @@ async function loadTreeView(
|
||||
if (route.route) {
|
||||
const { revision, path } = detectRevision(
|
||||
route.route,
|
||||
branches || { [project.defaultBranch]: project.head },
|
||||
branchMap || { [project.defaultBranch]: project.head },
|
||||
);
|
||||
route.revision = revision;
|
||||
route.path = path;
|
||||
@@ -365,7 +367,7 @@ async function loadTreeView(
|
||||
const commit = parseRevisionToOid(
|
||||
route.revision,
|
||||
project.defaultBranch,
|
||||
branches || { [project.defaultBranch]: project.head },
|
||||
branchMap || { [project.defaultBranch]: project.head },
|
||||
);
|
||||
|
||||
const path = route.path || "/";
|
||||
@@ -382,13 +384,11 @@ async function loadTreeView(
|
||||
project,
|
||||
view: {
|
||||
resource: "tree",
|
||||
peers,
|
||||
peer: route.peer,
|
||||
branches: Object.keys(branchMap || {}),
|
||||
revision: route.revision,
|
||||
params: {
|
||||
loadedBranches: branches,
|
||||
loadedPeers: peers,
|
||||
loadedTree: tree,
|
||||
},
|
||||
tree,
|
||||
path,
|
||||
blobResult,
|
||||
},
|
||||
@@ -441,7 +441,7 @@ async function loadHistoryView(
|
||||
): Promise<ProjectLoadedRoute> {
|
||||
const api = new HttpdClient(route.seed);
|
||||
|
||||
const [project, peers, branches] = await Promise.all([
|
||||
const [project, peers, branchMap] = await Promise.all([
|
||||
api.project.getById(route.project),
|
||||
api.project.getAllRemotes(route.project),
|
||||
getPeerBranches(api, route.project, route.peer),
|
||||
@@ -450,8 +450,8 @@ async function loadHistoryView(
|
||||
let commitId;
|
||||
if (route.revision && isOid(route.revision)) {
|
||||
commitId = route.revision;
|
||||
} else if (branches) {
|
||||
commitId = branches[route.revision || project.defaultBranch];
|
||||
} else if (branchMap) {
|
||||
commitId = branchMap[route.revision || project.defaultBranch];
|
||||
} else if (!route.revision) {
|
||||
commitId = project.head;
|
||||
}
|
||||
@@ -479,13 +479,11 @@ async function loadHistoryView(
|
||||
project,
|
||||
view: {
|
||||
resource: "history",
|
||||
peers,
|
||||
peer: route.peer,
|
||||
branches: Object.keys(branchMap || {}),
|
||||
revision: route.revision,
|
||||
params: {
|
||||
loadedBranches: branches,
|
||||
loadedPeers: peers,
|
||||
loadedTree: tree,
|
||||
},
|
||||
tree,
|
||||
commitHeaders: commitsResponse.commits.map(c => c.commit),
|
||||
totalCommitCount: commitsResponse.stats.commits,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user