From 1b67c213a420800cbf0fd57f80818c80eb83de03 Mon Sep 17 00:00:00 2001 From: lubiana Date: Sat, 12 Jul 2025 19:26:44 +0200 Subject: [PATCH] smarty --- src/App.tsx | 53 ++++++++++++++++++++++++++++++----------- src/components/Card.tsx | 6 ++++- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 156a953..b48801a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback, useMemo } from 'react'; +import React, { useState, useCallback, useMemo, useRef, useEffect } from 'react'; import Card from './components/Card'; import TierCard from './components/TierCard'; import HistoryList from './components/HistoryList'; @@ -55,6 +55,27 @@ function App() { const [upgrades, setUpgrades] = useState({ evenDouble: false, oddDouble: false, allTripple: false, gubbleDouble: false, addFourthNumber: false }); const [upgradeBought, setUpgradeBought] = useState(false); + // Ref for scroll container + const tierRowRef = useRef(null); + // Ref for the highest unlocked card + const highestUnlockedRef = useRef(null); + + // Find the index of the highest unlocked tier + const highestUnlockedIndex = useMemo(() => { + let maxIdx = -1; + TIERS.forEach((tier, idx) => { + if (unlockedTiers.includes(tier.name)) maxIdx = idx; + }); + return maxIdx; + }, [unlockedTiers]); + + // Scroll the highest unlocked card into view when unlockedTiers changes + useEffect(() => { + if (highestUnlockedRef.current && tierRowRef.current) { + highestUnlockedRef.current.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); + } + }, [highestUnlockedIndex]); + // --- Tier Unlock Logic --- const handleUnlockTier = useCallback((tier: Tier) => { setMoney(m => { @@ -121,20 +142,20 @@ function App() { // --- Memoized winnings for current card --- const currentWinnings = useMemo(() => card ? card.fields.reduce((sum, f) => sum + (f.won || 0), 0) : 0, [card]); + const formatter = Intl.NumberFormat( + 'en', + { 'notation': 'compact' } + ) // --- UI --- return (
-

Scratch Card Game

-
Money: ${money}
-
Gubble Points: {gubblePoints}
- +
+

Scratch Card Game

+
Money: ${formatter.format(money)}
+
Gubble Points: {formatter.format(gubblePoints)}
+ +
-
- {TIERS.map((tier) => ( -
+
+ {TIERS.map((tier, idx) => ( +
= ({ card, setCard, setMoney, setGubblePoints, upgrades }) => { + const formatter = Intl.NumberFormat( + 'en', + { 'notation': 'compact' } + ) return (
{card.tier?.name} Scratch Card
@@ -70,7 +74,7 @@ const Card: React.FC = ({ card, setCard, setMoney, setGubblePoints, u }} > {field.scratched ? ( - {field.value}{field.won ? +${field.won} : ''} + {field.value}{field.won ? +${formatter.format(field.won)} : ''} ) : ( ? )}