diff --git a/app/index.tsx b/app/index.tsx index c187422..2da8b34 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -1,17 +1,39 @@ -import React, { useState } from "react"; -import { ScrollView, Text, Alert, Button, View, StyleSheet } from "react-native"; +import React, { useState, useEffect } from "react"; +import { ScrollView, Alert, Button } from "react-native"; import PlayerSelector from "@/components/PlayerSelector"; import BuyInSelector from "@/components/BuyInSelector"; import ChipsSelector from "@/components/ChipsSelector"; import ChipDistributionSummary from "@/components/ChipDistributionSummary"; -import { saveState, loadState } from "../components/CalculatorState"; +import ChipDetection from "@/components/ChipDetection"; +import { saveState, loadState } from "@/components/CalculatorState"; -const IndexScreen = () => { +export enum COLORS { + "white", + "red", + "green", + "blue", + "black", +} + +const IndexScreen: React.FC = () => { const [playerCount, setPlayerCount] = useState(2); - const [buyInAmount, setBuyInAmount] = useState(null); + const [buyInAmount, setBuyInAmount] = useState(20); const [numberOfChips, setNumberOfChips] = useState(5); const [totalChipsCount, setTotalChipsCount] = useState([]); + useEffect(() => { + const loadSavedState = async () => { + const savedState = await loadState("SLOT1"); // Default loading from SLOT1 + if (savedState) { + setPlayerCount(savedState.playerCount); + setBuyInAmount(savedState.buyInAmount); + setNumberOfChips(savedState.numberOfChips); + setTotalChipsCount(savedState.totalChipsCount); + } + }; + loadSavedState(); + }, []); + const handleSave = async (slot: "SLOT1" | "SLOT2") => { if (buyInAmount === null) { Alert.alert("Error", "Please select a valid buy-in amount"); @@ -35,9 +57,13 @@ const IndexScreen = () => { } }; + const updateChipCount = (chipData: { [color: string]: number }) => { + const chipCountArray = Object.values(chipData); + setTotalChipsCount(chipCountArray); + }; + return ( - - + @@ -54,21 +80,10 @@ const IndexScreen = () => { />