Skip to content

Instantly share code, notes, and snippets.

@Discordanian
Created January 19, 2024 18:42
Show Gist options
  • Select an option

  • Save Discordanian/dc01564dd2576c53dfe71027afe57fe8 to your computer and use it in GitHub Desktop.

Select an option

Save Discordanian/dc01564dd2576c53dfe71027afe57fe8 to your computer and use it in GitHub Desktop.
Leptos question. Probably basic and I'm probably being a dunce. Any help is appreciated.
/*
This is in my main.rs section. The suspects::SuspectID::Suspect00 is an enum.
*/
fn app() {
let (rx_suspect, tx_suspect) = create_signal(suspects::SuspectID::Suspect00);
mount_to_body(move || {
view! {
<questions::Questions rx_suspect />
<suspects::Suspects tx_suspect/>
}
})
}
/*
This is my suspects.rs file
Suspects receives tx_suspect and passes it to SuspectAlibiGrid where I loop over a construct
and try to create an array of buttons that I'm trying to set the SuspectID enumeration type
*/
#[component]
pub fn Suspects(tx_suspect: WriteSignal<SuspectID>) -> impl IntoView {
view! {
<SuspectAlibiGrid male=true tx_suspect/>
}
}
fn SuspectAlibiGrid(male: bool, tx_suspect: WriteSignal<SuspectID>) -> impl IntoView {
view! {
{
SUSPECT_DATA.iter()
.filter(|&s| male == s.is_male && s.id > 0)
.map(|sd| view!{
<button on:click=move |_| tx_suspect.update(|value| *value=sd.suspect_id)>{sd.idstr}</button>
})
.collect_view()
}
}
}
/*
Questions Should read the value and use it to change the display
*/
#[component]
pub fn Questions(rx_suspect: ReadSignal<SuspectID>) -> impl IntoView {
view! {
<Mugshot rx_suspect/>
}
}
fn Mugshot(rx_suspect: ReadSignal<SuspectID>) -> impl IntoView {
let suspectid = rx_suspect.get();
let suspect = SUSPECT_DATA[suspectid as usize];
let mugurl = suspect.img_url;
view! {
<div class="card">
<img src={mugurl} alt={mugname}/>
</div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment