Skip to content

Commit

Permalink
Refactor README and improve card amount validation in main.rs; change…
Browse files Browse the repository at this point in the history
… logging level to debug in price_check and tracker
  • Loading branch information
Qrimpuff committed Dec 21, 2024
1 parent 2f8e94a commit 2d24d09
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Formats supported:
Run the following command in the root of the project to start the Dioxus dev server:

```bash
dx serve --release
dx serve
```

- Open the browser to http://localhost:8080/hocg-deck-convert
25 changes: 21 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn App() -> Element {
"Consider using Deck Log to build your deck, or you can also choose one of the official starter decks to get you started."
}
p {
"If you have any questions about the game, consider joining the "
"If you have any questions about the game, the "
a {
href: "https://discord.com/invite/GJ9RhA22nP",
target: "_blank",
Expand All @@ -84,7 +84,7 @@ fn App() -> Element {
}
"Hololive OCG Fan Server"
}
"."
" is welcoming to beginners."
}
}
div { class: "columns is-tablet",
Expand Down Expand Up @@ -605,6 +605,23 @@ fn Cards(cards: CommonCards, card_type: CardType, card_lang: Signal<CardLanguage
.card_info(&CARDS_INFO.read())
.and_then(|c| c.yuyutei_sell_url.clone());

// verify card amount
let warning = COMMON_DECK
.read()
.as_ref()
.map(|d| {
d.all_cards()
.filter(|c| c.card_number == cards.card_number)
.map(|c| c.amount)
.sum::<u32>()
})
.unwrap_or(0)
> cards
.card_info(&CARDS_INFO.read())
.map(|i| i.max)
.unwrap_or(50);
let warning_class = if warning { "is-warning" } else { "is-dark" };

rsx! {
div {
figure { class: "image m-2 {img_class}",
Expand All @@ -615,7 +632,7 @@ fn Cards(cards: CommonCards, card_type: CardType, card_lang: Signal<CardLanguage
"onerror": "this.src='{error_img_path}'",
}
if show_price {
span { class: "badge is-bottom is-dark",
span { class: "badge is-bottom {warning_class}",
" ¥{price} × {cards.amount} "
if let Some(price_url) = price_url {
a {
Expand All @@ -628,7 +645,7 @@ fn Cards(cards: CommonCards, card_type: CardType, card_lang: Signal<CardLanguage
}
}
} else if card_type != CardType::Oshi {
span { class: "badge is-bottom is-dark", "{cards.amount}" }
span { class: "badge is-bottom {warning_class}", "{cards.amount}" }
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ impl CommonDeck {
.into_iter()
.map(|(k, v)| CommonCards::from_card_number(k.clone(), v, info))
{
if card.amount > card.card_info(info).map(|i| i.max).unwrap_or(50) {
let max = card.card_info(info).map(|i| i.max).unwrap_or(50);
if card.amount > max {
errors.push(format!(
"Too many {} in main deck. ({} cards)",
"Too many {} in main deck. ({} cards; {max} max)",
card.card_number, card.amount
));
}
Expand Down
4 changes: 2 additions & 2 deletions src/sources/price_check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, error::Error, sync::OnceLock};

use dioxus::{
logger::tracing::{debug, info},
logger::tracing::debug,
prelude::*,
};
use itertools::Itertools;
Expand Down Expand Up @@ -44,7 +44,7 @@ async fn price_check(
prices: &PriceCache,
service: PriceCheckService,
) -> Result<PriceCache, Box<dyn Error>> {
info!("price check");
debug!("price check");

// read price from cache
let urls: Vec<_> = deck
Expand Down
3 changes: 2 additions & 1 deletion src/tracker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::OnceLock;

use dioxus::logger::tracing::debug;
use gloo::utils::{document, window};
use reqwest::{Client, ClientBuilder};
use serde::Serialize;
Expand Down Expand Up @@ -53,7 +54,7 @@ where
}
}

// info!("{payload:?}");
debug!("{payload:?}");

// skip tracking
let untrack = window()
Expand Down

0 comments on commit 2d24d09

Please sign in to comment.