table
This commit is contained in:
15
src/app.rs
15
src/app.rs
@@ -1,4 +1,3 @@
|
||||
use ratatui::widgets::ListState;
|
||||
use sqlite::Connection;
|
||||
|
||||
use crate::{data_layer, entities::*, enums::*};
|
||||
@@ -7,11 +6,10 @@ pub struct App {
|
||||
pub current_screen: CurrentScreen,
|
||||
pub current_widget: CurrentWidget,
|
||||
pub acc_list: AccountList,
|
||||
pub trx_list: TrxList,
|
||||
pub trx_table: TrxTable,
|
||||
pub new_account: Account,
|
||||
pub new_transaction: Transaction,
|
||||
pub connection: Connection,
|
||||
exit: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -30,11 +28,10 @@ impl App {
|
||||
current_screen: CurrentScreen::Main,
|
||||
current_widget: CurrentWidget::AccountList,
|
||||
acc_list: AccountList::new(),
|
||||
trx_list: TrxList::new(),
|
||||
trx_table: TrxTable::new(),
|
||||
new_account: Account::new(0, String::new(), AccountType::Cash),
|
||||
new_transaction: Transaction::new_empty(),
|
||||
connection: con,
|
||||
exit: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,16 +48,16 @@ impl App {
|
||||
|
||||
pub fn get_list_trx(&mut self) -> Vec<Transaction> {
|
||||
let accounts = self
|
||||
.trx_list
|
||||
.trx_table
|
||||
.get_trx(self.acc_list.get_selected_id(), &self.connection);
|
||||
return accounts.to_vec();
|
||||
}
|
||||
|
||||
pub fn next_tr(&mut self) {
|
||||
self.trx_list.state.select_next();
|
||||
self.trx_table.state.select_next();
|
||||
}
|
||||
pub fn previous_tr(&mut self) {
|
||||
self.trx_list.state.select_previous();
|
||||
self.trx_table.state.select_previous();
|
||||
}
|
||||
|
||||
pub fn save_new_account(&mut self) {
|
||||
@@ -71,7 +68,7 @@ impl App {
|
||||
|
||||
pub fn save_new_tr(&mut self) {
|
||||
let tr = data_layer::upsert_transaction(&self.connection, self.new_transaction.clone());
|
||||
self.trx_list.add_tr(tr);
|
||||
self.trx_table.add_tr(tr);
|
||||
self.new_transaction = Transaction::new_empty();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user