Disable bulb controls when no bulbs selected
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -475,8 +475,6 @@ dependencies = [
|
|||||||
"http",
|
"http",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
|
|||||||
@ -32,7 +32,7 @@ struct Opt {
|
|||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
quiet: bool,
|
quiet: bool,
|
||||||
|
|
||||||
#[clap(long, short, default_value = "127.0.0.0:8000")]
|
#[clap(long, short, default_value = "127.0.0.1:8000")]
|
||||||
bind: SocketAddr,
|
bind: SocketAddr,
|
||||||
|
|
||||||
#[clap(long, default_value = "./www")]
|
#[clap(long, default_value = "./www")]
|
||||||
|
|||||||
@ -10,7 +10,7 @@ wasm-bindgen = "=0.2.87" # must match Trunk.toml
|
|||||||
serde = { version = "1.0.0", features = ['derive'] }
|
serde = { version = "1.0.0", features = ['derive'] }
|
||||||
ron = "0.7.1"
|
ron = "0.7.1"
|
||||||
chrono = { version = "0.4.20", features = ["serde"] }
|
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"
|
gloo-console = "0.3.0"
|
||||||
|
|
||||||
[dependencies.css_typegen]
|
[dependencies.css_typegen]
|
||||||
|
|||||||
@ -7,7 +7,7 @@ wasm_bindgen = "0.2.87"
|
|||||||
[[proxy]]
|
[[proxy]]
|
||||||
# This WebSocket proxy example has a backend and ws field. This example will listen for
|
# 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`.
|
# 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
|
ws = true
|
||||||
|
|
||||||
#[[proxy]]
|
#[[proxy]]
|
||||||
|
|||||||
4
frontend/rust-toolchain.toml
Normal file
4
frontend/rust-toolchain.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "stable"
|
||||||
|
components = ["rust-src", "rustfmt", "rust-src"]
|
||||||
|
targets = ["wasm32-unknown-unknown"]
|
||||||
@ -3,8 +3,8 @@ use crate::css::C;
|
|||||||
use chrono::{NaiveTime, Weekday};
|
use chrono::{NaiveTime, Weekday};
|
||||||
use common::{BulbGroup, BulbGroupShape, BulbMap, ClientMessage, ServerMessage};
|
use common::{BulbGroup, BulbGroupShape, BulbMap, ClientMessage, ServerMessage};
|
||||||
use lighter_lib::{BulbId, BulbMode};
|
use lighter_lib::{BulbId, BulbMode};
|
||||||
use seed::prelude::*;
|
|
||||||
use seed::{attrs, button, div, input, C};
|
use seed::{attrs, button, div, input, C};
|
||||||
|
use seed::{prelude::*, IF};
|
||||||
use seed_router::Page;
|
use seed_router::Page;
|
||||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
@ -228,14 +228,11 @@ impl Page for Model {
|
|||||||
.next()
|
.next()
|
||||||
.and_then(|&index| self.bulb_map.groups.get(index))
|
.and_then(|&index| self.bulb_map.groups.get(index))
|
||||||
.and_then(|group| group.bulbs.first())
|
.and_then(|group| group.bulbs.first())
|
||||||
.and_then(|id| self.bulb_states.get(id))
|
.and_then(|id| self.bulb_states.get(id));
|
||||||
.cloned() // TODO: remove clone
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let calendar_day = |day: Weekday| {
|
let calendar_day = |day: Weekday| {
|
||||||
let time = selected_bulb
|
let time = selected_bulb
|
||||||
.wake_schedule
|
.and_then(|b| b.wake_schedule.get(&day))
|
||||||
.get(&day)
|
|
||||||
.map(|t| t.to_string())
|
.map(|t| t.to_string())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
div![
|
div![
|
||||||
@ -261,18 +258,20 @@ impl Page for Model {
|
|||||||
],
|
],
|
||||||
div![
|
div![
|
||||||
C![C.bulb_controls],
|
C![C.bulb_controls],
|
||||||
|
IF!(selected_bulb.is_none() => C![C.bulb_controls_disable]),
|
||||||
self.color_picker
|
self.color_picker
|
||||||
.view()
|
.view()
|
||||||
.map_msg(|msg| Msg::ColorPicker(msg)),
|
.map_msg(|msg| Msg::ColorPicker(msg)),
|
||||||
button![
|
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]
|
C![C.bulb_power_button, C.bulb_power_button_on]
|
||||||
} else {
|
} else {
|
||||||
C![C.bulb_power_button]
|
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 => "switch_socket" }],
|
||||||
div![attrs! { At::Id => "off_label" }, "Off"],
|
div![attrs! { At::Id => "off_label" }, "Off"],
|
||||||
div![attrs! { At::Id => "on_label" }, "On"],
|
div![attrs! { At::Id => "on_label" }, "On"],
|
||||||
|
|||||||
@ -103,9 +103,47 @@ body {
|
|||||||
padding-right: 0.5em;
|
padding-right: 0.5em;
|
||||||
background: #56636e;
|
background: #56636e;
|
||||||
border: solid 0.25em #5b3f63;
|
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 {
|
.bulb_map {
|
||||||
background: url(images/blueprint_bg.png);
|
background: url(images/blueprint_bg.png);
|
||||||
background-size: auto;
|
background-size: auto;
|
||||||
|
|||||||
Reference in New Issue
Block a user