Skip to content

Commit

Permalink
chore: Decrease tech debt
Browse files Browse the repository at this point in the history
  • Loading branch information
kdheepak committed May 12, 2024
1 parent 10b3ef7 commit 32a7318
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
39 changes: 19 additions & 20 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ use crate::{
action::Action,
calendar::Calendar,
completion::{get_start_word_under_cursor, CompletionList},
config,
config::Config,
config::{self, Config},
event::{Event, KeyCode},
help::Help,
history::HistoryContext,
Expand Down Expand Up @@ -928,17 +927,16 @@ impl TaskwarriorTui {
let maximum_column_width = area.width;
let widths = self.calculate_widths(&contexts, &headers, maximum_column_width);

let selected = self.contexts.table_state.current_selection().unwrap_or_default();
let header = headers.iter();
let selected = self.contexts.table_state.selected().unwrap_or_default();
let mut rows = vec![];
let mut highlight_style = Style::default();
for (i, context) in contexts.iter().enumerate() {
let mut style = Style::default();
if &self.contexts.rows[i].active == "yes" {
style = self.config.uda_style_context_active;
}
rows.push(Row::StyledData(context.iter(), style));
if i == self.contexts.table_state.current_selection().unwrap_or_default() {
rows.push(ratatui::widgets::Row::new(context.clone()).style(style));
if i == self.contexts.table_state.selected().unwrap_or_default() {
highlight_style = style;
}
}
Expand All @@ -949,25 +947,26 @@ impl TaskwarriorTui {
.collect();

let highlight_style = highlight_style.add_modifier(Modifier::BOLD);
let t = Table::new(header, rows.into_iter())
let t = ratatui::widgets::Table::new(rows.into_iter(), constraints.clone())

Check failure on line 950 in src/app.rs

View workflow job for this annotation

GitHub Actions / Clippy

explicit call to `.into_iter()` in function argument accepting `IntoIterator`
.block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.title(Line::from(vec![Span::styled("Context", Style::default().add_modifier(Modifier::BOLD))])),
)
.header_style(
self
.config
.color
.get("color.label")
.copied()
.unwrap_or_default()
.add_modifier(Modifier::UNDERLINED),
.header(
ratatui::widgets::Row::new(headers).style(
self
.config
.color
.get("color.label")
.copied()
.unwrap_or_default()
.add_modifier(Modifier::UNDERLINED),
),
)
.highlight_style(highlight_style)
.highlight_symbol(&self.config.uda_selection_indicator)
.widths(&constraints);
.highlight_symbol(self.config.uda_selection_indicator.clone());

f.render_stateful_widget(t, area, &mut self.contexts.table_state);
}
Expand Down Expand Up @@ -1442,7 +1441,7 @@ impl TaskwarriorTui {
}

pub fn context_next(&mut self) {
let i = match self.contexts.table_state.current_selection() {
let i = match self.contexts.table_state.selected() {
Some(i) => {
if i >= self.contexts.len() - 1 {
0
Expand All @@ -1456,7 +1455,7 @@ impl TaskwarriorTui {
}

pub fn context_previous(&mut self) {
let i = match self.contexts.table_state.current_selection() {
let i = match self.contexts.table_state.selected() {
Some(i) => {
if i == 0 {
self.contexts.len() - 1
Expand All @@ -1470,7 +1469,7 @@ impl TaskwarriorTui {
}

pub fn context_select(&mut self) -> Result<()> {
let i = self.contexts.table_state.current_selection().unwrap_or_default();
let i = self.contexts.table_state.selected().unwrap_or_default();
let mut command = std::process::Command::new("task");
command.arg("context").arg(&self.contexts.rows[i].name);
command.output()?;
Expand Down
5 changes: 2 additions & 3 deletions src/pane/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use crate::{
app::{Mode, TaskwarriorTui},
event::KeyCode,
pane::Pane,
table::TableState,
};

#[derive(Debug, Clone, Default)]
Expand All @@ -55,7 +54,7 @@ impl ContextDetails {
}

pub struct ContextsState {
pub table_state: TableState,
pub table_state: ratatui::widgets::TableState,
pub report_height: u16,
pub columns: Vec<String>,
pub rows: Vec<ContextDetails>,
Expand All @@ -64,7 +63,7 @@ pub struct ContextsState {
impl ContextsState {
pub(crate) fn new() -> Self {
Self {
table_state: TableState::default(),
table_state: ratatui::widgets::TableState::default(),
report_height: 0,
columns: vec![NAME.to_string(), TYPE.to_string(), DEFINITION.to_string(), ACTIVE.to_string()],
rows: vec![],
Expand Down
2 changes: 1 addition & 1 deletion src/task_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn format_date_time(dt: NaiveDateTime) -> String {

pub fn format_date(dt: NaiveDateTime) -> String {
let offset = Local.offset_from_utc_datetime(&dt);
let dt = DateTime::<Local>::from_utc(dt, offset);
let dt = DateTime::<Local>::from_naive_utc_and_offset(dt, offset);
dt.format("%Y-%m-%d").to_string()
}

Expand Down

0 comments on commit 32a7318

Please sign in to comment.