Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions tui/src/key_checker/key_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ use crate::page_handler::{
SummaryTab, TableData, TxTab,
};
use crate::pages::{
ChoicePopupState, ConfigChoices, DeletionChoices, InfoPopupState, MovementDirection,
NewPathChoices, PopupType,
ACTIVITY_TABLE_ID, ChoicePopupState, ConfigChoices, DeletionChoices, HOME_TABLE_ID,
InfoPopupState, MovementDirection, NewPathChoices, PopupType, SEARCH_TABLE_ID,
SUMMARY_TABLE_ID,
};
use crate::theme::Theme;
use crate::tx_handler::TxData;
Expand Down Expand Up @@ -344,6 +345,8 @@ impl<'a> InputKeyHandler<'a> {
LogType::Info,
);
}

self.lerp_state.clear_lerp(SEARCH_TABLE_ID);
self.reload_activity_table()?;
}
Ok(())
Expand Down Expand Up @@ -567,7 +570,10 @@ impl<'a> InputKeyHandler<'a> {
HomeTab::Table => {}
},
CurrentUi::AddTx => self.add_tx_data.move_index_right(self.add_tx_tab),
CurrentUi::Search => self.search_data.move_index_right(self.search_tab),
CurrentUi::Search => {
self.search_data.move_index_right(self.search_tab);
self.lerp_state.clear_lerp(SEARCH_TABLE_ID);
}
CurrentUi::Chart => {
if !*self.chart_hidden_mode {
match self.chart_tab {
Expand Down Expand Up @@ -611,20 +617,26 @@ impl<'a> InputKeyHandler<'a> {
}
SummaryTab::Table => {}
}

self.lerp_state.clear_lerp(SUMMARY_TABLE_ID);
}
}
CurrentUi::Activity => match self.activity_tab {
ActivityTab::Years => {
self.activity_months.set_index_zero();
self.activity_years.next_yearly();
self.reload_activity_table()?;
}
ActivityTab::Months => {
self.activity_months.next();
self.reload_activity_table()?;
}
ActivityTab::List => {}
},
CurrentUi::Activity => {
match self.activity_tab {
ActivityTab::Years => {
self.activity_months.set_index_zero();
self.activity_years.next_yearly();
self.reload_activity_table()?;
}
ActivityTab::Months => {
self.activity_months.next();
self.reload_activity_table()?;
}
ActivityTab::List => {}
};

self.lerp_state.clear_lerp(ACTIVITY_TABLE_ID);
}
CurrentUi::Initial => {}
}

Expand Down Expand Up @@ -1899,6 +1911,8 @@ impl InputKeyHandler<'_> {

*self.home_table = TableData::new(self.home_txs.tx_array());

self.lerp_state.clear_lerp(HOME_TABLE_ID);

Ok(())
}

Expand Down
8 changes: 6 additions & 2 deletions tui/src/pages/activity_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::page_handler::{ActivityTab, IndexedData, TableData};
use crate::theme::Theme;
use crate::utility::{LerpState, create_tab, main_block, styled_block, tab_highlight_style};

pub const ACTIVITY_TABLE_ID: &str = "activity_table_row";

