diff --git a/flake.lock b/flake.lock index 5f21c76..4d38755 100644 --- a/flake.lock +++ b/flake.lock @@ -30,11 +30,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1722738111, - "narHash": "sha256-cWD5pCs9AYb+512/yCx9D0Pl5KcmyuXHeJpsDw/D1vs=", + "lastModified": 1723429325, + "narHash": "sha256-4x/32xTCd+xCwFoI/kKSiCr5LQA2ZlyTRYXKEni5HR8=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "27ec296d93cb4b2d03e8cbd019b1b4cde8c34280", + "rev": "65e3dc0fe079fe8df087cd38f1fe6836a0373aad", "type": "github" }, "original": { diff --git a/src/navigator.rs b/src/navigator.rs index 5bb58cf..3302cee 100644 --- a/src/navigator.rs +++ b/src/navigator.rs @@ -16,7 +16,7 @@ pub struct Navigator { impl Navigator { pub fn new(db: Rc) -> Self { Self { - pages: vec![], + pages: vec![Box::new(HomePage::new(Rc::clone(&db)))], prompts: Prompts::new(), db, } @@ -49,28 +49,41 @@ impl Navigator { } Action::CreateEpic => { // prompt the user to create a new epic and persist it in the database - self.db.create_epic((self.prompts.create_epic)()); + self.db + .create_epic((self.prompts.create_epic)()) + .with_context(|| format!("failed to create epic"))?; } Action::UpdateEpicStatus { epic_id } => { - todo!(); // prompt the user to update status and persist it in the database - // let status = (self.prompts.update_status)().(|| { - // return Err(anyhow!("failed to update epic status") - // .context(format!("invalid status given"))); - // }); - self.db - .update_epic_status(epic_id, crate::models::Status::Open); + // prompt the user to update status and persist it in the database + let status = (self.prompts.update_status)() + .with_context(|| format!("invalid status: {epic_id}"))?; + self.db.update_epic_status(epic_id, status)?; } Action::DeleteEpic { epic_id } => { - todo!() // prompt the user to delete the epic and persist it in the database + // prompt the user to delete the epic and persist it in the database + self.db + .delete_epic(epic_id) + .with_context(|| format!("failed to delete epic: {epic_id}"))?; } Action::CreateStory { epic_id } => { - todo!() // prompt the user to create a new story and persist it in the database + // prompt the user to create a new story and persist it in the database + self.db + .create_story((self.prompts.create_story)(), epic_id) + .with_context(|| format!("failed to create story: {epic_id}"))?; } Action::UpdateStoryStatus { story_id } => { - todo!() // prompt the user to update status and persist it in the database + // prompt the user to update status and persist it in the database + let status = (self.prompts.update_status)() + .with_context(|| format!("invalid status: {story_id}"))?; + self.db.update_story_status(story_id, status)?; } Action::DeleteStory { epic_id, story_id } => { - todo!() // prompt the user to delete the story and persist it in the database + // prompt the user to delete the story and persist it in the database + if (self.prompts.delete_story)() { + self.db + .delete_story(epic_id, story_id) + .with_context(|| format!("failed to delete story: {story_id}"))?; + } } Action::Exit => { // remove all pages from the pages vector diff --git a/src/ui/pages/mod.rs b/src/ui/pages/mod.rs index ef62579..27572cd 100644 --- a/src/ui/pages/mod.rs +++ b/src/ui/pages/mod.rs @@ -20,6 +20,12 @@ pub trait Page { pub struct HomePage { pub db: Rc, } + +impl HomePage { + pub fn new(db: Rc) -> Self { + Self { db } + } +} impl Page for HomePage { fn draw_page(&self) -> Result<()> { println!("----------------------------- EPICS -----------------------------");