Move stuff to app/common.rs

This commit is contained in:
Andreas Tsouchlos 2025-12-31 02:03:51 +02:00
parent b496edf404
commit dd2d19ee13
4 changed files with 50 additions and 43 deletions

View File

@ -11,8 +11,10 @@ use tokio::{
time::sleep, time::sleep,
}; };
use crate::literature::{ use crate::{
Publication, SnowballingHistory, get_publication_by_id, app::common::Component,
literature::{Publication, SnowballingHistory, get_publication_by_id},
status_error, status_info,
}; };
use seeding::{SeedingAction, SeedingComponent}; use seeding::{SeedingAction, SeedingComponent};
@ -55,14 +57,6 @@ pub enum Action {
Global(GlobalAction), Global(GlobalAction),
} }
pub trait Component<T> {
fn handle_action(
&mut self,
action: T,
tx: &mpsc::UnboundedSender<Action>,
) -> Result<(), SendError<Action>>;
}
impl From<GlobalAction> for Action { impl From<GlobalAction> for Action {
fn from(action: GlobalAction) -> Self { fn from(action: GlobalAction) -> Self {
Action::Global(action) Action::Global(action)
@ -109,34 +103,6 @@ pub struct App {
pub action_tx: &'static mpsc::UnboundedSender<Action>, pub action_tx: &'static mpsc::UnboundedSender<Action>,
} }
#[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 moving through steps and iterations (populating pending papers)
// TODO: Implement exclusion and inclusion of papers (e.g., X and Y chars) // TODO: Implement exclusion and inclusion of papers (e.g., X and Y chars)
// TODO: Implement possibility of pushing excluded papers back into pending // TODO: Implement possibility of pushing excluded papers back into pending

View File

@ -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<T> {
fn handle_action(
&mut self,
action: T,
tx: &mpsc::UnboundedSender<Action>,
) -> Result<(), SendError<Action>>;
}

View File

@ -1,10 +1,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::{self, error::SendError}; use tokio::sync::mpsc::{self, error::SendError};
use crate::{ use crate::{app::Action, app::common::Component, literature::Publication};
app::{Action, Component},
literature::Publication,
};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum SeedingAction { pub enum SeedingAction {

View File

@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio::sync::mpsc::error::SendError; use tokio::sync::mpsc::error::SendError;
use crate::app::{Action, Component}; use crate::app::{Action, common::Component};
use crate::literature::Publication; use crate::literature::Publication;
#[derive(Serialize, Deserialize, Default, PartialEq)] #[derive(Serialize, Deserialize, Default, PartialEq)]