From 8c9afa61283ee74058f640260afb590bd806ff21 Mon Sep 17 00:00:00 2001 From: Sofia Date: Tue, 2 Jun 2026 12:17:56 +0300 Subject: [PATCH] Implement main menu --- src/states.rs | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/states.rs b/src/states.rs index a17123d..a3467b7 100644 --- a/src/states.rs +++ b/src/states.rs @@ -272,31 +272,23 @@ impl State for EnterPinState { } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] enum MainMenuItem { #[default] - Item1, - Item2, - Item3, - Item4, - Item5, - Item6, + SendSMS, + ReadSMS, } impl MenuItem for MainMenuItem { fn as_text(&self) -> String { match self { - MainMenuItem::Item1 => "item1", - MainMenuItem::Item2 => "item2", - MainMenuItem::Item3 => "item3", - MainMenuItem::Item4 => "item4", - MainMenuItem::Item5 => "item5", - MainMenuItem::Item6 => "item6", + MainMenuItem::SendSMS => "Send SMS", + MainMenuItem::ReadSMS => "Read SMS", } .to_string() } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct MainMenuState { menu: Menu, } @@ -305,19 +297,20 @@ impl Default for MainMenuState { fn default() -> Self { Self { menu: Menu::default() - .with_item(MainMenuItem::Item1) - .with_item(MainMenuItem::Item2) - .with_item(MainMenuItem::Item3) - .with_item(MainMenuItem::Item4) - .with_item(MainMenuItem::Item5) - .with_item(MainMenuItem::Item6), + .with_item(MainMenuItem::SendSMS) + .with_item(MainMenuItem::ReadSMS), } } } impl State for MainMenuState { fn update(&mut self, data: &mut StateData) -> Option> { - self.menu.poll(&mut data.io); + if let Some(option) = self.menu.poll(&mut data.io) { + match option { + MainMenuItem::SendSMS => return Some(Box::new(PhoneNumberState::default())), + MainMenuItem::ReadSMS => {} + } + } None } @@ -375,15 +368,15 @@ impl State for MessageState { |resp| match resp.unwrap() { SendSMSResponse::MessageRefrence(refrence) => Box::new(TextState { text: format!("SMS sent\nRef: {}", refrence), - after: PhoneNumberState::default(), + after: MainMenuState::default(), }), SendSMSResponse::Error => Box::new(TextState { text: "ERROR!".to_owned(), - after: PhoneNumberState::default(), + after: MainMenuState::default(), }), SendSMSResponse::ErrorMessage(msg) => Box::new(TextState { text: format!("Error:\n{}", msg), - after: PhoneNumberState::default(), + after: MainMenuState::default(), }), }, )))