début du ui

This commit is contained in:
thatscringebro
2025-12-17 07:55:40 -05:00
parent 55dfd16cd2
commit 33fb39e732
3 changed files with 137 additions and 12 deletions

View File

@@ -1,19 +1,49 @@
use ratatui::widgets::ListState;
use sqlite::Connection;
use crate::{data_layer, entities::Account};
pub enum CurrentScreen {
Main,
Exiting,
}
pub enum CurrentWidget {
AccountList,
TrxInfo,
TrxList,
}
pub struct AccountList {
accounts: Vec<Account>,
pub state: ListState,
}
impl AccountList {
fn new() -> AccountList {
return AccountList {
accounts: Vec::new(),
state: ListState::default(),
};
}
fn get_accounts(&self, con: &Connection) -> Vec<Account> {
if self.accounts.iter().count() == 0 {
return data_layer::get_accounts(con);
}
return self.accounts.clone();
}
}
pub struct App {
pub current_screen: CurrentScreen,
connection: Connection,
pub current_widget: CurrentWidget,
pub acc_list: AccountList,
pub connection: Connection,
exit: bool,
}
impl App {
pub fn new() -> App {
let connection = match Connection::open("ft_rs.db") {
let con = match Connection::open("ft_rs.db") {
Ok(con) => con,
Err(e) => {
eprintln!("Error opening database: {}", e);
@@ -22,8 +52,14 @@ impl App {
};
return App {
current_screen: CurrentScreen::Main,
connection: connection,
current_widget: CurrentWidget::AccountList,
acc_list: AccountList::new(),
connection: con,
exit: false,
};
}
pub fn get_list_accounts(&self) -> Vec<Account> {
return self.acc_list.get_accounts(&self.connection);
}
}