trx as list => to change to table

This commit is contained in:
thatscringebro
2025-12-18 15:57:49 -05:00
parent 2395d72c7e
commit df4fd0202d
3 changed files with 79 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ use sqlite::Connection;
use crate::{
data_layer,
entities::{Account, AccountType},
entities::{Account, AccountType, Transaction},
};
pub enum CurrentScreen {
@@ -38,10 +38,39 @@ impl AccountList {
}
}
pub struct TrxList {
trx: Vec<Transaction>,
pub state: ListState,
}
impl TrxList {
fn new() -> TrxList {
let mut list_state = ListState::default();
list_state.select_first();
return TrxList {
trx: Vec::new(),
state: list_state,
};
}
fn get_trx(&self, con: &Connection, app: &App) -> Vec<Transaction> {
if self.trx.iter().count() == 0 {
if let Some(i) = app.acc_list.state.selected() {
return data_layer::get_account_transactions(
con,
app.get_list_accounts()[i].get_id(),
);
}
return Vec::new();
}
return self.trx.clone();
}
}
pub struct App {
pub current_screen: CurrentScreen,
pub current_widget: CurrentWidget,
pub acc_list: AccountList,
pub trx_list: TrxList,
pub connection: Connection,
exit: bool,
}
@@ -59,6 +88,7 @@ impl App {
current_screen: CurrentScreen::Main,
current_widget: CurrentWidget::AccountList,
acc_list: AccountList::new(),
trx_list: TrxList::new(),
connection: con,
exit: false,
};
@@ -80,4 +110,19 @@ impl App {
pub fn previous_ac(&mut self) {
self.acc_list.state.select_previous();
}
pub fn get_list_trx(&self) -> Vec<Transaction> {
let accounts = &self.trx_list.get_trx(&self.connection, self);
return accounts.to_vec();
}
pub fn first_tr(&mut self) {
self.trx_list.state.select_first();
}
pub fn next_tr(&mut self) {
self.trx_list.state.select_next();
}
pub fn previous_tr(&mut self) {
self.trx_list.state.select_previous();
}
}