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

View File

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

View File

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

View File

@ -99,23 +99,13 @@ impl UseBoardHandle {
#[hook] #[hook]
pub fn use_board() -> UseBoardHandle { pub fn use_board() -> UseBoardHandle {
let current_attempt = use_state(|| "".to_string()); let current_attempt = use_state(String::new);
let attempts: UseStateHandle<Attempts> = use_state(|| Attempts::new()); let attempts: UseStateHandle<Attempts> = use_state(Attempts::new);
let attempt_index = use_mut_ref(|| 0usize); let attempt_index = use_mut_ref(|| 0usize);
let answer = use_memo(|_| get_word_of_the_day(), None::<()>); let answer = use_memo(|_| get_word_of_the_day(), None::<()>);
let virtual_keyboard = use_state(|| new_empty_virtual_keyboard().into()); let virtual_keyboard = use_state(|| new_empty_virtual_keyboard().into());
let result = use_state(|| None::<GameResult>); 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 { UseBoardHandle {
current_attempt, current_attempt,
attempts, attempts,

View File

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

View File

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