From 54750cd160d24eea6e83f18edd85ffcd563364b2 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Fri, 22 Sep 2023 22:11:15 -0700 Subject: [PATCH] cleaned out quick transaction --- src/app.rs | 2 +- src/db/tables.rs | 5 ++-- src/ui.rs | 5 +++- src/uis/history.rs | 5 +--- src/uis/manual_transaction.rs | 42 ++++++++++++++++++----------- src/uis/quick_transaction.rs | 51 +++++------------------------------ 6 files changed, 42 insertions(+), 68 deletions(-) diff --git a/src/app.rs b/src/app.rs index 88f2210..27aad9c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -78,7 +78,7 @@ pub enum ActiveFrame { pub struct States<'a> { pub nav_state: NavigationState<'a>, - pub transactions: QuickTransactionState<'a>, + pub transactions: QuickTransactionState, pub manual_transactions: ManualTransactionState, pub history: HistoryState, diff --git a/src/db/tables.rs b/src/db/tables.rs index 42fafbb..d025a06 100644 --- a/src/db/tables.rs +++ b/src/db/tables.rs @@ -87,11 +87,12 @@ impl Transaction { impl fmt::Display for Transaction { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, " T{:0>6} | {:>9} | {:>10}", + write!( + f, + " T{:0>6} | {:>9} | {:>10}", self.trns_id, self.trns_amount.to_decimal(2).to_string(), self.trns_date.to_string() ) } } - diff --git a/src/ui.rs b/src/ui.rs index e75b9ba..1b8169a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -10,7 +10,10 @@ use ratatui::{ use crate::{ app::{ActiveFrame, App}, - uis::{render_history_tab, render_manual_transaction, render_navigation_frame, render_quick_transaction}, + uis::{ + render_history_tab, render_manual_transaction, render_navigation_frame, + render_quick_transaction, + }, }; pub fn render(f: &mut Frame, app: &mut App) { diff --git a/src/uis/history.rs b/src/uis/history.rs index 4ceaf18..a0b63f1 100644 --- a/src/uis/history.rs +++ b/src/uis/history.rs @@ -90,10 +90,7 @@ pub fn render_history_tab(f: &mut Frame, body_rect: Rect, app: &m ])); lines.push(Line::from(vec![ Span::styled("Transaction Date: ", ident_style), - Span::styled( - selected_item.trns_date.to_string(), - value_style, - ), + Span::styled(selected_item.trns_date.to_string(), value_style), ])); } diff --git a/src/uis/manual_transaction.rs b/src/uis/manual_transaction.rs index f62bf5b..18c7a4e 100644 --- a/src/uis/manual_transaction.rs +++ b/src/uis/manual_transaction.rs @@ -16,6 +16,17 @@ use crate::{ use chrono::prelude::Local; use crossterm::event::{KeyCode, KeyEvent}; +#[derive(Clone, Copy, PartialEq, Eq)] +pub enum ManualDataFocus { + Account, + Amount, + Date, + Bucket, + Description, + Breakdowns, + Submit, +} + pub struct ManualTransactionState { pub focus: Option, pub show_popup: bool, @@ -56,7 +67,8 @@ impl ManualTransactionState { ManualDataFocus::Date => ManualDataFocus::Bucket, ManualDataFocus::Bucket => ManualDataFocus::Description, ManualDataFocus::Description => ManualDataFocus::Breakdowns, - ManualDataFocus::Breakdowns => ManualDataFocus::Account, + ManualDataFocus::Breakdowns => ManualDataFocus::Submit, + ManualDataFocus::Submit => ManualDataFocus::Account, } } else { ManualDataFocus::Account @@ -198,7 +210,7 @@ impl ManualTransactionState { } } } - } else if event.code == KeyCode::Enter{ + } else if event.code == KeyCode::Enter { app.states.manual_transactions.focus = Some(ManualDataFocus::Account); } } @@ -210,7 +222,6 @@ impl Default for ManualTransactionState { } } - pub fn render_manual_transaction(f: &mut Frame, body_rect: Rect, app: &App) { // Render the custom tab bar let constraints: Vec = vec![ @@ -227,6 +238,8 @@ pub fn render_manual_transaction(f: &mut Frame, body_rect: Rect, Constraint::Length(1), Constraint::Length(1), // Breakdown Constraint::Length(1), + Constraint::Length(1), // Submit Button + Constraint::Length(1), ]; let split_body = Layout::default() @@ -287,7 +300,7 @@ pub fn render_manual_transaction(f: &mut Frame, body_rect: Rect, render_manual_row( f, - split_body[split_body.len() - 4], + split_body[split_body.len() - 6], "Description: ", manual_state.description.clone().unwrap_or("".to_string()), manual_state.focus, @@ -296,13 +309,22 @@ pub fn render_manual_transaction(f: &mut Frame, body_rect: Rect, render_manual_row( f, - split_body[split_body.len() - 2], + split_body[split_body.len() - 4], "Transaction Breakdown: ", "[ + ]".to_string(), manual_state.focus, ManualDataFocus::Breakdowns, ); + render_manual_row( + f, + split_body[split_body.len() - 2], + "", + "Submit".to_string(), + manual_state.focus, + ManualDataFocus::Submit, + ); + if app.states.manual_transactions.focus == Some(ManualDataFocus::Account) && app.states.manual_transactions.show_popup { @@ -368,16 +390,6 @@ pub fn render_manual_transaction(f: &mut Frame, body_rect: Rect, } } -#[derive(Clone, Copy, PartialEq, Eq)] -pub enum ManualDataFocus { - Account, - Amount, - Date, - Bucket, - Description, - Breakdowns, -} - pub fn render_manual_row( f: &mut Frame, row_body_rect: Rect, diff --git a/src/uis/quick_transaction.rs b/src/uis/quick_transaction.rs index 5474b52..c7e4af4 100644 --- a/src/uis/quick_transaction.rs +++ b/src/uis/quick_transaction.rs @@ -9,72 +9,33 @@ use ratatui::{ Frame, }; -pub struct QuickTransactionState<'a> { - pub cur_tab_index: usize, - pub tabs: Vec<&'a str>, +pub struct QuickTransactionState { + } -impl<'a> QuickTransactionState<'a> { - pub fn new() -> QuickTransactionState<'a> { - QuickTransactionState { - cur_tab_index: 0, - tabs: vec!["Quick Entry", "Manual Entry"], +impl QuickTransactionState { + pub fn new() -> QuickTransactionState { + QuickTransactionState { } } - pub fn next_tab(&mut self) { - self.cur_tab_index = (self.cur_tab_index + 1) % self.tabs.len(); - } - pub fn handle_event(event: KeyEvent, app: &mut App) { // let transact_state = &app.states.transactions; if event.kind == KeyEventKind::Press { match event.code { - KeyCode::Tab => app.states.transactions.next_tab(), _ => {} } } } } -impl<'a> Default for QuickTransactionState<'a> { +impl Default for QuickTransactionState { fn default() -> Self { Self::new() } } pub fn render_quick_transaction(f: &mut Frame, body_rect: Rect, app: &App) { - let chunks = Layout::default() - .direction(Direction::Vertical) - .constraints([Constraint::Length(3), Constraint::Min(0)]) - .split(body_rect); - // Render the custom tab bar - let mut constraints: Vec = vec![]; - let tab_percent: u16 = (100 / app.states.transactions.tabs.len()) as u16; - for _ in 0..app.states.transactions.tabs.len() { - constraints.push(Constraint::Percentage(tab_percent)); - } - - let tab_chunks = Layout::default() - .direction(Direction::Horizontal) - .constraints(constraints) - .split(chunks[0]); - - for i in 0..app.states.transactions.tabs.len() { - let tab = Paragraph::new(Text::styled( - app.states.transactions.tabs[i], - Style::default().fg(Color::White), - )) - .alignment(ratatui::layout::Alignment::Center) - .block(Block::default().borders(Borders::ALL).style({ - if app.states.transactions.cur_tab_index == i { - Style::default().bg(Color::Blue) - } else { - Style::default() - } - })); - f.render_widget(tab, tab_chunks[i]) - } }