diff --git a/Cargo.lock b/Cargo.lock index 65896c3..2545f35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,7 +150,7 @@ dependencies = [ ] [[package]] -name = "brittling" +name = "brittle" version = "0.1.0" dependencies = [ "ammonia", diff --git a/Cargo.toml b/Cargo.toml index 95c6802..274a6e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = [".", "macros"] [package] -name = "brittling" +name = "brittle" version = "0.1.0" edition = "2024" diff --git a/src/app.rs b/src/app.rs index 6e3269e..eb99afa 100644 --- a/src/app.rs +++ b/src/app.rs @@ -14,7 +14,7 @@ use tokio::{ }; use crate::{ - app::run::Action, + app::{run::Action, snowballing::ActivePane}, literature::{ Publication, SnowballingHistory, get_citing_works_stream, get_publication_by_id, get_references_stream, @@ -128,20 +128,14 @@ impl App { self.state.status_message = StatusMessage::Info("".to_string()); } - // TODO: Is deduplication necessary here? #[action] fn add_included_pub(&mut self, publ: Publication) { - self.state - .history - .current_iteration - .included_publications - .push(publ.clone()); + self.state.history.add_included_publication(publ); } - // TODO: Is deduplication necessary here? #[action] fn add_pending_pub(&mut self, publ: Publication) { - self.state.history.pending_publications.push(publ.clone()); + self.state.history.add_pending_publication(publ); } #[action] @@ -282,6 +276,24 @@ impl App { Ok(()) } + #[action] + // TODO: Implement + fn remove_selected_pending(&mut self) { + if self.state.snowballing.active_pane != ActivePane::PendingPublications + { + return; + } + } + + #[action] + // TODO: Implement + fn include_selected_pending(&mut self) { + if self.state.snowballing.active_pane != ActivePane::PendingPublications + { + return; + } + } + pub fn handle_key( &mut self, key: KeyCode, @@ -323,6 +335,12 @@ impl App { (Tab::Snowballing, KeyCode::Char('c')) => { action_tx.send(GlobalAction::FetchCitingWorks.into()) } + (Tab::Snowballing, KeyCode::Char('X')) => { + action_tx.send(GlobalAction::RemoveSelectedPending.into()) + } + (Tab::Snowballing, KeyCode::Char('<')) => { + action_tx.send(GlobalAction::IncludeSelectedPending.into()) + } _ => Ok(()), } } diff --git a/src/literature.rs b/src/literature.rs index 57e9f71..420339e 100644 --- a/src/literature.rs +++ b/src/literature.rs @@ -50,16 +50,17 @@ pub struct SnowballingIteration { pub struct SnowballingHistory { pub seed: Vec, pub current_iteration: SnowballingIteration, - pub previoius_iterations: Vec, + pub previous_iterations: Vec, pub pending_publications: Vec, } impl SnowballingHistory { + // TODO: Make this return references if possible pub fn get_all_included(&self) -> Vec { vec![self.current_iteration.included_publications.clone()] .into_iter() .chain( - self.previoius_iterations + self.previous_iterations .iter() .map(|iter| iter.included_publications.clone()), ) @@ -67,9 +68,42 @@ impl SnowballingHistory { .collect() } + // TODO: Make this return references if possible pub fn get_all_pending(&self) -> Vec { self.pending_publications.clone() } + + fn publication_exists(&self, publ: &Publication) -> bool { + self.pending_publications + .iter() + .chain(self.current_iteration.included_publications.iter()) + .chain(self.current_iteration.excluded_publications.iter()) + .chain( + self.previous_iterations + .iter() + .flat_map(|p| p.included_publications.iter()), + ) + .chain( + self.previous_iterations + .iter() + .flat_map(|p| p.excluded_publications.iter()), + ) + .any(|p| p.id == publ.id) + } + + // TODO: Implement deduplication + pub fn add_pending_publication(&mut self, publ: Publication) { + if !self.publication_exists(&publ) { + self.pending_publications.push(publ); + } + } + + // TODO: Implement deduplication + pub fn add_included_publication(&mut self, publ: Publication) { + if !self.publication_exists(&publ) { + self.current_iteration.included_publications.push(publ); + } + } } fn sanitize_text(raw_text: &str) -> String { diff --git a/src/ui.rs b/src/ui.rs index 348b0ec..2461687 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -298,7 +298,7 @@ fn draw_left_pane(frame: &mut Frame, app: &mut AppState, area: Rect) { Line::from(vec![ Span::raw("Step: "), Span::styled( - app.history.previoius_iterations.len().to_string(), + app.history.previous_iterations.len().to_string(), Style::default().fg(Color::Cyan), ), ]),