From 90cba9b5bbad1f842bd93a1cd0d872b34ec1e588 Mon Sep 17 00:00:00 2001 From: kirbylife Date: Tue, 3 Oct 2023 13:32:01 -0600 Subject: [PATCH] Make clippy happy --- src/components/board.rs | 11 +++++------ src/components/result_board.rs | 2 +- src/consts.rs | 3 --- src/hooks/use_board.rs | 14 ++------------ src/main.rs | 14 +++++++------- src/services/words.rs | 7 ++----- 6 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/components/board.rs b/src/components/board.rs index 07f16e9..256887a 100644 --- a/src/components/board.rs +++ b/src/components/board.rs @@ -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 {
{ for (0..MAX_ATTEMPTS).map(|i| { - if i < *attempt_index { - html! { } - } else if i == *attempt_index { - html! { } - } else { - html! { } + match i.cmp(attempt_index) { + Ordering::Less => html! { }, + Ordering::Equal => html! { }, + Ordering::Greater => html! { } } }) } diff --git a/src/components/result_board.rs b/src/components/result_board.rs index d9e971e..d5de789 100644 --- a/src/components/result_board.rs +++ b/src/components/result_board.rs @@ -1,4 +1,4 @@ -use crate::consts::{GameResult, MAX_ATTEMPTS}; +use crate::consts::MAX_ATTEMPTS; use yew::prelude::*; use crate::consts::{Attempts, Status}; diff --git a/src/consts.rs b/src/consts.rs index b789a94..0278a6c 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -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 { diff --git a/src/hooks/use_board.rs b/src/hooks/use_board.rs index 322535c..bfff28b 100644 --- a/src/hooks/use_board.rs +++ b/src/hooks/use_board.rs @@ -99,23 +99,13 @@ impl UseBoardHandle { #[hook] pub fn use_board() -> UseBoardHandle { - let current_attempt = use_state(|| "".to_string()); - let attempts: UseStateHandle = use_state(|| Attempts::new()); + let current_attempt = use_state(String::new); + let attempts: UseStateHandle = 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::); - 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, diff --git a/src/main.rs b/src/main.rs index 0ed597c..ddd237f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { />
{ - match (*board.result).clone() { - Some(res) => html! { }, - _ => html! { html! { }, + None => html! { } } diff --git a/src/services/words.rs b/src/services/words.rs index aa28219..e11c986 100644 --- a/src/services/words.rs +++ b/src/services/words.rs @@ -3,15 +3,12 @@ use lazy_static::lazy_static; lazy_static! { pub static ref WORDS: Vec = 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;