fixed list

This commit is contained in:
thatscringebro 2025-12-17 19:13:54 -05:00
parent dd6b6f7b2c
commit 2395d72c7e
3 changed files with 9 additions and 5 deletions

View File

@ -22,9 +22,11 @@ pub struct AccountList {
} }
impl AccountList { impl AccountList {
fn new() -> AccountList { fn new() -> AccountList {
let mut list_state = ListState::default();
list_state.select_first();
return AccountList { return AccountList {
accounts: Vec::new(), accounts: Vec::new(),
state: ListState::default(), state: list_state,
}; };
} }

View File

@ -80,7 +80,7 @@ pub fn get_account(con: &Connection, id: i64) -> Account {
pub fn get_account_total(id: i64, con: &Connection) -> f64 { pub fn get_account_total(id: i64, con: &Connection) -> f64 {
let mut query = "SELECT SUM(amount) as total FROM Transactions".to_owned(); let mut query = "SELECT SUM(amount) as total FROM Transactions".to_owned();
if id != 0 { if id != 0 {
query.push_str("WHERE account_id = ?") query.push_str(" WHERE account_id = ?")
} }
let mut statement = con.prepare(query).unwrap(); let mut statement = con.prepare(query).unwrap();

View File

@ -10,7 +10,10 @@ use ratatui::{
palette::tailwind::{BLUE, GREEN, SLATE}, palette::tailwind::{BLUE, GREEN, SLATE},
}, },
text::{Line, Text}, text::{Line, Text},
widgets::{Block, Borders, Clear, HighlightSpacing, List, ListItem, Paragraph, Widget, Wrap}, widgets::{
Block, Borders, Clear, HighlightSpacing, List, ListItem, Paragraph, StatefulWidget, Widget,
Wrap,
},
}; };
const NORMAL_ROW_BG: Color = SLATE.c950; const NORMAL_ROW_BG: Color = SLATE.c950;
@ -63,9 +66,8 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
.highlight_symbol(">") .highlight_symbol(">")
.highlight_spacing(HighlightSpacing::Always); .highlight_spacing(HighlightSpacing::Always);
frame.render_widget(list, layout[0]); StatefulWidget::render(list, layout[0], frame.buffer_mut(), &mut app.acc_list.state);
app.first_ac();
let info = if let Some(i) = app.acc_list.state.selected() { let info = if let Some(i) = app.acc_list.state.selected() {
format!( format!(
"Total: {}", "Total: {}",