Add question popup type

This commit is contained in:
2Shirt 2026-01-17 13:36:36 -08:00
parent 33774da89c
commit 135ef44feb
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
4 changed files with 49 additions and 9 deletions

View file

@ -64,6 +64,8 @@ pub enum Action {
PostResponse { color: ResponseColor, text: String }, PostResponse { color: ResponseColor, text: String },
ResetTicket, ResetTicket,
SelectTicket(u16), SelectTicket(u16),
UserNo,
UserYes,
// Screens // Screens
DismissPopup, DismissPopup,
DisplayPopup(PopupType, String), DisplayPopup(PopupType, String),

View file

@ -14,6 +14,7 @@
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// //
use color_eyre::Result; use color_eyre::Result;
use crossterm::event::KeyCode;
use rand::random; use rand::random;
use ratatui::{ use ratatui::{
prelude::*, prelude::*,
@ -25,13 +26,14 @@ use tokio::sync::mpsc::UnboundedSender;
use tracing::info; use tracing::info;
use super::Component; use super::Component;
use crate::{action::Action, config::Config}; use crate::{action::Action, config::Config, tui::Event};
#[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)] #[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
pub enum Type { pub enum Type {
#[default] #[default]
Info, Info,
Error, Error,
Question,
Success, Success,
} }
@ -39,6 +41,7 @@ pub enum Type {
pub struct Popup { pub struct Popup {
command_tx: Option<UnboundedSender<Action>>, command_tx: Option<UnboundedSender<Action>>,
config: Config, config: Config,
get_input: bool,
popup_type: Type, popup_type: Type,
popup_text: String, popup_text: String,
} }
@ -46,7 +49,10 @@ pub struct Popup {
impl Popup { impl Popup {
#[must_use] #[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self {
get_input: false,
..Default::default()
}
} }
} }
@ -61,11 +67,34 @@ impl Component for Popup {
Ok(()) Ok(())
} }
fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>> {
if !self.get_input {
return Ok(None);
}
let action = match event {
Some(Event::Key(key_event)) => match key_event.code {
KeyCode::Char(c) => {
let response = c.to_ascii_lowercase();
match response {
'n' => Some(Action::UserNo),
'y' => Some(Action::UserYes),
_ => None,
}
}
_ => None,
},
Some(Event::Mouse(_)) => None,
_ => None,
};
Ok(action)
}
fn update(&mut self, action: Action) -> Result<Option<Action>> { fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action { match action {
Action::DismissPopup => self.popup_text.clear(), Action::DismissPopup => self.popup_text.clear(),
Action::DisplayPopup(new_type, new_text) => { Action::DisplayPopup(new_type, new_text) => {
info!("Show Popup ({new_type}): {new_text}"); info!("Show Popup ({new_type}): {new_text}");
self.get_input = new_type == Type::Question;
self.popup_type = new_type; self.popup_type = new_type;
self.popup_text = format!("\n{new_text}"); self.popup_text = format!("\n{new_text}");
} }
@ -85,6 +114,7 @@ impl Component for Popup {
match self.popup_type { match self.popup_type {
Type::Info => style = style.cyan(), Type::Info => style = style.cyan(),
Type::Error => style = style.red(), Type::Error => style = style.red(),
Type::Question => style = style.yellow(),
Type::Success => style = style.green(), Type::Success => style = style.green(),
} }

View file

@ -23,7 +23,10 @@ use tokio::sync::mpsc::UnboundedSender;
use tui_input::{Input, InputRequest}; use tui_input::{Input, InputRequest};
use super::Component; use super::Component;
use crate::{action::Action, config::Config, osticket::OsTicket, state::Mode, tui::Event}; use crate::{
action::Action, components::popup::Type as PopupType, config::Config, osticket::OsTicket,
state::Mode, tui::Event,
};
#[derive(Default)] #[derive(Default)]
pub struct TicketSelection { pub struct TicketSelection {
@ -82,12 +85,10 @@ impl Component for TicketSelection {
result result
} }
KeyCode::Enter => Some(Action::SetMode(Mode::ScanDisks)), KeyCode::Enter => Some(Action::SetMode(Mode::ScanDisks)),
KeyCode::Esc => { KeyCode::Esc => Some(Action::DisplayPopup(
if let Ok(mut osticket) = self.osticket_arc.lock() { PopupType::Question,
osticket.disable(); String::from("Disable osTicket integration?\n\nY / N"),
} )),
Some(Action::NextScreen)
}
_ => None, _ => None,
}, },
Some(Event::Mouse(_)) => None, Some(Event::Mouse(_)) => None,

View file

@ -595,6 +595,13 @@ impl App {
}; };
} }
Action::TasksComplete => self.action_tx.send(Action::NextScreen)?, Action::TasksComplete => self.action_tx.send(Action::NextScreen)?,
Action::UserNo => self.action_tx.send(Action::DismissPopup)?,
Action::UserYes => {
if let Ok(mut osticket) = self.osticket_arc.lock() {
osticket.disable();
}
self.action_tx.send(Action::NextScreen)?;
}
_ => {} _ => {}
} }
for component in &mut self.components { for component in &mut self.components {