Fix the message when you don't find the word

main
kirbylife 2023-10-13 00:45:12 -06:00
parent eb8c6f8bcf
commit 0db00efc4f
2 changed files with 20 additions and 8 deletions

View File

@ -1,30 +1,40 @@
use crate::consts::MAX_ATTEMPTS;
use crate::consts::{GameResult, MAX_ATTEMPTS};
use yew::prelude::*;
use crate::consts::{Attempts, Status};
#[derive(Properties, PartialEq)]
pub struct ResultBoardProps {
pub result: GameResult,
pub attempts: Attempts,
}
#[function_component]
pub fn ResultBoard(props: &ResultBoardProps) -> Html {
let ResultBoardProps {
result,
attempts,
} = props;
let game_result_text = match result {
GameResult::Win => {
format!("Palabra encontrada en {}/{} intentos", attempts.fields.len(), MAX_ATTEMPTS)
}
GameResult::Fail => {
format!("Palabra no encontrada :c")
}
};
html! {
<div class="result-board">
<p>
{ format!("Palabra encontrada en {}/{} intentos", attempts.fields.len(), MAX_ATTEMPTS) }
</p><br/>
<p> {
<p>{ game_result_text }</p>
<br/>
<p>{
for attempts.fields.iter().map(|attempt| {
html_nested! {
<> {
for attempt.iter().map(| att| {
match att.status {
Status::Found => html_nested! { <> { "🟩" } </> },
Status::Found => html_nested! { <>{ "🟩" }</> },
Status::Almost => html_nested! { <>{ "🟨" }</> },
Status::NotFound => html_nested! { <>{ "" }</> }
@ -33,7 +43,9 @@ pub fn ResultBoard(props: &ResultBoardProps) -> Html {
} <br/></>
}
})
} </p>
}</p>
<br/>
<p>{ "Vuelve mañana para otro reto" }</p>
</div>
}
}

View File

@ -53,7 +53,7 @@ fn App() -> Html {
<div>
<span> {
match *board.result {
Some(_) => html! { <ResultBoard attempts={(*board.attempts).clone()} /> },
Some(result) => html! { <ResultBoard { result } attempts={(*board.attempts).clone()} /> },
None => html! { <Keyboard
keyboard={ (board.virtual_keyboard).clone() }
onclick={ onclick } /> }