From c88d179c2d21af9bef41f41a226c303a844d557b Mon Sep 17 00:00:00 2001 From: itsscb Date: Mon, 12 Aug 2024 14:36:38 +0200 Subject: [PATCH] feat: adds handle_input --- src/ui/pages/mod.rs | 53 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/ui/pages/mod.rs b/src/ui/pages/mod.rs index 1d8165d..3926c8b 100644 --- a/src/ui/pages/mod.rs +++ b/src/ui/pages/mod.rs @@ -38,7 +38,19 @@ impl Page for HomePage { } fn handle_input(&self, input: &str) -> Result> { - todo!() // match against the user input and return the corresponding action. If the user input was invalid return None. + match input { + "c" => Ok(Some(Action::CreateEpic)), + "q" => Ok(Some(Action::Exit)), + _ => input.trim().parse().map_or_else( + |_| Ok(None), + |epic_id: u32| { + self.db.read_db()?.epics.get(&epic_id).map_or_else( + || Ok(None), + |_| Ok(Some(Action::NavigateToEpicDetail { epic_id })), + ) + }, + ), + } } } @@ -87,7 +99,32 @@ impl Page for EpicDetail { } fn handle_input(&self, input: &str) -> Result> { - todo!() // match against the user input and return the corresponding action. If the user input was invalid return None. + match input { + "p" => Ok(Some(Action::NavigateToPreviousPage)), + "u" => Ok(Some(Action::UpdateEpicStatus { + epic_id: self.epic_id, + })), + "d" => Ok(Some(Action::DeleteEpic { + epic_id: self.epic_id, + })), + "c" => Ok(Some(Action::CreateStory { + epic_id: self.epic_id, + })), + _ => input.trim().parse().map_or_else( + |_| Ok(None), + |story_id: u32| { + self.db.read_db()?.stories.get(&story_id).map_or_else( + || Ok(None), + |_| { + Ok(Some(Action::NavigateToStoryDetail { + epic_id: self.epic_id, + story_id, + })) + }, + ) + }, + ), + } } } @@ -125,7 +162,17 @@ impl Page for StoryDetail { } fn handle_input(&self, input: &str) -> Result> { - todo!() // match against the user input and return the corresponding action. If the user input was invalid return None. + match input { + "p" => Ok(Some(Action::NavigateToPreviousPage)), + "u" => Ok(Some(Action::UpdateStoryStatus { + story_id: self.story_id, + })), + "d" => Ok(Some(Action::DeleteStory { + epic_id: self.epic_id, + story_id: self.story_id, + })), + _ => Ok(None), + } } }