cleaned out quick transaction

This commit is contained in:
Nickiel12 2023-09-22 22:11:15 -07:00
parent 057cdb02c0
commit 54750cd160
6 changed files with 42 additions and 68 deletions

View file

@ -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,

View file

@ -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()
)
}
}

View file

@ -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<B: Backend>(f: &mut Frame<B>, app: &mut App) {

View file

@ -90,10 +90,7 @@ pub fn render_history_tab<B: Backend>(f: &mut Frame<B>, 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),
]));
}

View file

@ -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<ManualDataFocus>,
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<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
// Render the custom tab bar
let constraints: Vec<Constraint> = vec![
@ -227,6 +238,8 @@ pub fn render_manual_transaction<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, 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<B: Backend>(f: &mut Frame<B>, body_rect: Rect,
}
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ManualDataFocus {
Account,
Amount,
Date,
Bucket,
Description,
Breakdowns,
}
pub fn render_manual_row<B: Backend>(
f: &mut Frame<B>,
row_body_rect: Rect,

View file

@ -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<B: Backend>(f: &mut Frame<B>, 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<Constraint> = 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])
}
}