summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/transactions_view.rs
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2025-08-13 07:50:21 +0000
committerjoeac <me@joeac.net>2025-08-13 07:50:21 +0000
commitee3cd780e21260257b401c3f5cbababd9e27a15a (patch)
treeb0571649a1a1a7644dbc50183cc4c3a29966a963 /schist_desktop_gui/src/gui/components/transactions_view.rs
parent49342e8b553d5c92f1c043b3b0ce18bdf1c2cd44 (diff)
task-073
Co-authored-by: Joe Carstairs <jcarstairs@scottlogic.com> Reviewed-on: https://git.joeac.net/joeac/schist/pulls/1 Co-authored-by: Joe Carstairs <me@joeac.net> Co-committed-by: Joe Carstairs <me@joeac.net>
Diffstat (limited to 'schist_desktop_gui/src/gui/components/transactions_view.rs')
-rw-r--r--schist_desktop_gui/src/gui/components/transactions_view.rs118
1 files changed, 118 insertions, 0 deletions
diff --git a/schist_desktop_gui/src/gui/components/transactions_view.rs b/schist_desktop_gui/src/gui/components/transactions_view.rs
new file mode 100644
index 0000000..6181a14
--- /dev/null
+++ b/schist_desktop_gui/src/gui/components/transactions_view.rs
@@ -0,0 +1,118 @@
+use iced::{
+ alignment,
+ widget::{column, row, Container},
+ Element, Length,
+};
+use schist_models::account::Account;
+
+use crate::{
+ gui::components::{navigation, Navigation, Text},
+ style::SPACING_LG,
+ traits::{Component, Viewable},
+};
+
+#[derive(Clone, Debug)]
+pub struct TransactionsView {
+ accounts: Vec<Account>,
+ greeting: String,
+ navigation: Navigation<Text>,
+}
+
+#[derive(Clone, Debug)]
+pub enum Message {
+ NavigationMessage(navigation::Message<Text>),
+ SelectNextTransaction,
+ SelectPrevTransaction,
+ SetAccounts(Vec<Account>),
+}
+
+pub enum Action {
+ None,
+}
+
+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);
+ Self {
+ accounts: accounts,
+ greeting: greeting.to_owned(),
+ navigation: navigation,
+ }
+ }
+}
+
+impl<'a> Viewable<'a, Message> for TransactionsView {
+ fn view(&self) -> Element<Message> {
+ let navigation = self.navigation.view().map(Message::NavigationMessage);
+ let main_content = column![iced::widget::text(self.greeting.clone())];
+ row![
+ Container::new(navigation).width(Length::FillPortion(1)),
+ Container::new(main_content).width(Length::FillPortion(3)),
+ ]
+ .align_y(alignment::Vertical::Center)
+ .height(Length::Fill)
+ .spacing(SPACING_LG)
+ .into()
+ }
+}
+
+impl<'a> Component<'a, Message, Action> for TransactionsView {
+ fn update(&mut self, message: Message) -> Action {
+ match message {
+ Message::NavigationMessage(message) => {
+ match self.navigation.update(message) {
+ navigation::Action::SelectOption(group_name) => {
+ self.greeting = make_greeting(group_name);
+ Action::None
+ }
+ navigation::Action::None => Action::None,
+ };
+ Action::None
+ }
+ Message::SetAccounts(accounts) => {
+ self.accounts = accounts.clone();
+ match self
+ .navigation
+ .update(navigation::Message::SetOptions(view_account_names(
+ accounts,
+ ))) {
+ navigation::Action::SelectOption(option) => {
+ self.greeting = make_greeting(option);
+ Action::None
+ }
+ navigation::Action::None => Action::None,
+ }
+ }
+ Message::SelectNextTransaction => {
+ match self.navigation.update(navigation::Message::SelectNext) {
+ navigation::Action::SelectOption(option) => {
+ self.greeting = make_greeting(option);
+ Action::None
+ }
+ navigation::Action::None => Action::None,
+ }
+ }
+ Message::SelectPrevTransaction => {
+ match self.navigation.update(navigation::Message::SelectPrev) {
+ navigation::Action::SelectOption(option) => {
+ self.greeting = make_greeting(option);
+ Action::None
+ }
+ navigation::Action::None => Action::None,
+ }
+ }
+ }
+ }
+}
+
+fn make_greeting(account_name: Text) -> String {
+ format!("Hello, {} account!", account_name.content)
+}
+
+fn view_account_names(accounts: Vec<Account>) -> Vec<Text> {
+ accounts
+ .iter()
+ .map(|acc| Text::new(acc.name.clone()))
+ .collect()
+}