Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Sort node projects by HEAD commit time
Sebastian Martinez committed 2 years ago
commit 2c81228db69b66e474a2dd533f01319cf4a7a4e5
parent 0c0842e6f34a84530c2f3609d6306daf7908447f
3 files changed +26 -43
modified httpd-client/lib/project.ts
@@ -25,6 +25,7 @@ import {
  object,
  string,
  union,
+
  z,
} from "zod";

import {
@@ -46,26 +47,6 @@ import {
  patchCreatedSchema,
} from "./project/patch.js";

-
export interface Project {
-
  id: string;
-
  name: string;
-
  description: string;
-
  defaultBranch: string;
-
  delegates: string[];
-
  head: string;
-
  patches: {
-
    open: number;
-
    draft: number;
-
    archived: number;
-
    merged: number;
-
  };
-
  issues: {
-
    open: number;
-
    closed: number;
-
  };
-
  trackings: number;
-
}
-

const projectSchema = object({
  id: string(),
  name: string(),
@@ -84,25 +65,16 @@ const projectSchema = object({
    closed: number(),
  }),
  trackings: number(),
-
}) satisfies ZodSchema<Project>;
+
});
+
const projectsSchema = array(projectSchema);

-
const projectsSchema = array(projectSchema) satisfies ZodSchema<Project[]>;
-

-
export interface Activity {
-
  activity: number[];
-
}
+
export type Project = z.infer<typeof projectSchema>;

const activitySchema = object({
  activity: array(number()),
-
}) satisfies ZodSchema<Activity>;
+
});

-
export interface Blob {
-
  binary: boolean;
-
  content?: string;
-
  name: string;
-
  path: string;
-
  lastCommit: CommitHeader;
-
}
+
export type Activity = z.infer<typeof activitySchema>;

const blobSchema = object({
  binary: boolean(),
@@ -110,19 +82,17 @@ const blobSchema = object({
  name: string(),
  path: string(),
  lastCommit: commitHeaderSchema,
-
}) satisfies ZodSchema<Blob>;
+
});

-
interface TreeEntry {
-
  path: string;
-
  name: string;
-
  kind: "tree" | "blob";
-
}
+
export type Blob = z.infer<typeof blobSchema>;

const treeEntrySchema = object({
  path: string(),
  name: string(),
  kind: union([literal("blob"), literal("tree")]),
-
}) satisfies ZodSchema<TreeEntry>;
+
});
+

+
export type TreeEntry = z.infer<typeof treeEntrySchema>;

export interface TreeStats {
  commits: number;
modified src/views/nodes/View.svelte
@@ -29,6 +29,11 @@
      const result = await loadProjects(projectPageIndex, baseUrl);
      projectCount = result.total;
      projects = [...projects, ...result.projects];
+
      projects.sort(
+
        (a, b) =>
+
          b.latestCommitHeader.committer.time -
+
          a.latestCommitHeader.committer.time,
+
      );
      projectPageIndex += 1;
    } catch (err) {
      error = err;
modified src/views/nodes/router.ts
@@ -1,4 +1,4 @@
-
import type { BaseUrl, Project } from "@httpd-client";
+
import type { BaseUrl, CommitHeader, Project } from "@httpd-client";
import type { NotFoundRoute } from "@app/lib/router/definitions";
import type { WeeklyActivity } from "@app/lib/commit";

@@ -13,6 +13,7 @@ export interface NodesRouteParams {

export interface ProjectActivity {
  project: Project;
+
  latestCommitHeader: CommitHeader;
  activity: WeeklyActivity[];
}

@@ -52,15 +53,22 @@ export async function loadProjects(
  const results = await Promise.all(
    projects.map(async project => {
      const activity = await loadProjectActivity(project.id, baseUrl);
+
      const { commit: latestCommitHeader } = await api.project.getCommitBySha(
+
        project.id,
+
        project.head,
+
      );
      return {
        project,
+
        latestCommitHeader,
        activity,
      };
    }),
  );
+

  // Sorts projects by most recent commit descending.
  const sortedProjects = results.sort(
-
    (a, b) => b.activity[0]?.time - a.activity[0]?.time,
+
    (a, b) =>
+
      b.latestCommitHeader.committer.time - a.latestCommitHeader.committer.time,
  );

  return {