Change name; Add first version of deduplication; Fix typo

This commit is contained in:
Andreas Tsouchlos 2026-01-02 01:34:07 +02:00
parent 0276bfe515
commit bc0f71956b
5 changed files with 66 additions and 14 deletions

2
Cargo.lock generated
View File

@ -150,7 +150,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "brittling" name = "brittle"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"ammonia", "ammonia",

View File

@ -2,7 +2,7 @@
members = [".", "macros"] members = [".", "macros"]
[package] [package]
name = "brittling" name = "brittle"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"

View File

@ -14,7 +14,7 @@ use tokio::{
}; };
use crate::{ use crate::{
app::run::Action, app::{run::Action, snowballing::ActivePane},
literature::{ literature::{
Publication, SnowballingHistory, get_citing_works_stream, Publication, SnowballingHistory, get_citing_works_stream,
get_publication_by_id, get_references_stream, get_publication_by_id, get_references_stream,
@ -128,20 +128,14 @@ impl App {
self.state.status_message = StatusMessage::Info("".to_string()); self.state.status_message = StatusMessage::Info("".to_string());
} }
// TODO: Is deduplication necessary here?
#[action] #[action]
fn add_included_pub(&mut self, publ: Publication) { fn add_included_pub(&mut self, publ: Publication) {
self.state self.state.history.add_included_publication(publ);
.history
.current_iteration
.included_publications
.push(publ.clone());
} }
// TODO: Is deduplication necessary here?
#[action] #[action]
fn add_pending_pub(&mut self, publ: Publication) { fn add_pending_pub(&mut self, publ: Publication) {
self.state.history.pending_publications.push(publ.clone()); self.state.history.add_pending_publication(publ);
} }
#[action] #[action]
@ -282,6 +276,24 @@ impl App {
Ok(()) 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( pub fn handle_key(
&mut self, &mut self,
key: KeyCode, key: KeyCode,
@ -323,6 +335,12 @@ impl App {
(Tab::Snowballing, KeyCode::Char('c')) => { (Tab::Snowballing, KeyCode::Char('c')) => {
action_tx.send(GlobalAction::FetchCitingWorks.into()) 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(()), _ => Ok(()),
} }
} }

View File

@ -50,16 +50,17 @@ pub struct SnowballingIteration {
pub struct SnowballingHistory { pub struct SnowballingHistory {
pub seed: Vec<Publication>, pub seed: Vec<Publication>,
pub current_iteration: SnowballingIteration, pub current_iteration: SnowballingIteration,
pub previoius_iterations: Vec<SnowballingIteration>, pub previous_iterations: Vec<SnowballingIteration>,
pub pending_publications: Vec<Publication>, pub pending_publications: Vec<Publication>,
} }
impl SnowballingHistory { impl SnowballingHistory {
// TODO: Make this return references if possible
pub fn get_all_included(&self) -> Vec<Publication> { pub fn get_all_included(&self) -> Vec<Publication> {
vec![self.current_iteration.included_publications.clone()] vec![self.current_iteration.included_publications.clone()]
.into_iter() .into_iter()
.chain( .chain(
self.previoius_iterations self.previous_iterations
.iter() .iter()
.map(|iter| iter.included_publications.clone()), .map(|iter| iter.included_publications.clone()),
) )
@ -67,9 +68,42 @@ impl SnowballingHistory {
.collect() .collect()
} }
// TODO: Make this return references if possible
pub fn get_all_pending(&self) -> Vec<Publication> { pub fn get_all_pending(&self) -> Vec<Publication> {
self.pending_publications.clone() 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 { fn sanitize_text(raw_text: &str) -> String {

View File

@ -298,7 +298,7 @@ fn draw_left_pane(frame: &mut Frame, app: &mut AppState, area: Rect) {
Line::from(vec![ Line::from(vec![
Span::raw("Step: "), Span::raw("Step: "),
Span::styled( Span::styled(
app.history.previoius_iterations.len().to_string(), app.history.previous_iterations.len().to_string(),
Style::default().fg(Color::Cyan), Style::default().fg(Color::Cyan),
), ),
]), ]),