Skip to content

Commit

Permalink
Sort repos by activity
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Dec 5, 2024
1 parent 5c8844d commit 653cf9a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion crates/radicle-types/bindings/repo/ProjectPayloadMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
1 change: 1 addition & 0 deletions crates/radicle-types/bindings/repo/RepoInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type RepoInfo = {
visibility: Visibility;
rid: string;
seeding: number;
lastCommitTimestamp: number;
};
5 changes: 3 additions & 2 deletions crates/radicle-types/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions crates/radicle-types/src/traits/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -97,12 +97,12 @@ pub trait Repo: Profile {
.collect::<Vec<_>>();
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()?;
Expand All @@ -113,7 +113,6 @@ pub trait Repo: Profile {
issues,
patches,
head,
last_commit_timestamp: commit.time().seconds() * 1000,
};

Some(repo::ProjectPayload::new(data, meta))
Expand All @@ -126,6 +125,7 @@ pub trait Repo: Profile {
visibility: doc.visibility().clone().into(),
rid: repo.id,
seeding,
last_commit_timestamp: commit.time().seconds() * 1000,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/RepoCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</div>
</div>
<span style:color="var(--color-fill-gray)">
Updated {formatTimestamp(project.meta.lastCommitTimestamp)}
Updated {formatTimestamp(repo.lastCommitTimestamp)}
</span>
</div>
</div>
Expand Down

0 comments on commit 653cf9a

Please sign in to comment.