Skip to content

Commit 38e40d5

Browse files
committed
Query the cob counts async
1 parent 0a059da commit 38e40d5

File tree

8 files changed

+68
-26
lines changed

8 files changed

+68
-26
lines changed

src-tauri/bindings/CobStats.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
3+
export type CobStats = {
4+
issueCount: { open: number; closed: number };
5+
patchCount: { open: number; draft: number; archived: number; merged: number };
6+
};

src-tauri/bindings/SupportedPayloads.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@ export type SupportedPayloads = {
99
};
1010
meta: {
1111
head: string;
12-
issues: {
13-
open: number;
14-
closed: number;
15-
};
16-
patches: {
17-
open: number;
18-
draft: number;
19-
archived: number;
20-
merged: number;
21-
};
2212
lastCommit: number;
2313
};
2414
};

src-tauri/src/commands/repos.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use radicle::issue::cache::Issues;
2+
use radicle::patch::cache::Patches;
3+
use radicle::prelude::RepoId;
14
use radicle::storage::ReadStorage;
25

36
use crate::error::Error;
@@ -28,3 +31,22 @@ pub fn list_repos(ctx: tauri::State<AppState>) -> Result<Vec<types::repo::RepoIn
2831

2932
Ok::<_, Error>(infos)
3033
}
34+
35+
/// Get cob stats per repo.
36+
#[tauri::command]
37+
pub async fn cob_stats<'a>(
38+
ctx: tauri::State<'a, AppState>,
39+
rid: RepoId,
40+
) -> Result<types::stats::CobStats, Error> {
41+
let (repo, _) = ctx.repo(rid)?;
42+
43+
let patches = ctx.profile.patches(&repo)?;
44+
let patches = patches.counts()?;
45+
let issues = ctx.profile.issues(&repo)?;
46+
let issues = issues.counts()?;
47+
48+
Ok::<_, Error>(types::stats::CobStats {
49+
issue_count: issues,
50+
patch_count: patches,
51+
})
52+
}

src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub fn run() {
107107
.invoke_handler(tauri::generate_handler![
108108
auth::authenticate,
109109
repos::list_repos,
110+
repos::cob_stats,
110111
profile::config,
111112
])
112113
.run(tauri::generate_context!())

src-tauri/src/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod config;
22
pub mod repo;
3+
pub mod stats;

src-tauri/src/types/repo.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ pub struct SupportedPayloads {
3333
},
3434
meta: {
3535
head: string,
36-
issues: {
37-
open: number,
38-
closed: number,
39-
},
40-
patches: {
41-
open: number,
42-
draft: number,
43-
archived: number,
44-
merged: number,
45-
}
4636
lastCommit: number,
4737
}
4838
}"#)]

src-tauri/src/types/stats.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use serde::Serialize;
2+
use ts_rs::TS;
3+
4+
use radicle::{issue::IssueCounts, patch::PatchCounts};
5+
6+
#[derive(TS, Serialize)]
7+
#[serde(rename_all = "camelCase")]
8+
#[ts(export)]
9+
pub struct CobStats {
10+
#[ts(type = "{ open: number, closed: number }")]
11+
pub issue_count: IssueCounts,
12+
#[ts(type = "{ open: number, draft: number, archived: number, merged: number }")]
13+
pub patch_count: PatchCounts,
14+
}

src/components/RepoCard.svelte

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
22
import type { RepoInfo } from "@bindings/RepoInfo";
3+
import type { CobStats } from "@bindings/CobStats";
34
5+
import { invoke } from "@tauri-apps/api/core";
46
import { formatRepositoryId, formatTimestamp } from "@app/lib/utils";
57
68
import Border from "./Border.svelte";
@@ -29,6 +31,11 @@
2931
.container {
3032
width: 100%;
3133
}
34+
.placeholder {
35+
width: 1rem;
36+
height: 1rem;
37+
background-color: var(--color-fill-ghost);
38+
}
3239
</style>
3340

3441
<Border variant="ghost" styleWidth="100%" stylePadding="8px 12px" hoverable>
@@ -74,12 +81,23 @@
7481

7582
<div class="global-flex footer">
7683
<div class="global-flex">
77-
<div class="global-flex" style:gap="4px">
78-
<Icon name="issue" />{project.meta.issues.open}
79-
</div>
80-
<div class="global-flex" style:gap="4px">
81-
<Icon name="patch" />{project.meta.patches.open}
82-
</div>
84+
{#await invoke<CobStats>("cob_stats", { rid: repo.rid })}
85+
<div class="global-flex" style:gap="4px">
86+
<Icon name="issue" />
87+
<div class="placeholder"></div>
88+
</div>
89+
<div class="global-flex" style:gap="4px">
90+
<Icon name="patch" />
91+
<div class="placeholder"></div>
92+
</div>
93+
{:then { issueCount, patchCount }}
94+
<div class="global-flex" style:gap="4px">
95+
<Icon name="issue" />{issueCount.open}
96+
</div>
97+
<div class="global-flex" style:gap="4px">
98+
<Icon name="patch" />{patchCount.open}
99+
</div>
100+
{/await}
83101
</div>
84102
<span style:color="var(--color-fill-gray)">
85103
Updated {formatTimestamp(project.meta.lastCommit)}

0 commit comments

Comments
 (0)