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 },
ResetTicket,
SelectTicket(u16),
UserNo,
UserYes,
// Screens
DismissPopup,
DisplayPopup(PopupType, String),

View file

@ -14,6 +14,7 @@
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
//
use color_eyre::Result;
use crossterm::event::KeyCode;
use rand::random;
use ratatui::{
prelude::*,
@ -25,13 +26,14 @@ use tokio::sync::mpsc::UnboundedSender;
use tracing::info;
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)]
pub enum Type {
#[default]
Info,
Error,
Question,
Success,
}
@ -39,6 +41,7 @@ pub enum Type {
pub struct Popup {
command_tx: Option<UnboundedSender<Action>>,
config: Config,
get_input: bool,
popup_type: Type,
popup_text: String,
}
@ -46,7 +49,10 @@ pub struct Popup {
impl Popup {
#[must_use]
pub fn new() -> Self {
Self::default()
Self {
get_input: false,
..Default::default()
}
}
}
@ -61,11 +67,34 @@ impl Component for Popup {
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>> {
match action {
Action::DismissPopup => self.popup_text.clear(),
Action::DisplayPopup(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_text = format!("\n{new_text}");
}
@ -85,6 +114,7 @@ impl Component for Popup {
match self.popup_type {
Type::Info => style = style.cyan(),
Type::Error => style = style.red(),
Type::Question => style = style.yellow(),
Type::Success => style = style.green(),
}

View file

@ -23,7 +23,10 @@ use tokio::sync::mpsc::UnboundedSender;
use tui_input::{Input, InputRequest};
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)]
pub struct TicketSelection {
@ -82,12 +85,10 @@ impl Component for TicketSelection {
result
}
KeyCode::Enter => Some(Action::SetMode(Mode::ScanDisks)),
KeyCode::Esc => {
if let Ok(mut osticket) = self.osticket_arc.lock() {
osticket.disable();
}
Some(Action::NextScreen)
}
KeyCode::Esc => Some(Action::DisplayPopup(
PopupType::Question,
String::from("Disable osTicket integration?\n\nY / N"),
)),
_ => None,
},
Some(Event::Mouse(_)) => None,

View file

@ -595,6 +595,13 @@ impl App {
};
}
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 {