use reactive_stores::Field; use crate::prelude::*; use leptos::prelude::*; /// The three attunement slots: each is either empty (free-text input and /// "+" button) or holds an item name with a "×" clear button. #[component] pub fn Attunements () -> impl IntoView { let state = expect_context::(); let attunements: Field = state.player().attunements().into(); view! {
"Атюнменты:"
{slot_row(attunements, idx, slot)}
} } /// One attunement slot: the free-text entry (empty) or the item itself. /// A plain function: component tags are not allowed directly inside /// `For`'s `let(...)` children. fn slot_row ( attunements: Field, idx: usize, slot: Option, ) -> impl IntoView { let text_sig = RwSignal::new(String::new()); // Binds the typed item name; empty text is ignored. let bind = move |_| { let text = text_sig.get_untracked(); if text.trim().is_empty() { return; } attunements.update(|a| a.0[idx] = Some(text.trim().to_string())); }; let clear = move |_| attunements.update(|a| a.0[idx] = None); view! {
{if slot.is_some() { view! {
{slot.clone().unwrap_or_default()}
}.into_any() } else { view! { }.into_any() }}
} }