-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename and reorganize tauri commands
- Loading branch information
1 parent
665c5a9
commit ddf44ce
Showing
8 changed files
with
119 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters