From 653cf9a48d11dd67fddbbbc6f6a195223bf1445d Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 5 Dec 2024 13:45:43 +0100 Subject: [PATCH] Sort repos by activity --- crates/radicle-types/bindings/repo/ProjectPayloadMeta.ts | 1 - crates/radicle-types/bindings/repo/RepoInfo.ts | 1 + crates/radicle-types/src/repo.rs | 5 +++-- crates/radicle-types/src/traits/repo.rs | 8 ++++---- src/components/RepoCard.svelte | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/radicle-types/bindings/repo/ProjectPayloadMeta.ts b/crates/radicle-types/bindings/repo/ProjectPayloadMeta.ts index 1edd910..3a4bcab 100644 --- a/crates/radicle-types/bindings/repo/ProjectPayloadMeta.ts +++ b/crates/radicle-types/bindings/repo/ProjectPayloadMeta.ts @@ -4,5 +4,4 @@ export type ProjectPayloadMeta = { head: string; issues: { open: number; closed: number }; patches: { open: number; draft: number; archived: number; merged: number }; - lastCommitTimestamp: number; }; diff --git a/crates/radicle-types/bindings/repo/RepoInfo.ts b/crates/radicle-types/bindings/repo/RepoInfo.ts index 9c5f701..4a27623 100644 --- a/crates/radicle-types/bindings/repo/RepoInfo.ts +++ b/crates/radicle-types/bindings/repo/RepoInfo.ts @@ -10,4 +10,5 @@ export type RepoInfo = { visibility: Visibility; rid: string; seeding: number; + lastCommitTimestamp: number; }; diff --git a/crates/radicle-types/src/repo.rs b/crates/radicle-types/src/repo.rs index a8717b6..5ce6073 100644 --- a/crates/radicle-types/src/repo.rs +++ b/crates/radicle-types/src/repo.rs @@ -10,6 +10,7 @@ use crate::cobs::Author; use crate::error; #[derive(Serialize, TS)] +#[serde(rename_all = "camelCase")] #[ts(export)] #[ts(export_to = "repo/")] pub struct RepoInfo { @@ -20,6 +21,8 @@ pub struct RepoInfo { #[ts(as = "String")] pub rid: identity::RepoId, pub seeding: usize, + #[ts(type = "number")] + pub last_commit_timestamp: i64, } #[derive(Default, Serialize, TS)] @@ -110,8 +113,6 @@ pub struct ProjectPayloadMeta { pub issues: issue::IssueCounts, #[ts(type = "{ open: number, draft: number, archived: number, merged: number }")] pub patches: patch::PatchCounts, - #[ts(type = "number")] - pub last_commit_timestamp: i64, } #[derive(Clone, Serialize, TS, Debug, PartialEq)] diff --git a/crates/radicle-types/src/traits/repo.rs b/crates/radicle-types/src/traits/repo.rs index 06b1730..61a76f2 100644 --- a/crates/radicle-types/src/traits/repo.rs +++ b/crates/radicle-types/src/traits/repo.rs @@ -49,7 +49,7 @@ pub trait Repo: Profile { entries.push(repo_info) } - entries.sort_by_key(|repo::RepoInfo { rid, .. }| *rid); + entries.sort_by(|a, b| b.last_commit_timestamp.cmp(&a.last_commit_timestamp)); Ok::<_, Error>(entries) } @@ -97,12 +97,12 @@ pub trait Repo: Profile { .collect::>(); let db = profile.database()?; let seeding = db.count(&repo.id).unwrap_or_default(); + let (_, head) = repo.head()?; + let commit = repo.commit(head)?; let project = doc .payload() .get(&doc::PayloadId::project()) .and_then(|payload| { - let (_, head) = repo.head().ok()?; - let commit = repo.commit(head).ok()?; let patches = profile.patches(repo).ok()?; let patches = patches.counts().ok()?; let issues = profile.issues(repo).ok()?; @@ -113,7 +113,6 @@ pub trait Repo: Profile { issues, patches, head, - last_commit_timestamp: commit.time().seconds() * 1000, }; Some(repo::ProjectPayload::new(data, meta)) @@ -126,6 +125,7 @@ pub trait Repo: Profile { visibility: doc.visibility().clone().into(), rid: repo.id, seeding, + last_commit_timestamp: commit.time().seconds() * 1000, }) } diff --git a/src/components/RepoCard.svelte b/src/components/RepoCard.svelte index d6076da..751beb1 100644 --- a/src/components/RepoCard.svelte +++ b/src/components/RepoCard.svelte @@ -68,7 +68,7 @@ - Updated {formatTimestamp(project.meta.lastCommitTimestamp)} + Updated {formatTimestamp(repo.lastCommitTimestamp)}