diff --git a/app/index.tsx b/app/index.tsx index 7f1d8c7..b974fbd 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -7,16 +7,17 @@ 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 { saveState, loadState } from "@/util/CalculatorState"; import { savePersistentState, loadPersistentState, -} from "@/components/PersistentState"; +} from "@/util/PersistentState"; import styles from "@/styles/styles"; import Section from "@/containers/Section"; import AppContext from "@/util/context"; import { Picker } from "@react-native-picker/picker"; import i18n from "@/i18n/i18n"; +import PokerAppUi from "@/containers/PokerAppUi"; const IndexScreen: React.FC = () => { const [playerCount, setPlayerCount] = useState(2); @@ -25,23 +26,21 @@ const IndexScreen: React.FC = () => { const [totalChipsCount, setTotalChipsCount] = useState([]); const [selectedCurrency, setSelectedCurrency] = useState("$"); const [selectedLanguage, setSelectedLanguage] = useState("en"); + const [lightGrayMode, setLightGrayMode] = useState(false); + const context = useContext(AppContext); const isSettingsVisible = useMemo(() => context.showSettings, [context]); useEffect(() => { const loadPersistentData = async () => { try { - console.log("Loading persistent game state..."); const savedState = await loadPersistentState(); if (savedState) { - console.log("Persistent state restored:", savedState); setPlayerCount(savedState.playerCount || 2); setBuyInAmount(savedState.buyInAmount || 20); setNumberOfChips(savedState.numberOfChips || 5); setTotalChipsCount(savedState.totalChipsCount || []); setSelectedCurrency(savedState.selectedCurrency || "$"); - } else { - console.log("No persistent state found, using defaults."); } } catch (error) { console.error("Error loading persistent state:", error); @@ -62,35 +61,23 @@ const IndexScreen: React.FC = () => { totalChipsCount, selectedCurrency, }; - try { - await saveState(slot, state); - await savePersistentState(state); - console.log(`Game state saved to ${slot}:`, state); - Alert.alert(i18n.t("success"), i18n.t("state_saved", { slot })); // Fixed interpolation - } catch (error) { - console.error("Error saving state:", error); - Alert.alert(i18n.t("error"), i18n.t("failed_to_save_state")); - } + await saveState(slot, state); + await savePersistentState(state); + Alert.alert(i18n.t("success"), i18n.t("state_saved", { slot })); }; const handleLoad = async (slot: "SLOT1" | "SLOT2") => { - try { - const loadedState = await loadState(slot); - if (loadedState) { - setPlayerCount(loadedState.playerCount); - setBuyInAmount(loadedState.buyInAmount ?? 20); - setNumberOfChips(loadedState.numberOfChips); - setTotalChipsCount(loadedState.totalChipsCount); - setSelectedCurrency(loadedState.selectedCurrency || "$"); - await savePersistentState(loadedState); - console.log(`Game state loaded from ${slot}:`, loadedState); - Alert.alert(i18n.t("success"), i18n.t("state_loaded_from", { slot })); // Fixed interpolation - } else { - Alert.alert(i18n.t("info"), i18n.t("no_saved_state_found")); - } - } catch (error) { - console.error("Error loading state:", error); - Alert.alert(i18n.t("error"), i18n.t("failed_to_load_state")); + const loadedState = await loadState(slot); + if (loadedState) { + setPlayerCount(loadedState.playerCount); + setBuyInAmount(loadedState.buyInAmount ?? 20); + setNumberOfChips(loadedState.numberOfChips); + setTotalChipsCount(loadedState.totalChipsCount); + setSelectedCurrency(loadedState.selectedCurrency || "$"); + await savePersistentState(loadedState); + Alert.alert(i18n.t("success"), i18n.t("state_loaded_from", { slot })); + } else { + Alert.alert(i18n.t("info"), i18n.t("no_saved_state_found")); } }; @@ -100,107 +87,122 @@ const IndexScreen: React.FC = () => { }; return ( - - {isSettingsVisible && ( + +
- - - - -
- )} - - {isSettingsVisible && ( -
- setLightGrayMode(!lightGrayMode)} />
- )} -
- -
+ {isSettingsVisible && ( +
+ + + + +
+ )} -
- -
+ {isSettingsVisible && ( +
+ +
+ )} -
- { - const chipCountArray = Object.values(chipData); - setTotalChipsCount(chipCountArray); - setNumberOfChips(chipCountArray.length); - }} - /> -
+
+ +
-
- -
+
+ +
-
- -
+
+ { + const chipCountArray = Object.values(chipData); + setTotalChipsCount(chipCountArray); + setNumberOfChips(chipCountArray.length); + }} + /> +
-
- <> +
+ +
+ +
+ +
+ +
- +
+
+
); }; diff --git a/containers/Button.tsx b/containers/Button.tsx index 624f7d9..ed85970 100644 --- a/containers/Button.tsx +++ b/containers/Button.tsx @@ -1,9 +1,69 @@ -import { ButtonProps, Button } from "react-native"; -import { COLORS } from "@/styles/styles"; +import React from "react"; +import { Text, TouchableOpacity, StyleSheet } from "react-native"; -// More styling can be done, or swap this out with more flexible component like a TouchableOpacity if needed -const AppButton = (props: ButtonProps) => ( -