diff --git a/src/app.rs b/src/app.rs index b352ef8c..9ea9c5bb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -72,6 +72,7 @@ pub enum IssueMessage { Focus(IssueCid), OpenPopup(IssueCid), ClosePopup(IssueCid), + New(String, String, String, String), Leave, } @@ -192,6 +193,7 @@ impl App { _ => Ok(Some(Message::Batch(results))), } } + Message::Issue(IssueMessage::New(_title, _tags, _assignees, _description)) => Ok(None), Message::Issue(IssueMessage::Show(id)) => { self.view_issue(app, id, &theme)?; Ok(None) diff --git a/src/app/event.rs b/src/app/event.rs index d0f3924d..9da1d28b 100644 --- a/src/app/event.rs +++ b/src/app/event.rs @@ -9,6 +9,7 @@ use radicle_tui::ui::widget::common::context::{ContextBar, Shortcuts}; use radicle_tui::ui::widget::common::form::TextInput; use radicle_tui::ui::widget::common::list::PropertyList; use radicle_tui::ui::widget::home::{Dashboard, IssueBrowser, PatchBrowser}; +use radicle_tui::ui::widget::issue::NewForm; use radicle_tui::ui::widget::{issue, patch}; use radicle_tui::ui::widget::Widget; @@ -158,8 +159,53 @@ impl tuirealm::Component for Widget { code: Key::Char('s'), modifiers: KeyModifiers::ALT, }) => { - self.perform(Cmd::Submit); - None + match self.perform(Cmd::Submit) { + CmdResult::Submit(State::Map(inputs)) => { + let mut missing_values = vec![]; + + let title = match inputs.get(NewForm::INPUT_TITLE) { + Some(StateValue::String(title)) if !title.is_empty() => { + Some(title.clone()) + } + _ => None, + }; + let tags = match inputs.get(NewForm::INPUT_TAGS) { + Some(StateValue::String(tags)) => Some(tags.clone()), + _ => Some(String::from("[]")), + }; + let assignees = match inputs.get(NewForm::INPUT_ASSIGNESS) { + Some(StateValue::String(assignees)) => Some(assignees.clone()), + _ => Some(String::from("[]")), + }; + let description = match inputs.get(NewForm::INPUT_DESCRIPTION) { + Some(StateValue::String(description)) if !description.is_empty() => { + Some(description.clone()) + } + _ => None, + }; + + if title.is_none() { + missing_values.push(NewForm::INPUT_TITLE); + } + if description.is_none() { + missing_values.push(NewForm::INPUT_DESCRIPTION); + } + + // show error popup if missing. + if !missing_values.is_empty() { + let error = format!("Missing fields: {:?}", missing_values); + Some(Message::Popup(PopupMessage::Error(error))) + } else { + Some(Message::Issue(IssueMessage::New( + title.unwrap(), + tags.unwrap(), + assignees.unwrap(), + description.unwrap(), + ))) + } + } + _ => None, + } } Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => { Some(Message::Issue(IssueMessage::ClosePopup(IssueCid::NewForm))) diff --git a/src/ui/widget/issue.rs b/src/ui/widget/issue.rs index 6214e2a2..0451a291 100644 --- a/src/ui/widget/issue.rs +++ b/src/ui/widget/issue.rs @@ -1,11 +1,13 @@ +use std::collections::HashMap; + use radicle::cob::thread::Comment; use radicle::cob::thread::CommentId; use radicle::cob::issue::Issue; use radicle::cob::issue::IssueId; -use tuirealm::tui::layout::Constraint; -use tuirealm::tui::layout::Direction; -use tuirealm::tui::layout::Layout; +use tuirealm::tui::layout::{Constraint, Direction, Layout}; +use tuirealm::StateValue; + use super::common::container::{Container, LabeledContainer}; use super::common::context::{ContextBar, Progress}; @@ -252,6 +254,11 @@ pub struct NewForm { } impl NewForm { + pub const INPUT_TITLE: &str = "title"; + pub const INPUT_TAGS: &str = "tags"; + pub const INPUT_ASSIGNESS: &str = "assignees"; + pub const INPUT_DESCRIPTION: &str = "description"; + pub fn new(theme: &Theme) -> Self { use tuirealm::props::Layout; @@ -300,8 +307,25 @@ impl WidgetComponent for NewForm { fn perform(&mut self, _properties: &Props, cmd: Cmd) -> CmdResult { match self.form.perform(cmd) { CmdResult::Submit(State::Vec(values)) => { - println!("{:?}", values); - CmdResult::None + let inputs = HashMap::from([ + ( + Self::INPUT_TITLE.to_owned(), + values.get(0).unwrap_or(&StateValue::None).clone(), + ), + ( + Self::INPUT_TAGS.to_owned(), + values.get(1).unwrap_or(&StateValue::None).clone(), + ), + ( + Self::INPUT_ASSIGNESS.to_owned(), + values.get(2).unwrap_or(&StateValue::None).clone(), + ), + ( + Self::INPUT_DESCRIPTION.to_owned(), + values.get(3).unwrap_or(&StateValue::None).clone(), + ), + ]); + CmdResult::Submit(State::Map(inputs)) } _ => CmdResult::None, }