mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-27 15:40:36 +08:00
Rename and reorganize tauri commands
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<AppState>,
|
||||
rid: RepoId,
|
||||
status: query::IssueStatus,
|
||||
) -> Result<Vec<cobs::Issue>, 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::<Vec<_>>();
|
||||
|
||||
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::<Vec<_>>();
|
||||
|
||||
Ok::<_, Error>(issues)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn issue_by_id(
|
||||
ctx: tauri::State<AppState>,
|
||||
rid: RepoId,
|
||||
id: Oid,
|
||||
) -> Result<Option<cobs::Issue>, 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)
|
||||
}
|
||||
@@ -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<AppState>,
|
||||
rid: RepoId,
|
||||
status: query::IssueStatus,
|
||||
) -> Result<Vec<cobs::Issue>, 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::<Vec<_>>();
|
||||
|
||||
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::<Vec<_>>();
|
||||
|
||||
Ok::<_, Error>(issues)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn issues_by_id(
|
||||
ctx: tauri::State<AppState>,
|
||||
rid: RepoId,
|
||||
id: Oid,
|
||||
) -> Result<Option<cobs::Issue>, 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<AppState>,
|
||||
@@ -79,7 +37,7 @@ pub fn list_patches(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn patches_by_id(
|
||||
pub fn patch_by_id(
|
||||
ctx: tauri::State<AppState>,
|
||||
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<AppState>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
+10
-10
@@ -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!())
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="global-flex">
|
||||
{#await invoke<Stats>( "diff", { rid, base: patch.base, head: patch.head }, ) then stats}
|
||||
{#await invoke<Stats>( "diff_stats", { rid, base: patch.base, head: patch.head }, ) then stats}
|
||||
<DiffStatBadge {stats} />
|
||||
{/await}
|
||||
{#each patch.labels as label}
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user