Compare commits
1 commit
main
...
livecoding
Author | SHA1 | Date | |
---|---|---|---|
cd02c48a14 |
1 changed files with 2 additions and 31 deletions
33
src/main.rs
33
src/main.rs
|
@ -5,6 +5,7 @@ use openmensa_rs::{request::MealRequest, Meal};
|
|||
use seed::{prelude::*, *};
|
||||
|
||||
const DATE_ISO_FMT: &str = "%Y-%m-%d";
|
||||
const DATE_DE_FMT: &str = "%d.%m.%Y";
|
||||
|
||||
// ------ ------
|
||||
// Init
|
||||
|
@ -66,37 +67,7 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||
|
||||
// `view` describes what to display.
|
||||
fn view(model: &Model) -> Node<Msg> {
|
||||
div![
|
||||
// button![model.counter, ev(Ev::Click, |_| Msg::Increment),],
|
||||
h1![format!("Speiseplan vom {}", model.date.format("%d.%m.%Y"))],
|
||||
input![
|
||||
attrs! {
|
||||
At::Type => "date",
|
||||
At::Value => model.date.format(DATE_ISO_FMT)
|
||||
},
|
||||
input_ev(Ev::Input, Msg::SetDate),
|
||||
],
|
||||
if &model.meals.len() > &0 {
|
||||
view_meals(&model.meals)
|
||||
} else {
|
||||
p!["Kein Speiseplan verfügbar"]
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
fn view_meals(meals: &[Meal]) -> Node<Msg> {
|
||||
ul![meals.iter().map(|meal| {
|
||||
let price = meal.prices().students();
|
||||
let price_str = match price {
|
||||
Some(p) => format!("{:.2} €", p),
|
||||
None => String::from("unbekannt"),
|
||||
};
|
||||
|
||||
li![
|
||||
el_key(&meal.id()),
|
||||
format!("{} ({})", meal.name(), price_str),
|
||||
]
|
||||
})]
|
||||
div!["Hello World"]
|
||||
}
|
||||
|
||||
// ------ ------
|
||||
|
|
Loading…
Reference in a new issue