run cargo fmt
This commit is contained in:
parent
8cf6fbce57
commit
368e3b2b30
@ -60,7 +60,9 @@ pub async fn put(url: &str, data: JsValue) -> Result<(), FetchError> {
|
||||
opts.body(Some(&data));
|
||||
|
||||
let request = Request::new_with_str_and_init(url, &opts)?;
|
||||
request.headers().set("Content-Type", "application/x-www-form-urlencoded")?;
|
||||
request
|
||||
.headers()
|
||||
.set("Content-Type", "application/x-www-form-urlencoded")?;
|
||||
self::send_request(request).await?;
|
||||
|
||||
Ok(())
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std::str::FromStr;
|
||||
use web_sys::{HtmlInputElement, HtmlSelectElement};
|
||||
use yew::{classes, html, Component, Context, Html, Properties, NodeRef};
|
||||
use yew_agent::{Dispatched, Dispatcher};
|
||||
use crate::event_bus::{EventBus, Request};
|
||||
use crate::events::Event;
|
||||
use std::str::FromStr;
|
||||
use web_sys::{HtmlInputElement, HtmlSelectElement};
|
||||
use yew::{classes, html, Component, Context, Html, NodeRef, Properties};
|
||||
use yew_agent::{Dispatched, Dispatcher};
|
||||
|
||||
pub enum Msg {
|
||||
AmountChanged,
|
||||
@ -31,7 +31,9 @@ impl Account {
|
||||
fn amount(&self) -> f64 {
|
||||
if let Some(amount_el) = self.amount_ref.cast::<HtmlInputElement>() {
|
||||
f64::from_str(&amount_el.value()).unwrap_or_default()
|
||||
} else { 0_f64 }
|
||||
} else {
|
||||
0_f64
|
||||
}
|
||||
}
|
||||
|
||||
fn is_amount_valid(&self) -> bool {
|
||||
@ -41,8 +43,14 @@ impl Account {
|
||||
fn selected_transfer_account(&self) -> Option<String> {
|
||||
if let Some(transfer_account_el) = self.transfer_account_ref.cast::<HtmlSelectElement>() {
|
||||
let value: String = transfer_account_el.value();
|
||||
if value.is_empty() || value == "undefined" { None } else { Some(value) }
|
||||
} else { None }
|
||||
if value.is_empty() || value == "undefined" {
|
||||
None
|
||||
} else {
|
||||
Some(value)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,16 +78,24 @@ impl Component for Account {
|
||||
}
|
||||
Msg::Deposit => {
|
||||
let amount = self.amount() + ctx.props().balance;
|
||||
self.event_bus.send(Request::EventBusMsg(Event::SetBalance(amount, ctx.props().nr.clone())));
|
||||
self.event_bus.send(Request::EventBusMsg(Event::SetBalance(
|
||||
amount,
|
||||
ctx.props().nr.clone(),
|
||||
)));
|
||||
|
||||
false
|
||||
}
|
||||
Msg::Withdraw => {
|
||||
let amount = ctx.props().balance - self.amount();
|
||||
if amount > 0_f64 {
|
||||
self.event_bus.send(Request::EventBusMsg(Event::SetBalance(amount, ctx.props().nr.clone())));
|
||||
self.event_bus.send(Request::EventBusMsg(Event::SetBalance(
|
||||
amount,
|
||||
ctx.props().nr.clone(),
|
||||
)));
|
||||
} else {
|
||||
self.event_bus.send(Request::EventBusMsg(Event::ShowError("Balance can not be overdrawn".into())));
|
||||
self.event_bus.send(Request::EventBusMsg(Event::ShowError(
|
||||
"Balance can not be overdrawn".into(),
|
||||
)));
|
||||
}
|
||||
|
||||
false
|
||||
@ -88,11 +104,18 @@ impl Component for Account {
|
||||
let amount = ctx.props().balance - self.amount();
|
||||
|
||||
if amount > 0_f64 {
|
||||
self.event_bus.send(Request::EventBusMsg(Event::SetBalance(amount, ctx.props().nr.clone())));
|
||||
self.event_bus.send(Request::EventBusMsg(Event::SetBalance(
|
||||
amount,
|
||||
ctx.props().nr.clone(),
|
||||
)));
|
||||
} else {
|
||||
let transfer_nr = self.selected_transfer_account();
|
||||
if let Some(transfer_nr) = transfer_nr {
|
||||
self.event_bus.send(Request::EventBusMsg(Event::Transfer(amount, ctx.props().nr.clone(), transfer_nr)));
|
||||
self.event_bus.send(Request::EventBusMsg(Event::Transfer(
|
||||
amount,
|
||||
ctx.props().nr.clone(),
|
||||
transfer_nr,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,21 +125,13 @@ impl Component for Account {
|
||||
}
|
||||
|
||||
fn view(&self, ctx: &Context<Self>) -> Html {
|
||||
let onchange = ctx
|
||||
.link()
|
||||
.callback(|_| Msg::AmountChanged);
|
||||
let onchange = ctx.link().callback(|_| Msg::AmountChanged);
|
||||
|
||||
let on_deposit = ctx
|
||||
.link()
|
||||
.callback(|_| Msg::Deposit);
|
||||
let on_deposit = ctx.link().callback(|_| Msg::Deposit);
|
||||
|
||||
let on_withdraw = ctx
|
||||
.link()
|
||||
.callback(|_| Msg::Withdraw);
|
||||
let on_withdraw = ctx.link().callback(|_| Msg::Withdraw);
|
||||
|
||||
let on_transfer = ctx
|
||||
.link()
|
||||
.callback(|_| Msg::Transfer);
|
||||
let on_transfer = ctx.link().callback(|_| Msg::Transfer);
|
||||
|
||||
html! {
|
||||
<>
|
||||
|
@ -10,7 +10,7 @@ pub enum Msg {
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct AccountsProps {
|
||||
pub account_nrs: Vec<String>,
|
||||
pub selected_nr: String
|
||||
pub selected_nr: String,
|
||||
}
|
||||
|
||||
pub struct Accounts {
|
||||
@ -49,12 +49,7 @@ impl Component for Accounts {
|
||||
}
|
||||
|
||||
impl Accounts {
|
||||
fn account_entry(
|
||||
&self,
|
||||
nr: &str,
|
||||
selected_nr: &str,
|
||||
ctx: &Context<Self>,
|
||||
) -> Html {
|
||||
fn account_entry(&self, nr: &str, selected_nr: &str, ctx: &Context<Self>) -> Html {
|
||||
let mut class = Classes::from("accounts__item");
|
||||
if selected_nr == nr {
|
||||
class.push("accounts__item-selected");
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::api;
|
||||
use crate::components::account::Account;
|
||||
use crate::components::accounts::Accounts;
|
||||
use crate::event_bus::EventBus;
|
||||
use crate::events::Event;
|
||||
use crate::api;
|
||||
use yew::{classes, html, Component, Context, Html};
|
||||
use yew_agent::{Bridge, Bridged};
|
||||
|
||||
@ -37,7 +37,7 @@ impl Component for Main {
|
||||
account_nrs: vec![],
|
||||
selected_balance: 0_f64,
|
||||
selected_nr: "".into(),
|
||||
selected_owner: "".into()
|
||||
selected_owner: "".into(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,10 +85,7 @@ impl Component for Main {
|
||||
});
|
||||
false
|
||||
}
|
||||
Event::Transfer(amount, from, to) => {
|
||||
|
||||
false
|
||||
}
|
||||
Event::Transfer(amount, from, to) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
use crate::components::main::Main;
|
||||
|
||||
mod api;
|
||||
mod client;
|
||||
mod components;
|
||||
mod event_bus;
|
||||
mod events;
|
||||
mod api;
|
||||
|
||||
fn main() {
|
||||
yew::start_app::<Main>();
|
||||
|
Loading…
Reference in New Issue
Block a user