diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index ad1079f..44faa3d 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1,5 +1,5 @@ pub mod auth; -pub mod cobs; +pub mod cob; pub mod profile; -pub mod repos; +pub mod repo; pub mod thread; diff --git a/src-tauri/src/commands/cob.rs b/src-tauri/src/commands/cob.rs new file mode 100644 index 0000000..d21c3c3 --- /dev/null +++ b/src-tauri/src/commands/cob.rs @@ -0,0 +1,51 @@ +pub mod issue; +pub mod patch; + +mod query { + use serde::{Deserialize, Serialize}; + + use radicle::issue; + use radicle::patch; + + #[derive(Default, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] + pub enum IssueStatus { + Closed, + #[default] + Open, + All, + } + + impl IssueStatus { + pub fn matches(&self, issue: &issue::State) -> bool { + match self { + Self::Open => matches!(issue, issue::State::Open), + Self::Closed => matches!(issue, issue::State::Closed { .. }), + Self::All => true, + } + } + } + + #[derive(Default, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] + pub enum PatchStatus { + #[default] + Open, + Draft, + Archived, + Merged, + All, + } + + impl PatchStatus { + pub fn matches(&self, patch: &patch::State) -> bool { + match self { + Self::Open => matches!(patch, patch::State::Open { .. }), + Self::Draft => matches!(patch, patch::State::Draft), + Self::Archived => matches!(patch, patch::State::Archived), + Self::Merged => matches!(patch, patch::State::Merged { .. }), + Self::All => true, + } + } + } +} diff --git a/src-tauri/src/commands/cob/issue.rs b/src-tauri/src/commands/cob/issue.rs new file mode 100644 index 0000000..edaf2cc --- /dev/null +++ b/src-tauri/src/commands/cob/issue.rs @@ -0,0 +1,50 @@ +use radicle::git::Oid; +use radicle::identity::RepoId; +use radicle::issue::cache::Issues; + +use crate::cob::query; +use crate::error::Error; +use crate::types::cobs; +use crate::AppState; + +#[tauri::command] +pub fn list_issues( + ctx: tauri::State, + rid: RepoId, + status: query::IssueStatus, +) -> Result, Error> { + let (repo, _) = ctx.repo(rid)?; + let issues = ctx.profile.issues(&repo)?; + let mut issues: Vec<_> = issues + .list()? + .filter_map(|r| { + let (id, issue) = r.ok()?; + (status.matches(issue.state())).then_some((id, issue)) + }) + .collect::>(); + + issues.sort_by(|(_, a), (_, b)| b.timestamp().cmp(&a.timestamp())); + let aliases = &ctx.profile.aliases(); + let issues = issues + .into_iter() + .map(|(id, issue)| cobs::Issue::new(id, issue, aliases)) + .collect::>(); + + Ok::<_, Error>(issues) +} + +#[tauri::command] +pub fn issue_by_id( + ctx: tauri::State, + rid: RepoId, + id: Oid, +) -> Result, Error> { + let (repo, _) = ctx.repo(rid)?; + let issues = ctx.profile.issues(&repo)?; + let issue = issues.get(&id.into())?; + + let aliases = &ctx.profile.aliases(); + let issue = issue.map(|issue| cobs::Issue::new(id.into(), issue, aliases)); + + Ok::<_, Error>(issue) +} diff --git a/src-tauri/src/commands/cobs.rs b/src-tauri/src/commands/cob/patch.rs similarity index 50% rename from src-tauri/src/commands/cobs.rs rename to src-tauri/src/commands/cob/patch.rs index 39a5a35..31f2ac3 100644 --- a/src-tauri/src/commands/cobs.rs +++ b/src-tauri/src/commands/cob/patch.rs @@ -3,55 +3,13 @@ use std::str::FromStr; use radicle::cob::ObjectId; use radicle::git::Oid; use radicle::identity::RepoId; -use radicle::issue::cache::Issues; use radicle::patch::cache::Patches; +use crate::cob::query; use crate::error::Error; use crate::types::cobs; use crate::AppState; -#[tauri::command] -pub fn list_issues( - ctx: tauri::State, - rid: RepoId, - status: query::IssueStatus, -) -> Result, Error> { - let (repo, _) = ctx.repo(rid)?; - let issues = ctx.profile.issues(&repo)?; - let mut issues: Vec<_> = issues - .list()? - .filter_map(|r| { - let (id, issue) = r.ok()?; - (status.matches(issue.state())).then_some((id, issue)) - }) - .collect::>(); - - issues.sort_by(|(_, a), (_, b)| b.timestamp().cmp(&a.timestamp())); - let aliases = &ctx.profile.aliases(); - let issues = issues - .into_iter() - .map(|(id, issue)| cobs::Issue::new(id, issue, aliases)) - .collect::>(); - - Ok::<_, Error>(issues) -} - -#[tauri::command] -pub fn issues_by_id( - ctx: tauri::State, - rid: RepoId, - id: Oid, -) -> Result, Error> { - let (repo, _) = ctx.repo(rid)?; - let issues = ctx.profile.issues(&repo)?; - let issue = issues.get(&id.into())?; - - let aliases = &ctx.profile.aliases(); - let issue = issue.map(|issue| cobs::Issue::new(id.into(), issue, aliases)); - - Ok::<_, Error>(issue) -} - #[tauri::command] pub fn list_patches( ctx: tauri::State, @@ -79,7 +37,7 @@ pub fn list_patches( } #[tauri::command] -pub fn patches_by_id( +pub fn patch_by_id( ctx: tauri::State, rid: RepoId, id: String, @@ -118,7 +76,7 @@ pub fn revisions_by_patch( } #[tauri::command] -pub fn revisions_by_id( +pub fn revision_by_patch_and_id( ctx: tauri::State, rid: RepoId, id: String, @@ -137,52 +95,3 @@ pub fn revisions_by_id( }); Ok::<_, Error>(revision) } - -mod query { - use serde::{Deserialize, Serialize}; - - use radicle::issue; - use radicle::patch; - - #[derive(Default, Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] - pub enum IssueStatus { - Closed, - #[default] - Open, - All, - } - - impl IssueStatus { - pub fn matches(&self, issue: &issue::State) -> bool { - match self { - Self::Open => matches!(issue, issue::State::Open), - Self::Closed => matches!(issue, issue::State::Closed { .. }), - Self::All => true, - } - } - } - - #[derive(Default, Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] - pub enum PatchStatus { - #[default] - Open, - Draft, - Archived, - Merged, - All, - } - - impl PatchStatus { - pub fn matches(&self, patch: &patch::State) -> bool { - match self { - Self::Open => matches!(patch, patch::State::Open { .. }), - Self::Draft => matches!(patch, patch::State::Draft), - Self::Archived => matches!(patch, patch::State::Archived), - Self::Merged => matches!(patch, patch::State::Merged { .. }), - Self::All => true, - } - } - } -} diff --git a/src-tauri/src/commands/repos.rs b/src-tauri/src/commands/repo.rs similarity index 98% rename from src-tauri/src/commands/repos.rs rename to src-tauri/src/commands/repo.rs index 8b11c9a..e31cabb 100644 --- a/src-tauri/src/commands/repos.rs +++ b/src-tauri/src/commands/repo.rs @@ -44,7 +44,7 @@ pub fn repo_by_id( } #[tauri::command] -pub async fn diff( +pub async fn diff_stats( ctx: tauri::State<'_, AppState>, rid: RepoId, base: String, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0a55222..2282bc1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -17,7 +17,7 @@ use radicle::storage::git::Repository; use radicle::storage::{ReadRepository, ReadStorage}; use radicle::Node; -use commands::{auth, cobs, profile, repos, thread}; +use commands::{auth, cob, profile, repo, thread}; use types::repo::SupportedPayloads; struct AppState { @@ -138,17 +138,17 @@ pub fn run() { .plugin(tauri_plugin_window_state::Builder::default().build()) .invoke_handler(tauri::generate_handler![ auth::authenticate, - repos::list_repos, - repos::repo_by_id, - repos::diff, - cobs::list_issues, - cobs::issues_by_id, - cobs::list_patches, + repo::list_repos, + repo::repo_by_id, + repo::diff_stats, + cob::issue::list_issues, + cob::issue::issue_by_id, + cob::patch::list_patches, + cob::patch::patch_by_id, + cob::patch::revisions_by_patch, + cob::patch::revision_by_patch_and_id, thread::create_issue_comment, thread::create_patch_comment, - cobs::patches_by_id, - cobs::revisions_by_patch, - cobs::revisions_by_id, profile::config, ]) .run(tauri::generate_context!()) diff --git a/src/components/PatchTeaser.svelte b/src/components/PatchTeaser.svelte index 6589d67..acd6c24 100644 --- a/src/components/PatchTeaser.svelte +++ b/src/components/PatchTeaser.svelte @@ -82,7 +82,7 @@
- {#await invoke( "diff", { rid, base: patch.base, head: patch.head }, ) then stats} + {#await invoke( "diff_stats", { rid, base: patch.base, head: patch.head }, ) then stats} {/await} {#each patch.labels as label} diff --git a/src/views/repo/router.ts b/src/views/repo/router.ts index 4776f04..f612c11 100644 --- a/src/views/repo/router.ts +++ b/src/views/repo/router.ts @@ -111,7 +111,7 @@ export async function loadIssue( rid: route.rid, status: "all", }); - const issue: Issue = await invoke("issues_by_id", { + const issue: Issue = await invoke("issue_by_id", { rid: route.rid, id: route.issue, });