added joke info fields

This commit is contained in:
Bart Massey 2024-05-29 15:51:45 -07:00
parent 6189f29e00
commit 365bab73c6

View File

@ -24,15 +24,30 @@ pub struct JokeProps {
pub joke: JokeStruct,
}
pub fn format_tags(tags: &HashSet<String>) -> String {
let taglist: Vec<&str> = tags.iter().map(String::as_ref).collect();
taglist.join(", ")
}
#[function_component(Joke)]
pub fn joke(joke: &JokeProps) -> Html {
html! {
html! { <>
<div class="joke">
<span class="teller">{"Knock-Knock!"}</span><br/>
<span class="tellee">{"Who's there?"}</span><br/>
<span class="teller">{joke.joke.whos_there.clone()}</span><br/>
<span class="tellee">{format!("{} who?", &joke.joke.whos_there)}</span><br/>
<span class="teller">{joke.joke.answer_who.clone()}</span><br/>
<span class="teller">{joke.joke.answer_who.clone()}</span>
</div>
<span class="annotation">
{format!("[id: {}", &joke.joke.id)}
if let Some(ref tags) = joke.joke.tags {
{format!("; tags: {}", &format_tags(tags))}
}
if let Some(ref source) = joke.joke.source {
{format!("; source: {}", source)}
}
{"]"}
</span>
</> }
}