feat: stats

This commit is contained in:
tresabhi committed 2025-05-04 21:45:38 -05:00
1 parent c8cb490b48
commit 57971453ad
3 files changed
+20 -7

No files matched your search

+2 -1
View File
@@ -863,7 +863,8 @@
"guess": "Guess", "guess": "Guess",
"next": "Next", "next": "Next",
"no_results": "No results" "no_results": "No results"
} },
"stats": "%s1 / %s2 guessed correctly"
}, },
"tankopedia": { "tankopedia": {
@@ -3,6 +3,7 @@ import {
TankDefinition, TankDefinition,
TIER_ROMAN_NUMERALS, TIER_ROMAN_NUMERALS,
} from '@blitzkit/core'; } from '@blitzkit/core';
import { literals } from '@blitzkit/i18n';
import { import {
ArrowRightIcon, ArrowRightIcon,
MagnifyingGlassIcon, MagnifyingGlassIcon,
@@ -40,6 +41,8 @@ const ids = Object.keys(tankDefinitions.tanks);
export function Guesser() { export function Guesser() {
const tank = GuessEphemeral.use((state) => state.tank); const tank = GuessEphemeral.use((state) => state.tank);
const guessState = GuessEphemeral.use((state) => state.guessState); const guessState = GuessEphemeral.use((state) => state.guessState);
const correctGuesses = GuessEphemeral.use((state) => state.correctGuesses);
const totalGuesses = GuessEphemeral.use((state) => state.totalGuesses);
const { strings, unwrap } = useLocale(); const { strings, unwrap } = useLocale();
const input = useRef<HTMLInputElement>(null); const input = useRef<HTMLInputElement>(null);
const [searching, setSearching] = useState(false); const [searching, setSearching] = useState(false);
@@ -132,6 +135,15 @@ export function Guesser() {
</Card> </Card>
)} )}
<Flex justify="center">
<Text>
{literals(strings.website.tools.guess.stats, [
`${correctGuesses}`,
`${totalGuesses}`,
])}
</Text>
</Flex>
<Flex gap="3"> <Flex gap="3">
<TextField.Root <TextField.Root
disabled={guessState !== null} disabled={guessState !== null}
@@ -158,8 +170,8 @@ export function Guesser() {
revealEvent.dispatch(true); revealEvent.dispatch(true);
mutateGuessEphemeral((draft) => { mutateGuessEphemeral((draft) => {
draft.guessState = correct; draft.guessState = correct;
draft.totalSeen++; draft.totalGuesses++;
draft.correct += correct ? 1 : 0; draft.correctGuesses += correct ? 1 : 0;
}); });
} else { } else {
const id = Number(ids[Math.floor(Math.random() * ids.length)]); const id = Number(ids[Math.floor(Math.random() * ids.length)]);
@@ -6,15 +6,15 @@ export interface GuessEphemeral {
tank: TankDefinition; tank: TankDefinition;
// true = correct, false = incorrect, null = not guessed // true = correct, false = incorrect, null = not guessed
guessState: boolean | null; guessState: boolean | null;
totalSeen: number; totalGuesses: number;
correct: number; correctGuesses: number;
} }
export const GuessEphemeral = createContextualStore((tank: TankDefinition) => export const GuessEphemeral = createContextualStore((tank: TankDefinition) =>
create<GuessEphemeral>()(() => ({ create<GuessEphemeral>()(() => ({
tank, tank,
guessState: null, guessState: null,
totalSeen: 0, totalGuesses: 0,
correct: 0, correctGuesses: 0,
})), })),
); );