diff --git a/src/app.rs b/src/app.rs index 05b6126..b162293 100644 --- a/src/app.rs +++ b/src/app.rs @@ -11,8 +11,10 @@ use tokio::{ time::sleep, }; -use crate::literature::{ - Publication, SnowballingHistory, get_publication_by_id, +use crate::{ + app::common::Component, + literature::{Publication, SnowballingHistory, get_publication_by_id}, + status_error, status_info, }; use seeding::{SeedingAction, SeedingComponent}; @@ -55,14 +57,6 @@ pub enum Action { Global(GlobalAction), } -pub trait Component { - fn handle_action( - &mut self, - action: T, - tx: &mpsc::UnboundedSender, - ) -> Result<(), SendError>; -} - impl From for Action { fn from(action: GlobalAction) -> Self { Action::Global(action) @@ -109,34 +103,6 @@ pub struct App { pub action_tx: &'static mpsc::UnboundedSender, } -#[allow(unused_macros)] -macro_rules! status_info { - ($action_tx:expr, $text:expr, $($args:expr)*) => { - $action_tx.send( - GlobalAction::ShowStatusMessage(StatusMessage::Info(format!($text, $($args)*))) - .into(), - ) - }; -} -#[allow(unused_macros)] -macro_rules! status_warn { - ($action_tx:expr, $text:expr, $($args:expr)*) => { - $action_tx.send( - GlobalAction::ShowStatusMessage(StatusMessage::Warning(format!($text, $($args)*))) - .into(), - ) - }; -} -#[allow(unused_macros)] -macro_rules! status_error { - ($action_tx:expr, $text:expr $(, $args:expr)*) => { - $action_tx.send( - GlobalAction::ShowStatusMessage(StatusMessage::Error(format!($text, $($args)*))) - .into(), - ) - }; -} - // TODO: Implement moving through steps and iterations (populating pending papers) // TODO: Implement exclusion and inclusion of papers (e.g., X and Y chars) // TODO: Implement possibility of pushing excluded papers back into pending diff --git a/src/app/common.rs b/src/app/common.rs index e69de29..0de64eb 100644 --- a/src/app/common.rs +++ b/src/app/common.rs @@ -0,0 +1,44 @@ +use tokio::sync::mpsc::{self, error::SendError}; + +use crate::app::Action; + +#[allow(unused_macros)] +#[macro_export] +macro_rules! status_info { + ($action_tx:expr, $text:expr, $($args:expr)*) => { + $action_tx.send( + GlobalAction::ShowStatusMessage(StatusMessage::Info(format!($text, $($args)*))) + .into(), + ) + }; +} + +#[allow(unused_macros)] +#[macro_export] +macro_rules! status_warn { + ($action_tx:expr, $text:expr, $($args:expr)*) => { + $action_tx.send( + GlobalAction::ShowStatusMessage(StatusMessage::Warning(format!($text, $($args)*))) + .into(), + ) + }; +} + +#[allow(unused_macros)] +#[macro_export] +macro_rules! status_error { + ($action_tx:expr, $text:expr $(, $args:expr)*) => { + $action_tx.send( + GlobalAction::ShowStatusMessage(StatusMessage::Error(format!($text, $($args)*))) + .into(), + ) + }; +} + +pub trait Component { + fn handle_action( + &mut self, + action: T, + tx: &mpsc::UnboundedSender, + ) -> Result<(), SendError>; +} diff --git a/src/app/seeding.rs b/src/app/seeding.rs index a436424..e6076e0 100644 --- a/src/app/seeding.rs +++ b/src/app/seeding.rs @@ -1,10 +1,7 @@ use serde::{Deserialize, Serialize}; use tokio::sync::mpsc::{self, error::SendError}; -use crate::{ - app::{Action, Component}, - literature::Publication, -}; +use crate::{app::Action, app::common::Component, literature::Publication}; #[derive(Clone, Debug)] pub enum SeedingAction { diff --git a/src/app/snowballing.rs b/src/app/snowballing.rs index 38c2de6..d39f3ab 100644 --- a/src/app/snowballing.rs +++ b/src/app/snowballing.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use tokio::sync::mpsc; use tokio::sync::mpsc::error::SendError; -use crate::app::{Action, Component}; +use crate::app::{Action, common::Component}; use crate::literature::Publication; #[derive(Serialize, Deserialize, Default, PartialEq)]