Fix the system selection drop menu
Some checks failed
Monorepo build / test-all (push) Successful in 21s
Monorepo build / build-flake (push) Failing after 6s

This commit was merged in pull request #430.
This commit is contained in:
2026-08-12 09:32:42 -04:00
parent 57596670c9
commit 4eb5df93be
6 changed files with 41 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ web-sys = { workspace = true, features = ["Clipboard",
"DragEvent",
"HtmlDialogElement",
"HtmlDivElement",
"HtmlSelectElement",
"Location",
"Navigator",
"PublicKeyCredential",

View File

@@ -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>

View File

@@ -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>
}

View File

@@ -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);
}));

View File

@@ -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 {

View File

@@ -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)]