Add App::fetch function; Fix macros

This commit is contained in:
Andreas Tsouchlos 2025-12-31 03:01:19 +02:00
parent 2e51ae8064
commit 2e942a9b31
2 changed files with 23 additions and 11 deletions

View File

@ -41,6 +41,7 @@ pub enum GlobalAction {
FetchPub, FetchPub,
NextTab, NextTab,
Quit, Quit,
Fetch,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -154,16 +155,13 @@ impl App {
self.state.status_message = StatusMessage::Info("".to_string()); self.state.status_message = StatusMessage::Info("".to_string());
} }
fn add_included_publ( // TODO: Is deduplication necessary here?
&mut self, fn add_included_publ(&mut self, publ: Publication) {
publ: Publication,
) -> Result<(), SendError<Action>> {
self.state self.state
.history .history
.current_iteration .current_iteration
.included_publications .included_publications
.push(publ.clone()); .push(publ.clone());
Ok(())
} }
fn fetch_publication( fn fetch_publication(
@ -222,6 +220,14 @@ impl App {
self.action_tx.send(SeedingAction::ClearInput.into()) self.action_tx.send(SeedingAction::ClearInput.into())
} }
// TODO: Implement
fn fetch(
&self,
tx: &mpsc::UnboundedSender<Action>,
) -> Result<(), SendError<Action>> {
status_info!(tx, "Fetch action triggered from SnowballingComponent")
}
fn handle_global_action( fn handle_global_action(
&mut self, &mut self,
action: GlobalAction, action: GlobalAction,
@ -233,7 +239,10 @@ impl App {
GlobalAction::ClearStatMsg => Ok(self.clear_stat_msg()), GlobalAction::ClearStatMsg => Ok(self.clear_stat_msg()),
GlobalAction::ShowStatMsg(msg) => Ok(self.show_stat_msg(msg, tx)), GlobalAction::ShowStatMsg(msg) => Ok(self.show_stat_msg(msg, tx)),
GlobalAction::FetchPub => self.fetch_publication(tx), GlobalAction::FetchPub => self.fetch_publication(tx),
GlobalAction::AddIncludedPub(publ) => self.add_included_publ(publ), GlobalAction::AddIncludedPub(publ) => {
Ok(self.add_included_publ(publ))
}
GlobalAction::Fetch => self.fetch(tx),
} }
} }
@ -293,6 +302,9 @@ impl App {
(Tab::Snowballing, KeyCode::Char('k')) => { (Tab::Snowballing, KeyCode::Char('k')) => {
self.action_tx.send(SnowballingAction::PrevItem.into())?; self.action_tx.send(SnowballingAction::PrevItem.into())?;
} }
(Tab::Snowballing, KeyCode::Char(' ')) => {
self.action_tx.send(GlobalAction::Fetch.into())?;
}
_ => {} _ => {}
} }

View File

@ -5,9 +5,9 @@ use crate::app::Action;
#[allow(unused_macros)] #[allow(unused_macros)]
#[macro_export] #[macro_export]
macro_rules! status_info { macro_rules! status_info {
($action_tx:expr, $text:expr, $($args:expr)*) => { ($action_tx:expr, $text:expr $(, $args:expr)*) => {
$action_tx.send( $action_tx.send(
GlobalAction::ShowStatMsg(StatusMessage::Info(format!($text, $($args)*))) crate::app::GlobalAction::ShowStatMsg(crate::app::StatusMessage::Info(format!($text, $($args)*)))
.into(), .into(),
) )
}; };
@ -16,9 +16,9 @@ macro_rules! status_info {
#[allow(unused_macros)] #[allow(unused_macros)]
#[macro_export] #[macro_export]
macro_rules! status_warn { macro_rules! status_warn {
($action_tx:expr, $text:expr, $($args:expr)*) => { ($action_tx:expr, $text:expr $(, $args:expr)*) => {
$action_tx.send( $action_tx.send(
GlobalAction::ShowStatMsg(StatusMessage::Warning(format!($text, $($args)*))) crate::app::GlobalAction::ShowStatMsg(crate::app::StatusMessage::Info(format!($text, $($args)*)))
.into(), .into(),
) )
}; };
@ -29,7 +29,7 @@ macro_rules! status_warn {
macro_rules! status_error { macro_rules! status_error {
($action_tx:expr, $text:expr $(, $args:expr)*) => { ($action_tx:expr, $text:expr $(, $args:expr)*) => {
$action_tx.send( $action_tx.send(
GlobalAction::ShowStatMsg(StatusMessage::Error(format!($text, $($args)*))) crate::app::GlobalAction::ShowStatMsg(crate::app::StatusMessage::Info(format!($text, $($args)*)))
.into(), .into(),
) )
}; };