diff options
| author | Joe Carstairs <me@joeac.net> | 2026-02-08 15:15:24 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-02-08 15:15:24 +0000 |
| commit | d5f1554949321f2ebfda89efe39b0477a6ff2e55 (patch) | |
| tree | 0fbb780f8df2c4c742c0b602febacd2a2d9684c8 /schist_desktop_gui/src/gui | |
| parent | d21a2500813b3fea4892fff9dbbf572e37b5d70d (diff) | |
task-085: transactions view has transactions
Diffstat (limited to 'schist_desktop_gui/src/gui')
4 files changed, 83 insertions, 61 deletions
diff --git a/schist_desktop_gui/src/gui/components.rs b/schist_desktop_gui/src/gui/components.rs index bb5590f..606c418 100644 --- a/schist_desktop_gui/src/gui/components.rs +++ b/schist_desktop_gui/src/gui/components.rs @@ -1,3 +1,4 @@ +mod account_navigation_entry; pub mod balances_view; pub mod bucket_navigation_entry; pub mod buckets_view; @@ -7,6 +8,7 @@ pub mod panel; pub mod text; pub mod transactions_view; +pub use account_navigation_entry::AccountNavigationEntry; pub use balances_view::BalancesView; pub use bucket_navigation_entry::BucketNavigationEntry; pub use buckets_view::BucketsView; diff --git a/schist_desktop_gui/src/gui/components/account_navigation_entry.rs b/schist_desktop_gui/src/gui/components/account_navigation_entry.rs new file mode 100644 index 0000000..6a582a7 --- /dev/null +++ b/schist_desktop_gui/src/gui/components/account_navigation_entry.rs @@ -0,0 +1,34 @@ +use iced::Element; +use schist_models::Account; + +use crate::{ + gui::components::{navigation, Text}, + impl_focusable, +}; + +#[derive(Clone, Debug, PartialEq)] +pub struct AccountNavigationEntry { + pub account: Account, + is_focused: bool, +} + +impl AccountNavigationEntry { + pub fn new(account: Account) -> Self { + Self { + account, + is_focused: false, + } + } +} + +impl<'a> From<&'a AccountNavigationEntry> + for Element<'a, navigation::Message<AccountNavigationEntry>> +{ + fn from(account_navigation_entry: &'a AccountNavigationEntry) -> Self { + Text::default(&account_navigation_entry.account.name) + .highlight_maybe(account_navigation_entry.is_focused) + .into() + } +} + +impl_focusable!(AccountNavigationEntry); diff --git a/schist_desktop_gui/src/gui/components/transactions_view.rs b/schist_desktop_gui/src/gui/components/transactions_view.rs index 1cb569c..59d7ae3 100644 --- a/schist_desktop_gui/src/gui/components/transactions_view.rs +++ b/schist_desktop_gui/src/gui/components/transactions_view.rs @@ -1,26 +1,28 @@ +use std::collections::HashMap; + use iced::{ alignment, widget::{column, row, Container}, Element, Length, }; -use schist_models::Account; +use itertools::Itertools; +use schist_models::{Account, Transaction}; use crate::{ - gui::components::{navigation, Navigation, Text}, + gui::components::{navigation, AccountNavigationEntry, Navigation, Text}, style::SPACING_LG, traits::{Component, Viewable}, }; #[derive(Clone, Debug)] pub struct TransactionsView { - accounts: Vec<Account>, - greeting: String, - navigation: Navigation<Text>, + navigation: Navigation<AccountNavigationEntry>, + transactions_by_account_id: HashMap<i32, Vec<Transaction>>, } #[derive(Clone, Debug)] pub enum Message { - NavigationMessage(navigation::Message<Text>), + NavigationMessage(navigation::Message<AccountNavigationEntry>), SelectNextTransaction, SelectPrevTransaction, SetAccounts(Vec<Account>), @@ -31,13 +33,20 @@ pub enum Action { } impl TransactionsView { - pub fn new(accounts: Vec<Account>, greeting: &str) -> Self { - let account_names = view_account_names(accounts.clone()); - let navigation = Navigation::new(account_names.clone().first().cloned(), account_names); + pub fn new(accounts: Vec<Account>, transactions: Vec<Transaction>) -> Self { + let account_navigation_entries: Vec<AccountNavigationEntry> = accounts + .into_iter() + .map(AccountNavigationEntry::new) + .collect(); + let navigation = Navigation::new( + account_navigation_entries.first().cloned(), + account_navigation_entries, + ); Self { - accounts: accounts, - greeting: greeting.to_owned(), navigation: navigation, + transactions_by_account_id: transactions + .into_iter() + .into_group_map_by(|t| t.account_id), } } } @@ -45,7 +54,20 @@ impl TransactionsView { impl<'a> Viewable<'a, Message> for TransactionsView { fn view(&'a self) -> Element<'a, Message> { let navigation = self.navigation.view().map(Message::NavigationMessage); - let main_content = column![Text::default(&self.greeting).as_element()]; + let main_content = column![ + Text::default("Hello, transactions!").as_element(), + Text::default(&format!( + "{} transactions in this account.", + self.navigation.active_option.clone().map_or( + 0, + |AccountNavigationEntry { account, .. }| self + .transactions_by_account_id + .get(&account.id) + .map_or(0, |transactions| transactions.len()) + ) + )) + .as_element(), + ]; row