Radish alpha
r
rad:z4D5UCArafTzTQpDZNQRuqswh3ury
Radicle desktop app
Radicle
Git
Add list_repos_summary Tauri command
Rūdolfs Ošiņš committed 1 month ago
commit 8b2df264af211bb0bfbec96e467e8e1de2d94064
parent a6af849
6 files changed +52 -0
modified crates/radicle-tauri/src/commands/repo.rs
@@ -23,6 +23,13 @@ pub fn list_repos(
}

#[tauri::command]
+
pub fn list_repos_summary(
+
    ctx: tauri::State<AppState>,
+
) -> Result<Vec<types::repo::RepoSummary>, Error> {
+
    ctx.list_repos_summary()
+
}
+

+
#[tauri::command]
pub fn repo_count(ctx: tauri::State<AppState>) -> Result<types::repo::RepoCount, Error> {
    ctx.repo_count()
}
modified crates/radicle-tauri/src/lib.rs
@@ -58,6 +58,7 @@ pub fn run() {
            repo::diff_stats,
            repo::list_commits,
            repo::list_repos,
+
            repo::list_repos_summary,
            repo::repo_by_id,
            repo::repo_count,
            repo::repo_readme,
added crates/radicle-types/bindings/repo/RepoSummary.ts
@@ -0,0 +1,3 @@
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
+

+
export type RepoSummary = { rid: string; name: string };
modified crates/radicle-types/src/repo.rs
@@ -13,6 +13,16 @@ use crate::error;
#[serde(rename_all = "camelCase")]
#[ts(export)]
#[ts(export_to = "repo/")]
+
pub struct RepoSummary {
+
    #[ts(as = "String")]
+
    pub rid: identity::RepoId,
+
    pub name: String,
+
}
+

+
#[derive(Serialize, TS)]
+
#[serde(rename_all = "camelCase")]
+
#[ts(export)]
+
#[ts(export_to = "repo/")]
pub struct RepoCount {
    pub total: usize,
    pub contributor: usize,
modified crates/radicle-types/src/traits/repo.rs
@@ -73,6 +73,31 @@ pub trait Repo: Profile {
        Ok::<_, Error>(entries)
    }

+
    fn list_repos_summary(&self) -> Result<Vec<repo::RepoSummary>, Error> {
+
        let profile = self.profile();
+
        let storage = &profile.storage;
+
        let repos = storage.repositories()?;
+
        let mut entries = Vec::new();
+

+
        for RepositoryInfo { rid, doc, .. } in repos {
+
            let Some(data) = doc
+
                .payload()
+
                .get(&doc::PayloadId::project())
+
                .and_then(|payload| repo::ProjectPayloadData::try_from((*payload).clone()).ok())
+
            else {
+
                continue;
+
            };
+
            entries.push(repo::RepoSummary {
+
                rid,
+
                name: data.name,
+
            });
+
        }
+

+
        entries.sort_by_key(|r| r.name.to_lowercase());
+

+
        Ok::<_, Error>(entries)
+
    }
+

    fn repo_count(&self) -> Result<repo::RepoCount, Error> {
        let profile = self.profile();
        let storage = &profile.storage;
modified crates/test-http-api/src/api.rs
@@ -63,6 +63,7 @@ pub fn router(ctx: Context) -> Router {
        .route("/authenticate", post(auth_handler))
        .route("/repo_count", post(repo_count_handler))
        .route("/list_repos", post(repo_root_handler))
+
        .route("/list_repos_summary", post(list_repos_summary_handler))
        .route("/repo_by_id", post(repo_handler))
        .route("/version", post(version_handler))
        .route("/diff_stats", post(diff_stats_handler))
@@ -131,6 +132,11 @@ async fn repo_count_handler(State(ctx): State<Context>) -> impl IntoResponse {
    Ok::<_, Error>(Json(repos))
}

+
async fn list_repos_summary_handler(State(ctx): State<Context>) -> impl IntoResponse {
+
    let repos = ctx.list_repos_summary()?;
+
    Ok::<_, Error>(Json(repos))
+
}
+

#[derive(Serialize, Deserialize)]
struct RepoBody {
    pub rid: identity::RepoId,