Fix the system selection drop menu
This commit was merged in pull request #430.
This commit is contained in:
@@ -37,6 +37,7 @@ web-sys = { workspace = true, features = ["Clipboard",
|
||||
"DragEvent",
|
||||
"HtmlDialogElement",
|
||||
"HtmlDivElement",
|
||||
"HtmlSelectElement",
|
||||
"Location",
|
||||
"Navigator",
|
||||
"PublicKeyCredential",
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
<link data-trunk href="static/glimmer-style-bundle-0.1.2.css" rel="css" type="text/css"></link>
|
||||
<link data-trunk href="static/style-default.css" rel="css" type="text/css"></link>
|
||||
</head>
|
||||
<body data-theme="neon"></body>
|
||||
<body data-theme="summer"></body>
|
||||
</html>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
use gloo_console::log;
|
||||
use luminescent_dreams_common::clone;
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{EventTarget, HtmlInputElement, HtmlSelectElement};
|
||||
use yew::prelude::*;
|
||||
|
||||
pub trait DropMenuOption: PartialEq {
|
||||
fn as_html(&self, selected: bool) -> Html;
|
||||
fn from_str(s: &str) -> Self;
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
@@ -14,15 +19,28 @@ pub struct DropMenuProps<T: DropMenuOption> {
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
pub fn DropMenu<T: DropMenuOption>(
|
||||
pub fn DropMenu<T: DropMenuOption + std::fmt::Debug + 'static>(
|
||||
DropMenuProps {
|
||||
selected,
|
||||
options,
|
||||
change_selection: _,
|
||||
change_selection,
|
||||
}: &DropMenuProps<T>,
|
||||
) -> Html {
|
||||
let change_selection = Callback::from(clone!(change_selection, move |evt: Event| {
|
||||
// let event = evt.target().value
|
||||
let target: EventTarget = evt.target().unwrap();
|
||||
let option = target.dyn_into::<HtmlSelectElement>().unwrap();
|
||||
/*
|
||||
log!(format!("change_selection: {:?}", option.value()));
|
||||
log!(format!(
|
||||
"change_selection: {:?}",
|
||||
T::from_str(&option.value())
|
||||
));
|
||||
*/
|
||||
change_selection.emit(T::from_str(&option.value()));
|
||||
}));
|
||||
html! {
|
||||
<select>
|
||||
<select onchange={change_selection}>
|
||||
{ (*options).iter().map(|option| option.as_html(option == selected)).collect::<Html>() }
|
||||
</select>
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![deny(clippy::pedantic)]
|
||||
use glimmer_yew::prelude::*;
|
||||
use gloo_console::log;
|
||||
use stylist::css;
|
||||
use visions_types::{CharacterId, GameOverview, UserOverview};
|
||||
use yew::prelude::*;
|
||||
@@ -36,6 +37,7 @@ pub fn NewGame(
|
||||
}));
|
||||
|
||||
let on_system_change = Callback::from(clone!((system), move |new_system: SystemName| {
|
||||
log!(format!("on_system_change: {}", new_system));
|
||||
system.set(new_system);
|
||||
}));
|
||||
|
||||
|
||||
@@ -20,6 +20,14 @@ impl DropMenuOption for Role {
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
fn from_str(s: &str) -> Role {
|
||||
match s {
|
||||
"gm" => Role::Gm,
|
||||
"player" => Role::Player,
|
||||
_ => panic!("unsupported"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Role> for JsValue {
|
||||
|
||||
@@ -86,6 +86,14 @@ impl DropMenuOption for SystemName {
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
fn from_str(s: &str) -> SystemName {
|
||||
match s {
|
||||
"candela" => SystemName::Candela,
|
||||
"cypher" => SystemName::Cypher,
|
||||
_ => panic!("unsupported"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user