Skip to content

Commit

Permalink
Query the cob counts async
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Sep 6, 2024
1 parent 0a059da commit 38e40d5
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src-tauri/bindings/CobStats.ts
Original file line number Diff line number Diff line change
@@ -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 };
};
10 changes: 0 additions & 10 deletions src-tauri/bindings/SupportedPayloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
Expand Down
22 changes: 22 additions & 0 deletions src-tauri/src/commands/repos.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,3 +31,22 @@ pub fn list_repos(ctx: tauri::State<AppState>) -> Result<Vec<types::repo::RepoIn

Ok::<_, Error>(infos)
}

/// Get cob stats per repo.
#[tauri::command]
pub async fn cob_stats<'a>(
ctx: tauri::State<'a, AppState>,
rid: RepoId,
) -> Result<types::stats::CobStats, Error> {
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,
})
}
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!())
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod config;
pub mod repo;
pub mod stats;
10 changes: 0 additions & 10 deletions src-tauri/src/types/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}"#)]
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/types/stats.rs
Original file line number Diff line number Diff line change
@@ -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,
}
30 changes: 24 additions & 6 deletions src/components/RepoCard.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import type { RepoInfo } from "@bindings/RepoInfo";
import type { CobStats } from "@bindings/CobStats";
import { invoke } from "@tauri-apps/api/core";
import { formatRepositoryId, formatTimestamp } from "@app/lib/utils";
import Border from "./Border.svelte";
Expand Down Expand Up @@ -29,6 +31,11 @@
.container {
width: 100%;
}
.placeholder {
width: 1rem;
height: 1rem;
background-color: var(--color-fill-ghost);
}
</style>

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

<div class="global-flex footer">
<div class="global-flex">
<div class="global-flex" style:gap="4px">
<Icon name="issue" />{project.meta.issues.open}
</div>
<div class="global-flex" style:gap="4px">
<Icon name="patch" />{project.meta.patches.open}
</div>
{#await invoke<CobStats>("cob_stats", { rid: repo.rid })}
<div class="global-flex" style:gap="4px">
<Icon name="issue" />
<div class="placeholder"></div>
</div>
<div class="global-flex" style:gap="4px">
<Icon name="patch" />
<div class="placeholder"></div>
</div>
{:then { issueCount, patchCount }}
<div class="global-flex" style:gap="4px">
<Icon name="issue" />{issueCount.open}
</div>
<div class="global-flex" style:gap="4px">
<Icon name="patch" />{patchCount.open}
</div>
{/await}
</div>
<span style:color="var(--color-fill-gray)">
Updated {formatTimestamp(project.meta.lastCommit)}
Expand Down

0 comments on commit 38e40d5

Please sign in to comment.