From 38e40d5cfcadd2d6834fad8c4a3c9462172a0f15 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 6 Sep 2024 15:22:11 +0200 Subject: [PATCH] Query the cob counts async --- src-tauri/bindings/CobStats.ts | 6 +++++ src-tauri/bindings/SupportedPayloads.ts | 10 --------- src-tauri/src/commands/repos.rs | 22 ++++++++++++++++++ src-tauri/src/lib.rs | 1 + src-tauri/src/types/mod.rs | 1 + src-tauri/src/types/repo.rs | 10 --------- src-tauri/src/types/stats.rs | 14 ++++++++++++ src/components/RepoCard.svelte | 30 ++++++++++++++++++++----- 8 files changed, 68 insertions(+), 26 deletions(-) create mode 100644 src-tauri/bindings/CobStats.ts create mode 100644 src-tauri/src/types/stats.rs diff --git a/src-tauri/bindings/CobStats.ts b/src-tauri/bindings/CobStats.ts new file mode 100644 index 0000000..95ca6f0 --- /dev/null +++ b/src-tauri/bindings/CobStats.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type CobStats = { + issueCount: { open: number; closed: number }; + patchCount: { open: number; draft: number; archived: number; merged: number }; +}; diff --git a/src-tauri/bindings/SupportedPayloads.ts b/src-tauri/bindings/SupportedPayloads.ts index dad9ee1..c835838 100644 --- a/src-tauri/bindings/SupportedPayloads.ts +++ b/src-tauri/bindings/SupportedPayloads.ts @@ -9,16 +9,6 @@ export type SupportedPayloads = { }; meta: { head: string; - issues: { - open: number; - closed: number; - }; - patches: { - open: number; - draft: number; - archived: number; - merged: number; - }; lastCommit: number; }; }; diff --git a/src-tauri/src/commands/repos.rs b/src-tauri/src/commands/repos.rs index 62ddbe2..c2b76d5 100644 --- a/src-tauri/src/commands/repos.rs +++ b/src-tauri/src/commands/repos.rs @@ -1,3 +1,6 @@ +use radicle::issue::cache::Issues; +use radicle::patch::cache::Patches; +use radicle::prelude::RepoId; use radicle::storage::ReadStorage; use crate::error::Error; @@ -28,3 +31,22 @@ pub fn list_repos(ctx: tauri::State) -> Result(infos) } + +/// Get cob stats per repo. +#[tauri::command] +pub async fn cob_stats<'a>( + ctx: tauri::State<'a, AppState>, + rid: RepoId, +) -> Result { + let (repo, _) = ctx.repo(rid)?; + + let patches = ctx.profile.patches(&repo)?; + let patches = patches.counts()?; + let issues = ctx.profile.issues(&repo)?; + let issues = issues.counts()?; + + Ok::<_, Error>(types::stats::CobStats { + issue_count: issues, + patch_count: patches, + }) +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 07ee506..e1addc1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -107,6 +107,7 @@ pub fn run() { .invoke_handler(tauri::generate_handler![ auth::authenticate, repos::list_repos, + repos::cob_stats, profile::config, ]) .run(tauri::generate_context!()) diff --git a/src-tauri/src/types/mod.rs b/src-tauri/src/types/mod.rs index 551ac1a..f61b76a 100644 --- a/src-tauri/src/types/mod.rs +++ b/src-tauri/src/types/mod.rs @@ -1,2 +1,3 @@ pub mod config; pub mod repo; +pub mod stats; diff --git a/src-tauri/src/types/repo.rs b/src-tauri/src/types/repo.rs index 23e3506..4ff6146 100644 --- a/src-tauri/src/types/repo.rs +++ b/src-tauri/src/types/repo.rs @@ -33,16 +33,6 @@ pub struct SupportedPayloads { }, meta: { head: string, - issues: { - open: number, - closed: number, - }, - patches: { - open: number, - draft: number, - archived: number, - merged: number, - } lastCommit: number, } }"#)] diff --git a/src-tauri/src/types/stats.rs b/src-tauri/src/types/stats.rs new file mode 100644 index 0000000..045983e --- /dev/null +++ b/src-tauri/src/types/stats.rs @@ -0,0 +1,14 @@ +use serde::Serialize; +use ts_rs::TS; + +use radicle::{issue::IssueCounts, patch::PatchCounts}; + +#[derive(TS, Serialize)] +#[serde(rename_all = "camelCase")] +#[ts(export)] +pub struct CobStats { + #[ts(type = "{ open: number, closed: number }")] + pub issue_count: IssueCounts, + #[ts(type = "{ open: number, draft: number, archived: number, merged: number }")] + pub patch_count: PatchCounts, +} diff --git a/src/components/RepoCard.svelte b/src/components/RepoCard.svelte index fa9255f..be9d978 100644 --- a/src/components/RepoCard.svelte +++ b/src/components/RepoCard.svelte @@ -1,6 +1,8 @@