45 lines
1013 B
Rust
45 lines
1013 B
Rust
use serde::{Deserialize, Serialize};
|
|
use tokio::sync::mpsc::{UnboundedSender, error::SendError};
|
|
|
|
use crate::{
|
|
app::{GlobalAction, run::Action},
|
|
literature::Publication,
|
|
};
|
|
use brittle_macros::component;
|
|
|
|
#[derive(Serialize, Deserialize, Default)]
|
|
pub struct SeedingComponent {
|
|
pub input: String,
|
|
#[serde(skip)]
|
|
pub included_publications: Vec<Publication>,
|
|
}
|
|
|
|
#[component(SeedingAction)]
|
|
impl SeedingComponent {
|
|
#[action]
|
|
pub fn submit(
|
|
&mut self,
|
|
action_tx: &UnboundedSender<Action>,
|
|
) -> Result<(), SendError<Action>> {
|
|
action_tx
|
|
.send(GlobalAction::FetchAndIncludeSeed(self.input.clone()).into())
|
|
}
|
|
|
|
#[action]
|
|
pub fn clear_input(&mut self) {
|
|
self.input.clear();
|
|
}
|
|
|
|
#[action]
|
|
pub fn enter_char(&mut self, c: char) {
|
|
self.input.push(c)
|
|
}
|
|
|
|
#[action]
|
|
pub fn enter_backspace(&mut self) {
|
|
if self.input.len() > 0 {
|
|
self.input.truncate(self.input.len() - 1);
|
|
}
|
|
}
|
|
}
|