feat: add filtering
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-10 23:46:51 +02:00
parent 07b768d0be
commit 78ccae8a1b
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
2 changed files with 20 additions and 4 deletions

View File

@ -7,6 +7,9 @@ pub enum Commands {
Archive,
CreateSection { name: String },
Edit,
ShowAll,
HideDone,
}
impl Commands {
@ -37,6 +40,8 @@ impl CommandParser {
name: name.to_string(),
}),
"e" | "edit" => Some(Commands::Edit),
"show-all" => Some(Commands::ShowAll),
"hide-done" => Some(Commands::HideDone),
_ => None,
},
None => None,

View File

@ -12,7 +12,7 @@ use super::{
render_graph::summarize::SummarizeRenderGraph,
};
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum FilterBy {
NotDone,
None,
@ -24,7 +24,7 @@ impl Default for FilterBy {
}
}
#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
pub struct DisplayOptions {
pub filter_by: FilterBy,
}
@ -84,7 +84,11 @@ impl<'a> GraphExplorer<'a> {
}
fn linearize_graph(&self) -> Option<MovementGraph> {
self.inner.graph.clone().map(|g| g.into())
tracing::trace!("current display options: {:?}", self.inner.display_options);
self.inner
.graph
.clone()
.map(|g| MovementGraph::new(g, &self.inner.display_options))
}
/// Will only incrmeent to the next level
@ -223,6 +227,12 @@ impl<'a> GraphExplorer<'a> {
}
}
}
Commands::ShowAll => {
self.inner.display_options.filter_by = FilterBy::None;
}
Commands::HideDone => {
self.inner.display_options.filter_by = FilterBy::NotDone;
}
_ => (),
}
@ -257,7 +267,8 @@ impl<'a> StatefulWidget for GraphExplorer<'a> {
let _height = height as usize;
if let Some(graph) = &state.graph {
let movement_graph: MovementGraph = graph.clone().into();
let movement_graph: MovementGraph =
MovementGraph::new(graph.clone(), &state.display_options);
let lines = movement_graph.render_graph(&state.current_position);
let para = Paragraph::new(lines);
para.render(area, buf);