Make clippy happy

main
kirbylife 2023-10-03 13:32:01 -06:00
parent 637166ff58
commit 90cba9b5bb
6 changed files with 17 additions and 34 deletions

View File

@ -1,6 +1,7 @@
use yew::prelude::*;
use crate::components::{EmptyRow, CurrentRow, AttemptRow};
use crate::consts::{Attempts, MAX_ATTEMPTS};
use std::cmp::Ordering;
#[derive(Properties, PartialEq)]
pub struct BoardProps {
@ -23,12 +24,10 @@ pub fn Board(props: &BoardProps) -> Html {
<div class="board" onkeyup={onkeypress} tabindex="0">
{
for (0..MAX_ATTEMPTS).map(|i| {
if i < *attempt_index {
html! { <AttemptRow attempt={ attempts.fields[i].clone() } /> }
} else if i == *attempt_index {
html! { <CurrentRow text={ current_attempt } /> }
} else {
html! { <EmptyRow /> }
match i.cmp(attempt_index) {
Ordering::Less => html! { <AttemptRow attempt={ attempts.fields[i].clone() } /> },
Ordering::Equal => html! { <CurrentRow text={ current_attempt } /> },
Ordering::Greater => html! { <EmptyRow /> }
}
})
}

View File

@ -1,4 +1,4 @@
use crate::consts::{GameResult, MAX_ATTEMPTS};
use crate::consts::MAX_ATTEMPTS;
use yew::prelude::*;
use crate::consts::{Attempts, Status};

View File

@ -1,7 +1,4 @@
use yew::html::IntoPropValue;
pub const MAX_ATTEMPTS: usize = 6;
pub const WORD_LEN: usize = 5;
#[derive(Clone, PartialEq)]
pub enum KeyboardKeyType {

View File

@ -99,23 +99,13 @@ impl UseBoardHandle {
#[hook]
pub fn use_board() -> UseBoardHandle {
let current_attempt = use_state(|| "".to_string());
let attempts: UseStateHandle<Attempts> = use_state(|| Attempts::new());
let current_attempt = use_state(String::new);
let attempts: UseStateHandle<Attempts> = use_state(Attempts::new);
let attempt_index = use_mut_ref(|| 0usize);
let answer = use_memo(|_| get_word_of_the_day(), None::<()>);
let virtual_keyboard = use_state(|| new_empty_virtual_keyboard().into());
let result = use_state(|| None::<GameResult>);
let send_key = {
let current_attempt = current_attempt.clone();
let current_attempt_len = current_attempt.chars().count();
let attempts = attempts.clone();
let answer = (*answer).clone();
let attempt_index = attempt_index.clone();
let result = result.clone();
move |k: Key| {}
};
UseBoardHandle {
current_attempt,
attempts,

View File

@ -1,13 +1,12 @@
use yew::prelude::*;
use crate::components::{AttemptRow, Board};
use crate::components::CurrentRow;
use crate::components::EmptyRow;
use crate::components::Board;
use crate::components::Keyboard;
use crate::components::ResultBoard;
use crate::consts::{Key, MAX_ATTEMPTS};
use crate::consts::{Key};
use crate::hooks::use_board;
#[cfg(debug_assertions)]
use gloo::console;
mod components;
@ -26,6 +25,7 @@ fn App() -> Html {
Callback::from(move |event: KeyboardEvent| {
let key_code = event.key_code();
board.send_key(Key::from(key_code));
#[cfg(debug_assertions)]
console::log!(&event);
})
};
@ -52,9 +52,9 @@ fn App() -> Html {
/>
<div>
<span> {
match (*board.result).clone() {
Some(res) => html! { <ResultBoard attempts={(*board.attempts).clone()} /> },
_ => html! { <Keyboard
match *board.result {
Some(_) => html! { <ResultBoard attempts={(*board.attempts).clone()} /> },
None => html! { <Keyboard
keyboard={ (board.virtual_keyboard).clone() }
onclick={ onclick } /> }
}

View File

@ -3,15 +3,12 @@ use lazy_static::lazy_static;
lazy_static! {
pub static ref WORDS: Vec<String> = include_str!("../../words.txt")
.trim()
.lines()
.map(|w| w.to_string())
.map(|w| w.trim().into())
.collect();
}
pub fn get_all_words() -> &'static WORDS {
&WORDS
}
pub fn get_word_of_the_day() -> String {
let date = chrono::Utc::now();
let year = date.year() as usize;