Change name; Add first version of deduplication; Fix typo
This commit is contained in:
parent
0276bfe515
commit
bc0f71956b
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -150,7 +150,7 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brittling"
|
||||
name = "brittle"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ammonia",
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
members = [".", "macros"]
|
||||
|
||||
[package]
|
||||
name = "brittling"
|
||||
name = "brittle"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
|
||||
36
src/app.rs
36
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(()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,16 +50,17 @@ pub struct SnowballingIteration {
|
||||
pub struct SnowballingHistory {
|
||||
pub seed: Vec<Publication>,
|
||||
pub current_iteration: SnowballingIteration,
|
||||
pub previoius_iterations: Vec<SnowballingIteration>,
|
||||
pub previous_iterations: Vec<SnowballingIteration>,
|
||||
pub pending_publications: Vec<Publication>,
|
||||
}
|
||||
|
||||
impl SnowballingHistory {
|
||||
// TODO: Make this return references if possible
|
||||
pub fn get_all_included(&self) -> Vec<Publication> {
|
||||
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<Publication> {
|
||||
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 {
|
||||
|
||||
@ -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),
|
||||
),
|
||||
]),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user