diff --git a/Cargo.lock b/Cargo.lock index a621838..9b5a83e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -475,8 +475,6 @@ dependencies = [ "http", "js-sys", "pin-project", - "serde", - "serde_json", "thiserror", "wasm-bindgen", "wasm-bindgen-futures", diff --git a/backend/src/main.rs b/backend/src/main.rs index 965e6ca..5541a2f 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -32,7 +32,7 @@ struct Opt { #[clap(short, long)] quiet: bool, - #[clap(long, short, default_value = "127.0.0.0:8000")] + #[clap(long, short, default_value = "127.0.0.1:8000")] bind: SocketAddr, #[clap(long, default_value = "./www")] diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml index 66bf870..4c88d89 100644 --- a/frontend/Cargo.toml +++ b/frontend/Cargo.toml @@ -10,7 +10,7 @@ wasm-bindgen = "=0.2.87" # must match Trunk.toml serde = { version = "1.0.0", features = ['derive'] } ron = "0.7.1" chrono = { version = "0.4.20", features = ["serde"] } -gloo-net = "0.4.0" +gloo-net = { version = "0.4.0", default-features = false, features = ["websocket"] } gloo-console = "0.3.0" [dependencies.css_typegen] diff --git a/frontend/Trunk.toml b/frontend/Trunk.toml index 53e9227..6aad5e8 100644 --- a/frontend/Trunk.toml +++ b/frontend/Trunk.toml @@ -7,7 +7,7 @@ wasm_bindgen = "0.2.87" [[proxy]] # This WebSocket proxy example has a backend and ws field. This example will listen for # WebSocket connections at `/api/ws` and proxy them to `ws://localhost:9000/api/ws`. -backend = "ws://localhost:8000/api/ws" +backend = "ws://127.0.0.1:8000/api/ws" ws = true #[[proxy]] diff --git a/frontend/rust-toolchain.toml b/frontend/rust-toolchain.toml new file mode 100644 index 0000000..917bcd6 --- /dev/null +++ b/frontend/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = ["rust-src", "rustfmt", "rust-src"] +targets = ["wasm32-unknown-unknown"] diff --git a/frontend/src/page/lights.rs b/frontend/src/page/lights.rs index 9fe6a90..13d7990 100644 --- a/frontend/src/page/lights.rs +++ b/frontend/src/page/lights.rs @@ -3,8 +3,8 @@ use crate::css::C; use chrono::{NaiveTime, Weekday}; use common::{BulbGroup, BulbGroupShape, BulbMap, ClientMessage, ServerMessage}; use lighter_lib::{BulbId, BulbMode}; -use seed::prelude::*; use seed::{attrs, button, div, input, C}; +use seed::{prelude::*, IF}; use seed_router::Page; use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::Write; @@ -228,14 +228,11 @@ impl Page for Model { .next() .and_then(|&index| self.bulb_map.groups.get(index)) .and_then(|group| group.bulbs.first()) - .and_then(|id| self.bulb_states.get(id)) - .cloned() // TODO: remove clone - .unwrap_or_default(); + .and_then(|id| self.bulb_states.get(id)); let calendar_day = |day: Weekday| { let time = selected_bulb - .wake_schedule - .get(&day) + .and_then(|b| b.wake_schedule.get(&day)) .map(|t| t.to_string()) .unwrap_or_default(); div![ @@ -261,18 +258,20 @@ impl Page for Model { ], div![ C![C.bulb_controls], + IF!(selected_bulb.is_none() => C![C.bulb_controls_disable]), self.color_picker .view() .map_msg(|msg| Msg::ColorPicker(msg)), button![ - if selected_bulb.mode.power { + if selected_bulb.map(|b| b.mode.power).unwrap_or(false) { C![C.bulb_power_button, C.bulb_power_button_on] } else { C![C.bulb_power_button] }, - ev(Ev::Click, move |_| Msg::SetBulbPower( - !selected_bulb.mode.power - )), + { + let target_power = selected_bulb.map(|b| !b.mode.power); + ev(Ev::Click, move |_| target_power.map(Msg::SetBulbPower)) + }, div![attrs! { At::Id => "switch_socket" }], div![attrs! { At::Id => "off_label" }, "Off"], div![attrs! { At::Id => "on_label" }, "On"], diff --git a/frontend/static/styles/common.scss b/frontend/static/styles/common.scss index 00c9ae6..aad5ab1 100644 --- a/frontend/static/styles/common.scss +++ b/frontend/static/styles/common.scss @@ -103,9 +103,47 @@ body { padding-right: 0.5em; background: #56636e; border: solid 0.25em #5b3f63; - } +.bulb_controls_disable { + position: relative; + overflow: hidden; +} + +.bulb_controls_disable:before { + position: absolute; + content: ''; + display: block; + background: #000000; + opacity: 0.5; + left: 0; + right: 0; + top: 0; + bottom: 0; + margin: auto; + z-index: 90; +} + +.bulb_controls_disable:after { + position: absolute; + content: ''; + background: #56636e; + display: block; + width: 0; + height: 10px; + border-radius: 8px; + -webkit-transform: rotate(-30deg); + transform: rotate(-30deg); + left: 0; + right: 0; + top: 0; + bottom: 0; + margin: auto; + z-index: 91; + animation: to_full_width .2s ease-out 0s 1 forwards; +} +@keyframes to_full_width { to { width: 100%; } } + .bulb_map { background: url(images/blueprint_bg.png); background-size: auto;