Skip to content

Commit

Permalink
updated to seed 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
msuesskraut committed Nov 7, 2020
1 parent e746c4b commit 7358654
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ homepage = "https://msuesskraut.github.io/binoxxo/"
crate-type = ["cdylib"]

[dependencies]
seed = "0.7.0"
seed = "0.8.0"
wasm-bindgen = "0.2.68"
binoxxo = { version = "0.4.0", features = ["wasm-bindgen"] }
fluent-bundle = "0.13.1"
Expand Down
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ use crate::view::view;
use seed::browser::web_storage::LocalStorage;
use seed::prelude::*;

fn after_mount(_url: Url, _orders: &mut impl Orders<Message>) -> AfterMount<Model> {
fn init(_url: Url, _orders: &mut impl Orders<Message>) -> Model {
let difficulty = LocalStorage::get(DIFFICULTY_STORAGE).unwrap_or_default();
let language = LocalStorage::get(LANGUAGE_STORAGE).unwrap_or_default();
let helper = LocalStorage::get(HELPER_STORAGE).unwrap_or_default();
let model = Model::new(difficulty, helper, language);
AfterMount::new(model)
Model::new(difficulty, helper, language)
}

#[wasm_bindgen]
pub fn render() {
seed::App::builder(update, view)
.after_mount(after_mount)
.build_and_start();
seed::App::start("app", init, update, view);
}
19 changes: 9 additions & 10 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use binoxxo::field::Field;
use binoxxo::rules::{is_board_full, is_board_valid, is_move_valid};
use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};
use seed::{prelude::*, *};
use std::collections::HashMap;
use web_sys::console::log_1;

struct ViewBuilder<'a> {
Expand Down Expand Up @@ -61,7 +60,7 @@ impl<'a> ViewBuilder<'a> {
C![IF!(editable => "guess"), IF!(not(is_valid) => "error")],
style! {St::Width => format!("{}%", 100.0 / (size as f64))},
self.view_field(field),
IF!(editable => simple_ev(Ev::Click, Message::Toggle(CellPos { col, row })))
IF!(editable => ev(Ev::Click, move |_| { Message::Toggle(CellPos { col, row }) }))
]
}

Expand All @@ -78,7 +77,7 @@ impl<'a> ViewBuilder<'a> {
At::Href => "#";
},
self.tr(&format!("difficulty-{}", difficulty)),
simple_ev(Ev::Click, Message::NewGame(difficulty))
ev(Ev::Click, move |_| { Message::NewGame(difficulty) })
]
}

Expand Down Expand Up @@ -120,7 +119,7 @@ impl<'a> ViewBuilder<'a> {
Helper::Disabled => self.tr("helper-off"),
Helper::Enabled => self.tr("helper-on"),
},
simple_ev(Ev::Click, Message::ToggleHelper)
ev(Ev::Click, |_| { Message::ToggleHelper })
];

div![
Expand All @@ -146,7 +145,7 @@ impl<'a> ViewBuilder<'a> {
button![
C!["btn btn-primary"],
self.tr(&format!("difficulty-{}", difficulty)),
simple_ev(Ev::Click, Message::NewGame(difficulty))
ev(Ev::Click, move |_| { Message::NewGame(difficulty) })
]
}

Expand Down Expand Up @@ -201,10 +200,10 @@ impl<'a> ViewBuilder<'a> {

fn view_new_game(&self, difficulty: Difficulty) -> Vec<Node<Message>> {
// build arguments for translation difficulty-display
let mut difficulty_arg = HashMap::new();
difficulty_arg.insert(
let mut difficulty_arg = FluentArgs::new();
difficulty_arg.add(
"difficulty",
FluentValue::String(self.tr(&format!("difficulty-{}", difficulty)).into()),
FluentValue::from(self.tr(&format!("difficulty-{}", difficulty))),
);

let text = self.tr_with_args("difficulty-display", Some(&difficulty_arg));
Expand Down Expand Up @@ -260,7 +259,7 @@ impl<'a> ViewBuilder<'a> {
At::Title => self.tr("language-toggle");
},
i![C!["fas fa-language"]],
simple_ev(Ev::Click, Message::ToggleLanguage),
ev(Ev::Click, |_| { Message::ToggleLanguage }),
],
h1![self.tr("header")],
]
Expand All @@ -272,7 +271,7 @@ impl<'a> ViewBuilder<'a> {
C!["btn btn-secondary"],
id!("clear-board"),
self.tr("clear-board"),
simple_ev("click", Message::Clear)
ev("click", |_| { Message::Clear })
],
self.view_new_game(self.model.difficulty),
h4![self.tr("rules-header")],
Expand Down

0 comments on commit 7358654

Please sign in to comment.