32 lines
782 B
Rust
32 lines
782 B
Rust
use ratatui::widgets::ListState;
|
|
use sqlite::Connection;
|
|
|
|
use crate::{data_layer, entities::*};
|
|
|
|
pub struct TrxList {
|
|
trx: Vec<Transaction>,
|
|
ac_id: i64,
|
|
pub state: ListState,
|
|
}
|
|
impl TrxList {
|
|
pub fn new() -> TrxList {
|
|
let mut list_state = ListState::default();
|
|
list_state.select_first();
|
|
return TrxList {
|
|
trx: Vec::new(),
|
|
state: list_state,
|
|
ac_id: 0,
|
|
};
|
|
}
|
|
|
|
pub fn get_trx(&mut self, ac_id: i64, con: &Connection) -> Vec<Transaction> {
|
|
if ac_id == -1 {
|
|
return Vec::new();
|
|
}
|
|
if self.trx.iter().count() == 0 || self.ac_id != ac_id {
|
|
self.trx = data_layer::get_account_transactions(con, ac_id);
|
|
}
|
|
return self.trx.clone();
|
|
}
|
|
}
|