Skip to content

Commit

Permalink
fix(comps): remove unnecessary load books call from popup, use active…
Browse files Browse the repository at this point in the history
… book state to rename book

Signed-off-by: Deep Panchal <deep302001@gmail.com>
  • Loading branch information
deepanchal committed Jul 7, 2024
1 parent 6abcf32 commit 37d4bcb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/components/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl Popup {

impl Component for Popup {
fn init(&mut self, area: Rect) -> Result<()> {
self.send_action(Action::LoadBooks)?;
Ok(())
}

Expand Down Expand Up @@ -103,13 +102,15 @@ impl Component for Popup {
Ok(None)
}
PopupType::RenameBook => {
let old_name = self.initial_value.clone();
let new_name = self.input.value().to_string();
let cmd = String::from("dnote");
let cmd_args = vec!["edit".into(), old_name, "-n".into(), new_name];
self.send_action(Action::ExecuteCommand(cmd, cmd_args))?;
self.send_action(Action::ClosePopup)?;
self.send_action(Action::LoadBooks)?;
if let Some(book) = state.get_active_book() {
let old_name = book.name.clone();
let new_name = self.input.value().to_string();
let cmd = String::from("dnote");
let cmd_args = vec!["edit".into(), old_name, "-n".into(), new_name];
self.send_action(Action::ExecuteCommand(cmd, cmd_args))?;
self.send_action(Action::ClosePopup)?;
self.send_action(Action::LoadBooks)?;
}
Ok(None)
}
_ => Ok(None),
Expand Down

0 comments on commit 37d4bcb

Please sign in to comment.