Changed styles

This commit is contained in:
MantashaNoyela 2025-03-11 06:40:52 -07:00
parent da695be36d
commit 533356117a
9 changed files with 254 additions and 140 deletions

View File

@ -7,16 +7,17 @@ import ChipsSelector from "@/components/ChipsSelector";
import ChipDistributionSummary from "@/components/ChipDistributionSummary"; import ChipDistributionSummary from "@/components/ChipDistributionSummary";
import ChipDetection from "@/components/ChipDetection"; import ChipDetection from "@/components/ChipDetection";
import CurrencySelector from "@/components/CurrencySelector"; import CurrencySelector from "@/components/CurrencySelector";
import { saveState, loadState } from "@/components/CalculatorState"; import { saveState, loadState } from "@/util/CalculatorState";
import { import {
savePersistentState, savePersistentState,
loadPersistentState, loadPersistentState,
} from "@/components/PersistentState"; } from "@/util/PersistentState";
import styles from "@/styles/styles"; import styles from "@/styles/styles";
import Section from "@/containers/Section"; import Section from "@/containers/Section";
import AppContext from "@/util/context"; import AppContext from "@/util/context";
import { Picker } from "@react-native-picker/picker"; import { Picker } from "@react-native-picker/picker";
import i18n from "@/i18n/i18n"; import i18n from "@/i18n/i18n";
import PokerAppUi from "@/containers/PokerAppUi";
const IndexScreen: React.FC = () => { const IndexScreen: React.FC = () => {
const [playerCount, setPlayerCount] = useState(2); const [playerCount, setPlayerCount] = useState(2);
@ -25,23 +26,21 @@ const IndexScreen: React.FC = () => {
const [totalChipsCount, setTotalChipsCount] = useState<number[]>([]); const [totalChipsCount, setTotalChipsCount] = useState<number[]>([]);
const [selectedCurrency, setSelectedCurrency] = useState<string>("$"); const [selectedCurrency, setSelectedCurrency] = useState<string>("$");
const [selectedLanguage, setSelectedLanguage] = useState<string>("en"); const [selectedLanguage, setSelectedLanguage] = useState<string>("en");
const [lightGrayMode, setLightGrayMode] = useState<boolean>(false);
const context = useContext(AppContext); const context = useContext(AppContext);
const isSettingsVisible = useMemo(() => context.showSettings, [context]); const isSettingsVisible = useMemo(() => context.showSettings, [context]);
useEffect(() => { useEffect(() => {
const loadPersistentData = async () => { const loadPersistentData = async () => {
try { try {
console.log("Loading persistent game state...");
const savedState = await loadPersistentState(); const savedState = await loadPersistentState();
if (savedState) { if (savedState) {
console.log("Persistent state restored:", savedState);
setPlayerCount(savedState.playerCount || 2); setPlayerCount(savedState.playerCount || 2);
setBuyInAmount(savedState.buyInAmount || 20); setBuyInAmount(savedState.buyInAmount || 20);
setNumberOfChips(savedState.numberOfChips || 5); setNumberOfChips(savedState.numberOfChips || 5);
setTotalChipsCount(savedState.totalChipsCount || []); setTotalChipsCount(savedState.totalChipsCount || []);
setSelectedCurrency(savedState.selectedCurrency || "$"); setSelectedCurrency(savedState.selectedCurrency || "$");
} else {
console.log("No persistent state found, using defaults.");
} }
} catch (error) { } catch (error) {
console.error("Error loading persistent state:", error); console.error("Error loading persistent state:", error);
@ -62,19 +61,12 @@ const IndexScreen: React.FC = () => {
totalChipsCount, totalChipsCount,
selectedCurrency, selectedCurrency,
}; };
try {
await saveState(slot, state); await saveState(slot, state);
await savePersistentState(state); await savePersistentState(state);
console.log(`Game state saved to ${slot}:`, state); Alert.alert(i18n.t("success"), i18n.t("state_saved", { slot }));
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"));
}
}; };
const handleLoad = async (slot: "SLOT1" | "SLOT2") => { const handleLoad = async (slot: "SLOT1" | "SLOT2") => {
try {
const loadedState = await loadState(slot); const loadedState = await loadState(slot);
if (loadedState) { if (loadedState) {
setPlayerCount(loadedState.playerCount); setPlayerCount(loadedState.playerCount);
@ -83,15 +75,10 @@ const IndexScreen: React.FC = () => {
setTotalChipsCount(loadedState.totalChipsCount); setTotalChipsCount(loadedState.totalChipsCount);
setSelectedCurrency(loadedState.selectedCurrency || "$"); setSelectedCurrency(loadedState.selectedCurrency || "$");
await savePersistentState(loadedState); await savePersistentState(loadedState);
console.log(`Game state loaded from ${slot}:`, loadedState); Alert.alert(i18n.t("success"), i18n.t("state_loaded_from", { slot }));
Alert.alert(i18n.t("success"), i18n.t("state_loaded_from", { slot })); // Fixed interpolation
} else { } else {
Alert.alert(i18n.t("info"), i18n.t("no_saved_state_found")); 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 handleLanguageChange = (language: string) => { const handleLanguageChange = (language: string) => {
@ -100,10 +87,26 @@ const IndexScreen: React.FC = () => {
}; };
return ( return (
<PokerAppUi darkMode={lightGrayMode}>
<ScrollView <ScrollView
style={styles.scrollView} style={styles.scrollView}
contentContainerStyle={styles.scrollViewContent} contentContainerStyle={styles.scrollViewContent}
> >
<Section
title={i18n.t("appearance")}
iconName={"brightness-4"}
orientation="row"
>
<Button
title={
lightGrayMode
? i18n.t("switch_to_light_mode")
: i18n.t("switch_to_gray_mode")
}
onPress={() => setLightGrayMode(!lightGrayMode)}
/>
</Section>
{isSettingsVisible && ( {isSettingsVisible && (
<Section <Section
title={i18n.t("select_language")} title={i18n.t("select_language")}
@ -200,7 +203,6 @@ const IndexScreen: React.FC = () => {
iconName={"save"} iconName={"save"}
orientation="row" orientation="row"
> >
<>
<Button <Button
title={i18n.t("save_slot_1")} title={i18n.t("save_slot_1")}
onPress={() => handleSave("SLOT1")} onPress={() => handleSave("SLOT1")}
@ -219,9 +221,9 @@ const IndexScreen: React.FC = () => {
title={i18n.t("load_slot_2")} title={i18n.t("load_slot_2")}
onPress={() => handleLoad("SLOT2")} onPress={() => handleLoad("SLOT2")}
/> />
</>
</Section> </Section>
</ScrollView> </ScrollView>
</PokerAppUi>
); );
}; };

View File

@ -1,9 +1,69 @@
import { ButtonProps, Button } from "react-native"; import React from "react";
import { COLORS } from "@/styles/styles"; 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 interface ButtonProps {
const AppButton = (props: ButtonProps) => ( title: string;
<Button color={COLORS.PRIMARY} {...props} /> onPress: () => void;
); disabled?: boolean;
darkMode: boolean;
}
export default AppButton; const Button: React.FC<ButtonProps> = ({
title,
onPress,
disabled,
darkMode,
}) => {
return (
<TouchableOpacity
onPress={onPress}
disabled={disabled}
style={[
styles.button,
darkMode ? styles.darkButton : styles.lightButton,
disabled && styles.disabled,
]}
>
<Text
style={[
styles.buttonText,
darkMode ? styles.darkText : styles.lightText,
]}
>
{title}
</Text>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
button: {
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 8,
marginHorizontal: 5,
marginVertical: 5,
},
darkButton: {
backgroundColor: "#333333",
},
lightButton: {
backgroundColor: "#DDDDDD",
},
buttonText: {
fontSize: 16,
fontWeight: "bold",
textAlign: "center",
},
darkText: {
color: "#FFFFFF",
},
lightText: {
color: "#000000",
},
disabled: {
opacity: 0.5,
},
});
export default Button;

52
containers/PokerAppUi.tsx Normal file
View File

@ -0,0 +1,52 @@
import React, { ReactNode } from "react";
import {
SafeAreaView,
StatusBar,
View,
StyleSheet,
Dimensions,
} from "react-native";
interface PokerAppUiProps {
children: ReactNode;
darkMode?: boolean;
}
const PokerAppUi: React.FC<PokerAppUiProps> = ({
children,
darkMode = false,
}) => {
const screenHeight = Dimensions.get("window").height;
return (
<SafeAreaView
style={[styles.safeArea, darkMode ? styles.lightGray : styles.light]}
>
<StatusBar barStyle={"dark-content"} />
<View style={[styles.container, { minHeight: screenHeight }]}>
{children}
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
safeArea: {
flex: 1,
},
container: {
flex: 1,
width: "100%",
padding: 16,
justifyContent: "flex-start",
alignItems: "center",
},
light: {
backgroundColor: "#F5F5F5",
},
lightGray: {
backgroundColor: "#D3D3D3",
},
});
export default PokerAppUi;

2
package-lock.json generated
View File

@ -13,7 +13,7 @@
"@react-native-picker/picker": "^2.11.0", "@react-native-picker/picker": "^2.11.0",
"@react-navigation/bottom-tabs": "7.2.0", "@react-navigation/bottom-tabs": "7.2.0",
"@react-navigation/native": "7.0.14", "@react-navigation/native": "7.0.14",
"expo": "52.0.37", "expo": "^52.0.37",
"expo-blur": "14.0.3", "expo-blur": "14.0.3",
"expo-constants": "17.0.7", "expo-constants": "17.0.7",
"expo-file-system": "18.0.11", "expo-file-system": "18.0.11",

View File

@ -23,7 +23,7 @@
"@react-native-picker/picker": "^2.11.0", "@react-native-picker/picker": "^2.11.0",
"@react-navigation/bottom-tabs": "7.2.0", "@react-navigation/bottom-tabs": "7.2.0",
"@react-navigation/native": "7.0.14", "@react-navigation/native": "7.0.14",
"expo": "52.0.37", "expo": "^52.0.37",
"expo-blur": "14.0.3", "expo-blur": "14.0.3",
"expo-constants": "17.0.7", "expo-constants": "17.0.7",
"expo-file-system": "18.0.11", "expo-file-system": "18.0.11",
@ -31,6 +31,7 @@
"expo-haptics": "14.0.1", "expo-haptics": "14.0.1",
"expo-image-picker": "16.0.6", "expo-image-picker": "16.0.6",
"expo-linking": "7.0.5", "expo-linking": "7.0.5",
"expo-localization": "~16.0.1",
"expo-router": "4.0.17", "expo-router": "4.0.17",
"expo-splash-screen": "0.29.22", "expo-splash-screen": "0.29.22",
"expo-status-bar": "2.0.1", "expo-status-bar": "2.0.1",
@ -47,8 +48,7 @@
"react-native-safe-area-context": "4.12.0", "react-native-safe-area-context": "4.12.0",
"react-native-screens": "4.4.0", "react-native-screens": "4.4.0",
"react-native-web": "0.19.13", "react-native-web": "0.19.13",
"react-native-webview": "13.12.5", "react-native-webview": "13.12.5"
"expo-localization": "~16.0.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "7.26.9", "@babel/core": "7.26.9",

View File

@ -1,12 +1,12 @@
import AsyncStorage from "@react-native-async-storage/async-storage"; import AsyncStorage from "@react-native-async-storage/async-storage";
import { saveState, loadState, PokerState } from "../CalculatorState"; import { saveState, loadState, PokerState } from "@/util/CalculatorState";
// Mock AsyncStorage // Mock AsyncStorage
jest.mock("@react-native-async-storage/async-storage", () => jest.mock("@react-native-async-storage/async-storage", () =>
require("@react-native-async-storage/async-storage/jest/async-storage-mock") require("@react-native-async-storage/async-storage/jest/async-storage-mock")
); );
describe("CalculatorState.tsx", () => { describe("CalculatorState.ts", () => {
const mockState: PokerState = { const mockState: PokerState = {
playerCount: 4, playerCount: 4,
buyInAmount: 50, buyInAmount: 50,

View File

@ -3,14 +3,14 @@ import {
savePersistentState, savePersistentState,
loadPersistentState, loadPersistentState,
PokerState, PokerState,
} from "../PersistentState"; } from "@/util/PersistentState";
jest.mock("@react-native-async-storage/async-storage", () => ({ jest.mock("@react-native-async-storage/async-storage", () => ({
setItem: jest.fn(), setItem: jest.fn(),
getItem: jest.fn(), getItem: jest.fn(),
})); }));
describe("PersistentState.tsx", () => { describe("PersistentState.ts", () => {
const mockState: PokerState = { const mockState: PokerState = {
playerCount: 4, playerCount: 4,
buyInAmount: 50, buyInAmount: 50,