Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kdheepak committed Oct 2, 2023
1 parent 65dbd3e commit 09d4e8c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ group_imports = "StdExternalCrate"
tab_spaces = 2
use_field_init_shorthand = true
use_try_shorthand = true
combine_control_expr = false
3 changes: 2 additions & 1 deletion src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
tui::{Event, Frame},
};

pub mod task_details;
pub mod task_report;

pub trait Component {
Expand Down Expand Up @@ -43,5 +44,5 @@ pub trait Component {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
Ok(None)
}
fn draw(&mut self, f: &mut Frame<'_>, rect: Rect) -> Result<()>;
fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()>;
}
26 changes: 26 additions & 0 deletions src/components/task_details.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use color_eyre::eyre::Result;
use futures::channel::mpsc::UnboundedSender;
use ratatui::{prelude::*, widgets::*};
use task_hookrs::task::Task;

use super::{Component, Frame};
use crate::{action::Action, config::Config};

#[derive(Default)]
pub struct TaskDetails {
pub command_tx: Option<UnboundedSender<Action>>,
pub config: Config,
}

impl Component for TaskDetails {
fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action {
Action::TaskDetailsUpdateUuid(uuid) => {},
_ => {},
}
}

fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()> {
Ok(())
}
}
23 changes: 5 additions & 18 deletions src/components/task_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
action::{Action, TaskCommand},
config::{Config, KeyBindings},
};

const VIRTUAL_TAGS: [&str; 34] = [
"PROJECT",
"BLOCKED",
Expand Down Expand Up @@ -812,13 +813,13 @@ impl Component for TaskReport {
Ok(None)
}

fn draw(&mut self, f: &mut Frame<'_>, rect: Rect) -> Result<()> {
fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()> {
let column_spacing = 1;
if self.rows.len() == 0 {
f.render_widget(Paragraph::new("No data found").block(Block::new().borders(Borders::all())), rect);
f.render_widget(Paragraph::new("No data found").block(Block::new().borders(Borders::all())), area);
return Ok(());
}
let widths = self.calculate_widths(rect.width);
let widths = self.calculate_widths(area.width);
let constraints: Vec<Constraint> = widths.iter().map(|i| Constraint::Min(*i as u16)).collect();
let rows = self.rows.iter().enumerate().map(|(i, row)| {
let style = self.style_for_task(&self.tasks[i]);
Expand All @@ -841,7 +842,7 @@ impl Component for TaskReport {
.highlight_symbol(&self.config.task_report.selection_indicator)
.highlight_spacing(HighlightSpacing::Always)
.column_spacing(column_spacing);
f.render_stateful_widget(table, rect, &mut self.state);
f.render_stateful_widget(table, area, &mut self.state);
Ok(())
}
}
Expand Down Expand Up @@ -967,17 +968,3 @@ pub fn remove_tag(task: &mut Task, tag: &str) {
}
}
}

mod tests {
use pretty_assertions::assert_eq;

use super::*;

#[test]
fn test_export() -> Result<()> {
let mut tr = TaskReport::new().report("next".into());
tr.task_export()?;
assert_eq!(tr.tasks.len(), 33);
Ok(())
}
}

0 comments on commit 09d4e8c

Please sign in to comment.