diff --git a/app/index.tsx b/app/index.tsx index 163129f..adcb9d9 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -1,13 +1,25 @@ import React, { useState, useEffect } from "react"; -import { ScrollView, Text, Alert, Button } from "react-native"; +import { + ScrollView, + Text, + Alert, + Button, + View, + StyleSheet, +} from "react-native"; import PlayerSelector from "@/components/PlayerSelector"; import BuyInSelector from "@/components/BuyInSelector"; import ChipsSelector from "@/components/ChipsSelector"; import ChipDistributionSummary from "@/components/ChipDistributionSummary"; import ChipDetection from "@/components/ChipDetection"; +import CurrencySelector from "@/components/CurrencySelector"; import { saveState, loadState } from "@/components/CalculatorState"; -import { savePersistentState, loadPersistentState } from "@/components/PersistentState"; +import { + savePersistentState, + loadPersistentState, +} from "@/components/PersistentState"; +// Your existing states export enum COLORS { "white", "red", @@ -21,6 +33,8 @@ const IndexScreen: React.FC = () => { const [buyInAmount, setBuyInAmount] = useState(20); const [numberOfChips, setNumberOfChips] = useState(5); const [totalChipsCount, setTotalChipsCount] = useState([]); + const [selectedCurrency, setSelectedCurrency] = useState("$"); + const [isSettingsVisible, setIsSettingsVisible] = useState(false); // Load persistent data on startup useEffect(() => { @@ -30,12 +44,13 @@ const IndexScreen: React.FC = () => { const savedState = await loadPersistentState(); if (savedState) { console.log("Persistent state restored:", savedState); - setPlayerCount(savedState.playerCount); - setBuyInAmount(savedState.buyInAmount); - setNumberOfChips(savedState.numberOfChips); - setTotalChipsCount(savedState.totalChipsCount); + setPlayerCount(savedState.playerCount || 2); // Use defaults if missing + setBuyInAmount(savedState.buyInAmount || 20); // Use defaults if missing + setNumberOfChips(savedState.numberOfChips || 5); // Use defaults if missing + setTotalChipsCount(savedState.totalChipsCount || []); // Use defaults if missing + setSelectedCurrency(savedState.selectedCurrency || "$"); // Restore the selected currency, defaulting to "$" if not available } else { - console.log("No persistent state found."); + console.log("No persistent state found, using defaults."); } } catch (error) { console.error("Error loading persistent state:", error); @@ -44,14 +59,18 @@ const IndexScreen: React.FC = () => { loadPersistentData(); }, []); - // Save game state to selected slot const handleSave = async (slot: "SLOT1" | "SLOT2") => { if (buyInAmount === null) { Alert.alert("Error", "Please select a valid buy-in amount"); return; } - const state = { playerCount, buyInAmount, numberOfChips, totalChipsCount }; - + const state = { + playerCount, + buyInAmount, + numberOfChips, + totalChipsCount, + selectedCurrency, + }; try { await saveState(slot, state); await savePersistentState(state); @@ -63,7 +82,6 @@ const IndexScreen: React.FC = () => { } }; - // Load game state from selected slot const handleLoad = async (slot: "SLOT1" | "SLOT2") => { try { const loadedState = await loadState(slot); @@ -72,6 +90,7 @@ const IndexScreen: React.FC = () => { setBuyInAmount(loadedState.buyInAmount); setNumberOfChips(loadedState.numberOfChips); setTotalChipsCount(loadedState.totalChipsCount); + setSelectedCurrency(loadedState.selectedCurrency || "$"); await savePersistentState(loadedState); console.log(`Game state loaded from ${slot}:`, loadedState); Alert.alert("Success", `State loaded from ${slot}`); @@ -86,29 +105,92 @@ const IndexScreen: React.FC = () => { return ( - - - { - const chipCountArray = Object.values(chipData); - setTotalChipsCount(chipCountArray); - }} /> + + Poker Chips Helper +