summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/new_transaction_form.rs
blob: 58509b173f57a9bccaf8de98e5c7dfe81c0cb0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use iced::{Element, widget::row};

use crate::{gui::components::{Text, button, input::input}, style::SPACING_SM, traits::{Component, Viewable}};

#[derive(Clone, Debug)]
pub struct NewTransactionForm {
    day: String,
    month: String,
    year: String,
    bucket: String,
    payee: String,
    quantity: String,
    submit_text: Text,
}

#[derive(Clone, Debug)]
pub enum Message {
    DayInputChanged(String),
    MonthInputChanged(String),
    YearInputChanged(String),
    BucketInputChanged(String),
    PayeeInputChanged(String),
    QuantityInputChanged(String),
    Submit,
}

pub enum Action { None }

impl NewTransactionForm {
    pub fn new() -> Self {
        Self {
            day: String::new(),
            month: String::new(),
            year: String::new(),
            bucket: String::new(),
            payee: String::new(),
            quantity: String::new(),
            submit_text: Text::new("+ Add"),
        }
    }
}

impl<'a> Viewable<'a, Message> for NewTransactionForm {
    fn view(&'a self) -> Element<'a, Message> {
        row![
            input("25").on_input(Message::DayInputChanged).width(32.0),
            input("12").on_input(Message::MonthInputChanged).width(32.0),
            input("2026").on_input(Message::YearInputChanged).width(48.0),
            input("").on_input(Message::BucketInputChanged).width(138.0),
            input("").on_input(Message::PayeeInputChanged).width(266.0),
            input("").on_input(Message::QuantityInputChanged).width(104.0),
            button(&self.submit_text, Message::Submit, false).width(64.0),
        ].spacing(u32::from(SPACING_SM))
        .into()
    }
}

impl<'a> Component<'a, Message, Action> for NewTransactionForm {
    fn update(&mut self, message: Message) -> Action {
        Action::None
    }
}