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,23 +1,33 @@
use crate::consts::MAX_ATTEMPTS; use crate::consts::{GameResult, MAX_ATTEMPTS};
use yew::prelude::*; use yew::prelude::*;
use crate::consts::{Attempts, Status}; use crate::consts::{Attempts, Status};
#[derive(Properties, PartialEq)] #[derive(Properties, PartialEq)]
pub struct ResultBoardProps { pub struct ResultBoardProps {
pub result: GameResult,
pub attempts: Attempts, pub attempts: Attempts,
} }
#[function_component] #[function_component]
pub fn ResultBoard(props: &ResultBoardProps) -> Html { pub fn ResultBoard(props: &ResultBoardProps) -> Html {
let ResultBoardProps { let ResultBoardProps {
result,
attempts, attempts,
} = props; } = 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! { html! {
<div class="result-board"> <div class="result-board">
<p> <p>{ game_result_text }</p>
{ format!("Palabra encontrada en {}/{} intentos", attempts.fields.len(), MAX_ATTEMPTS) } <br/>
</p><br/>
<p>{ <p>{
for attempts.fields.iter().map(|attempt| { for attempts.fields.iter().map(|attempt| {
html_nested! { html_nested! {
@ -34,6 +44,8 @@ pub fn ResultBoard(props: &ResultBoardProps) -> Html {
} }
}) })
}</p> }</p>
<br/>
<p>{ "Vuelve mañana para otro reto" }</p>
</div> </div>
} }
} }

View File

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