pub fn activity_ui(
f: &mut Frame,
months: &IndexedData,
Expand Down Expand Up @@ -82,7 +84,9 @@ pub fn activity_ui(

let tx_count = activity_view.total_activity();
let lerp_id = "activity_tx_count";
let lerp_tx_count = lerp_state.lerp(lerp_id, tx_count as f64) as i64;
let lerp_tx_count = lerp_state.lerp(lerp_id, tx_count as f64, None) as i64;

let lerp_row = lerp_state.lerp(ACTIVITY_TABLE_ID, tx_count as f64, Some(0.50)) as usize;

let table_name = format!("Transactions: {lerp_tx_count}");

Expand All @@ -104,7 +108,7 @@ pub fn activity_ui(
.height(1)
.bottom_margin(0);

let activity_rows = table_data.items.iter().map(|item| {
let activity_rows = table_data.items.iter().take(lerp_row).map(|item| {
let height = 1;
let cells = item.iter().map(|c| Cell::from(c.separate_with_commas()));
Row::new(cells)
Expand Down
2 changes: 1 addition & 1 deletion tui/src/pages/add_tx_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn add_tx_ui(
index += 1;

let lerp_id = format!("{row_type}:{index}");
let to_show = lerp_state.lerp(&lerp_id, actual_data);
let to_show = lerp_state.lerp(&lerp_id, actual_data, None);

// re-add the previously removed symbol if is the Changes row
// Otherwise separate the number with commas
Expand Down
2 changes: 1 addition & 1 deletion tui/src/pages/chart_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn chart_ui(
let total_loop = final_date.signed_duration_since(checking_date).num_days() as f64;

let lerp_id = "chart_loop_size";
let mut to_loop = lerp_state.lerp(lerp_id, total_loop);
let mut to_loop = lerp_state.lerp(lerp_id, total_loop, None);

// labels of the x axis
date_labels.push(checking_date.to_string());
Expand Down
11 changes: 8 additions & 3 deletions tui/src/pages/home_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::page_handler::{HomeRow, HomeTab, IndexedData, TableData};
use crate::theme::Theme;
use crate::utility::{LerpState, create_tab, main_block, styled_block, tab_highlight_style};

pub const HOME_TABLE_ID: &str = "home_table_row";

pub const BALANCE_BOLD: [&str; 7] = [
"Balance",
"Changes",
Expand Down Expand Up @@ -58,7 +60,9 @@ pub fn home_ui(

let tx_count = home_table.items.len();
let lerp_id = "home_tx_count";
let lerp_tx_count = lerp_state.lerp(lerp_id, tx_count as f64) as i64;
let lerp_tx_count = lerp_state.lerp(lerp_id, tx_count as f64, None) as i64;

let lerp_tx_row = lerp_state.lerp(HOME_TABLE_ID, tx_count as f64, Some(0.50)) as i64;

let table_name = format!("Transactions: {lerp_tx_count}");

Expand All @@ -76,6 +80,7 @@ pub fn home_ui(
let rows = home_table
.items
.iter()
.take(lerp_tx_row as usize)
.enumerate()
.map(|(row_index, item)| {
let cells = item.iter().enumerate().map(|(index, c)| {
Expand All @@ -84,7 +89,7 @@ pub fn home_ui(
};

let lerp_id = format!("home_table:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

Cell::from(format!("{new_c:.2}").separate_with_commas())
});
Expand Down Expand Up @@ -183,7 +188,7 @@ pub fn home_ui(
};

let lerp_id = format!("{row_type}:{index}");
let to_show = lerp_state.lerp(&lerp_id, actual_data);
let to_show = lerp_state.lerp(&lerp_id, actual_data, None);

// re-add the previously removed symbol if is the Changes row
// Otherwise separate the number with commas
Expand Down
9 changes: 7 additions & 2 deletions tui/src/pages/search_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use crate::theme::Theme;
use crate::tx_handler::TxData;
use crate::utility::{LerpState, main_block, styled_block};

pub const SEARCH_TABLE_ID: &str = "search_table_row";

pub fn search_ui(
f: &mut Frame,
search_data: &TxData,
Expand Down Expand Up @@ -43,13 +45,16 @@ pub fn search_ui(

let tx_count = search_table.items.len();
let lerp_id = "home_tx_count";
let lerp_tx_count = lerp_state.lerp(lerp_id, tx_count as f64) as i64;
let lerp_tx_count = lerp_state.lerp(lerp_id, tx_count as f64, None) as i64;

let lerp_row = lerp_state.lerp(SEARCH_TABLE_ID, tx_count as f64, Some(0.50)) as usize;

let table_name = format!("Transactions: {lerp_tx_count}");

let rows = search_table
.items
.iter()
.take(lerp_row)
.enumerate()
.map(|(row_index, item)| {
let height = 1;
Expand All @@ -62,7 +67,7 @@ pub fn search_ui(
};

let lerp_id = format!("search_table:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

Cell::from(format!("{new_c:.2}").separate_with_commas())
});
Expand Down
41 changes: 26 additions & 15 deletions tui/src/pages/summary_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::utility::{
tab_highlight_style,
};

pub const SUMMARY_TABLE_ID: &str = "summary_table_row";

/// The function draws the Summary page of the interface.
pub fn summary_ui(
f: &mut Frame,
Expand All @@ -30,6 +32,12 @@ pub fn summary_ui(
) {
let size = f.area();

let tags_count = table_data.items.len();
let lerp_id = "summary_tags_count";
let lerp_tags_count = lerp_state.lerp(lerp_id, tags_count as f64, None) as i64;

let lerp_row = lerp_state.lerp(SUMMARY_TABLE_ID, tags_count as f64, Some(0.50)) as usize;

let tag_header = if let SortingType::Tags = summary_sort {
"Tags ↑"
} else {
Expand Down Expand Up @@ -202,6 +210,7 @@ pub fn summary_ui(
let rows = table_data
.items
.iter()
.take(lerp_row)
.enumerate()
.map(|(row_index, item)| {
let cells = item.iter().enumerate().map(|(index, c)| {
Expand All @@ -213,7 +222,7 @@ pub fn summary_ui(

let Ok(parsed_num) = c.parse::<f64>() else {
if c == "∞" {
let new_c = lerp_state.lerp(&lerp_id, 0.0);
let new_c = lerp_state.lerp(&lerp_id, 0.0, None);
return Cell::from(format!("{new_c:.2}").separate_with_commas());
}

Expand All @@ -226,15 +235,15 @@ pub fn summary_ui(
if let Some(sym) = symbol {
let c = c.replace(sym, "");
if let Ok(parsed_num) = c.parse::<f64>() {
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

return Cell::from(format!("{sym}{new_c:.2}").separate_with_commas());
}
}
return Cell::from(c.separate_with_commas());
};

let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

Cell::from(format!("{new_c:.2}").separate_with_commas())
});
Expand Down Expand Up @@ -268,9 +277,11 @@ pub fn summary_ui(
]
};

let tags_text = format!("Tags: {lerp_tags_count}");

let mut table_area = Table::new(rows, table_width)
.header(tag_table_header)
.block(styled_block("Tags", theme))
.block(styled_block(&tags_text, theme))
.style(Style::default().fg(theme.border()));

let summary_rows_largest =
Expand All @@ -282,7 +293,7 @@ pub fn summary_ui(
let cells = item.into_iter().enumerate().map(|(index, c)| {
let mut cell = if let Ok(parsed_num) = c.parse::<f64>() {
let lerp_id = format!("summary_table_largest:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

Cell::from(format!("{new_c:.2}").separate_with_commas())
} else {
Expand Down Expand Up @@ -326,7 +337,7 @@ pub fn summary_ui(
let cells = item.into_iter().enumerate().map(|(index, c)| {
let mut cell = if let Ok(parsed_num) = c.parse::<f64>() {
let lerp_id = format!("summary_table_peak:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

let text = if index == 1 && row_index == 2 {
// Month checked value. No need float for this
Expand Down Expand Up @@ -376,7 +387,7 @@ pub fn summary_ui(
let cells = item.into_iter().enumerate().map(|(index, c)| {
let mut cell = if let Ok(parsed_num) = c.parse::<f64>() {
let lerp_id = format!("method_table:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

Cell::from(format!("{new_c:.2}").separate_with_commas())
} else {
Expand All @@ -390,7 +401,7 @@ pub fn summary_ui(
let c = c.replace(sym, "");
if let Ok(parsed_num) = c.parse::<f64>() {
let lerp_id = format!("method_table:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

return Cell::from(
format!("{sym}{new_c:.2}").separate_with_commas(),
Expand All @@ -400,7 +411,7 @@ pub fn summary_ui(

if c == "∞" {
let lerp_id = format!("method_table:{index}:{row_index}");
lerp_state.lerp(&lerp_id, 0.0);
lerp_state.lerp(&lerp_id, 0.0, None);
}
Cell::from(c.separate_with_commas())
};
Expand Down Expand Up @@ -468,7 +479,7 @@ pub fn summary_ui(
let lerp_id = format!("lend_borrow_table:{index}:{row_index}");

if let Ok(parsed_num) = c.parse::<f64>() {
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

Cell::from(format!("{new_c:.2}").separate_with_commas())
} else {
Expand All @@ -481,14 +492,14 @@ pub fn summary_ui(
if let Some(sym) = symbol {
let c = c.replace(sym, "");
if let Ok(parsed_num) = c.parse::<f64>() {
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

return Cell::from(format!("{sym}{new_c:.2}").separate_with_commas());
}
}

if c == "∞" {
lerp_state.lerp(&lerp_id, 0.0);
lerp_state.lerp(&lerp_id, 0.0, None);
}
Cell::from(c.separate_with_commas())
}
Expand Down Expand Up @@ -523,13 +534,13 @@ pub fn summary_ui(
let cells = item.iter().enumerate().map(|(index, c)| {
let mut cell = if let Ok(parsed_num) = c.parse::<f64>() {
let lerp_id = format!("summary_rows_net:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

Cell::from(format!("{new_c:.2}").separate_with_commas())
} else {
if c == "∞" {
let lerp_id = format!("summary_rows_net:{index}:{row_index}");
lerp_state.lerp(&lerp_id, 0.0);
lerp_state.lerp(&lerp_id, 0.0, None);
}

let symbol = if c.contains('↑') || c.contains('↓') {
Expand All @@ -542,7 +553,7 @@ pub fn summary_ui(
let c = c.replace(sym, "");
if let Ok(parsed_num) = c.parse::<f64>() {
let lerp_id = format!("summary_net_rows:{index}:{row_index}");
let new_c = lerp_state.lerp(&lerp_id, parsed_num);
let new_c = lerp_state.lerp(&lerp_id, parsed_num, None);

return Cell::from(format!("{sym}{new_c:.2}").separate_with_commas());
}
Expand Down
Loading
Loading