Compare commits
No commits in common. "main" and "djwesty/51" have entirely different histories.
main
...
djwesty/51
3
app.json
3
app.json
@ -9,8 +9,7 @@
|
|||||||
"userInterfaceStyle": "automatic",
|
"userInterfaceStyle": "automatic",
|
||||||
"newArchEnabled": true,
|
"newArchEnabled": true,
|
||||||
"ios": {
|
"ios": {
|
||||||
"supportsTablet": true,
|
"supportsTablet": true
|
||||||
"bundleIdentifier": "com.anonymous.pokerchipshelper"
|
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
"adaptiveIcon": {
|
"adaptiveIcon": {
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
import i18n from "@/i18n/i18n";
|
import i18n from "@/i18n/i18n";
|
||||||
import { COLORS } from "@/styles/styles";
|
|
||||||
import AppContext, { IAppContext } from "@/util/context";
|
import AppContext, { IAppContext } from "@/util/context";
|
||||||
import { MaterialIcons } from "@expo/vector-icons";
|
import { MaterialIcons } from "@expo/vector-icons";
|
||||||
import { Stack } from "expo-router";
|
import { Stack } from "expo-router";
|
||||||
import React, { useMemo, useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import { I18nextProvider, useTranslation } from "react-i18next";
|
import { I18nextProvider, useTranslation } from "react-i18next";
|
||||||
import { useColorScheme } from "react-native";
|
|
||||||
|
|
||||||
const RootLayout: React.FC = () => {
|
const RootLayout: React.FC = () => {
|
||||||
const [showSettings, setShowSettings] = useState<boolean>(false);
|
const [showSettings, setShowSettings] = useState<boolean>(false);
|
||||||
@ -19,36 +17,20 @@ const RootLayout: React.FC = () => {
|
|||||||
[showSettings]
|
[showSettings]
|
||||||
);
|
);
|
||||||
|
|
||||||
const colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<AppContext.Provider value={ctx}>
|
<AppContext.Provider value={ctx}>
|
||||||
<I18nextProvider i18n={i18n}>
|
<I18nextProvider i18n={i18n}>
|
||||||
<Stack
|
<Stack
|
||||||
screenOptions={{
|
screenOptions={{
|
||||||
contentStyle: {
|
|
||||||
backgroundColor: colors.BACKGROUND,
|
|
||||||
},
|
|
||||||
headerShown: true,
|
headerShown: true,
|
||||||
title: t("poker_chips_helper"),
|
title: t("poker_chips_helper"),
|
||||||
navigationBarColor: colors.PRIMARY,
|
|
||||||
headerRight: () => (
|
headerRight: () => (
|
||||||
<MaterialIcons
|
<MaterialIcons
|
||||||
name="settings"
|
name="settings"
|
||||||
onPress={() => setShowSettings(!showSettings)}
|
onPress={() => setShowSettings(!showSettings)}
|
||||||
size={30}
|
size={30}
|
||||||
color={colors.TEXT}
|
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
headerStyle: {
|
|
||||||
backgroundColor: colors.PRIMARY,
|
|
||||||
},
|
|
||||||
headerTintColor: colors.TEXT,
|
|
||||||
statusBarBackgroundColor: "grey",
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</I18nextProvider>
|
</I18nextProvider>
|
||||||
|
144
app/index.tsx
144
app/index.tsx
@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect, useContext, useMemo } from "react";
|
import React, { useState, useEffect, useContext, useMemo } from "react";
|
||||||
import { ScrollView, Alert, useColorScheme, Appearance } from "react-native";
|
import { ScrollView, Alert } from "react-native";
|
||||||
import Button from "@/containers/Button";
|
import Button from "@/containers/Button";
|
||||||
import PlayerSelector from "@/components/PlayerSelector";
|
import PlayerSelector from "@/components/PlayerSelector";
|
||||||
import BuyInSelector from "@/components/BuyInSelector";
|
import BuyInSelector from "@/components/BuyInSelector";
|
||||||
@ -7,17 +7,16 @@ 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 "@/util/CalculatorState";
|
import { saveState, loadState } from "@/components/CalculatorState";
|
||||||
import {
|
import {
|
||||||
savePersistentState,
|
savePersistentState,
|
||||||
loadPersistentState,
|
loadPersistentState,
|
||||||
} from "@/util/PersistentState";
|
} from "@/components/PersistentState";
|
||||||
import styles, { COLORS } 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 i18n from "@/i18n/i18n";
|
import i18n from "@/i18n/i18n";
|
||||||
import { Picker, PickerItem } from "@/containers/Picker";
|
|
||||||
import { ItemValue } from "@react-native-picker/picker/typings/Picker";
|
|
||||||
|
|
||||||
const IndexScreen: React.FC = () => {
|
const IndexScreen: React.FC = () => {
|
||||||
const [playerCount, setPlayerCount] = useState(2);
|
const [playerCount, setPlayerCount] = useState(2);
|
||||||
@ -26,25 +25,23 @@ 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 colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
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);
|
||||||
@ -65,29 +62,41 @@ const IndexScreen: React.FC = () => {
|
|||||||
totalChipsCount,
|
totalChipsCount,
|
||||||
selectedCurrency,
|
selectedCurrency,
|
||||||
};
|
};
|
||||||
await saveState(slot, state);
|
try {
|
||||||
await savePersistentState(state);
|
await saveState(slot, state);
|
||||||
Alert.alert(i18n.t("success"), i18n.t("state_saved", { slot }));
|
await savePersistentState(state);
|
||||||
};
|
console.log(`Game state saved to ${slot}:`, state);
|
||||||
|
Alert.alert(i18n.t("success"), i18n.t("state_saved", { slot })); // Fixed interpolation
|
||||||
const handleLoad = async (slot: "SLOT1" | "SLOT2") => {
|
} catch (error) {
|
||||||
const loadedState = await loadState(slot);
|
console.error("Error saving state:", error);
|
||||||
if (loadedState) {
|
Alert.alert(i18n.t("error"), i18n.t("failed_to_save_state"));
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLanguageChange = (language: ItemValue, _: any) => {
|
const handleLoad = async (slot: "SLOT1" | "SLOT2") => {
|
||||||
setSelectedLanguage(language.toString());
|
try {
|
||||||
i18n.changeLanguage(language.toString());
|
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 handleLanguageChange = (language: string) => {
|
||||||
|
setSelectedLanguage(language);
|
||||||
|
i18n.changeLanguage(language);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -96,49 +105,33 @@ const IndexScreen: React.FC = () => {
|
|||||||
contentContainerStyle={styles.scrollViewContent}
|
contentContainerStyle={styles.scrollViewContent}
|
||||||
>
|
>
|
||||||
{isSettingsVisible && (
|
{isSettingsVisible && (
|
||||||
<>
|
<Section
|
||||||
<Section
|
title={i18n.t("select_language")}
|
||||||
title={i18n.t("appearance")}
|
iconName={"language"}
|
||||||
iconName={"brightness-4"}
|
orientation="row"
|
||||||
orientation="row"
|
>
|
||||||
|
<Picker
|
||||||
|
selectedValue={selectedLanguage}
|
||||||
|
onValueChange={handleLanguageChange}
|
||||||
|
style={styles.picker}
|
||||||
>
|
>
|
||||||
<Button
|
<Picker.Item label={i18n.t("english")} value="en" />
|
||||||
title={
|
<Picker.Item label={i18n.t("spanish")} value="es" />
|
||||||
darkMode
|
</Picker>
|
||||||
? i18n.t("switch_to_light_mode")
|
</Section>
|
||||||
: i18n.t("switch_to_dark_mode")
|
)}
|
||||||
}
|
|
||||||
onPress={() =>
|
|
||||||
Appearance.setColorScheme(darkMode ? "light" : "dark")
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section
|
{isSettingsVisible && (
|
||||||
title={i18n.t("select_language")}
|
<Section
|
||||||
iconName={"language"}
|
title={i18n.t("select_currency")}
|
||||||
orientation="row"
|
iconName={"attach-money"}
|
||||||
>
|
orientation="row"
|
||||||
<Picker
|
>
|
||||||
selectedValue={selectedLanguage}
|
<CurrencySelector
|
||||||
onValueChange={handleLanguageChange}
|
selectedCurrency={selectedCurrency}
|
||||||
>
|
setSelectedCurrency={setSelectedCurrency}
|
||||||
<PickerItem label={i18n.t("english")} value="en" />
|
/>
|
||||||
<PickerItem label={i18n.t("spanish")} value="es" />
|
</Section>
|
||||||
</Picker>
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
<Section
|
|
||||||
title={i18n.t("select_currency")}
|
|
||||||
iconName={"attach-money"}
|
|
||||||
orientation="row"
|
|
||||||
>
|
|
||||||
<CurrencySelector
|
|
||||||
selectedCurrency={selectedCurrency}
|
|
||||||
setSelectedCurrency={setSelectedCurrency}
|
|
||||||
/>
|
|
||||||
</Section>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Section
|
<Section
|
||||||
@ -171,7 +164,6 @@ const IndexScreen: React.FC = () => {
|
|||||||
updateChipCount={(chipData) => {
|
updateChipCount={(chipData) => {
|
||||||
const chipCountArray = Object.values(chipData);
|
const chipCountArray = Object.values(chipData);
|
||||||
setTotalChipsCount(chipCountArray);
|
setTotalChipsCount(chipCountArray);
|
||||||
setNumberOfChips(chipCountArray.length);
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Section>
|
</Section>
|
||||||
@ -212,23 +204,19 @@ const IndexScreen: React.FC = () => {
|
|||||||
title={i18n.t("save_slot_1")}
|
title={i18n.t("save_slot_1")}
|
||||||
onPress={() => handleSave("SLOT1")}
|
onPress={() => handleSave("SLOT1")}
|
||||||
disabled={buyInAmount === null}
|
disabled={buyInAmount === null}
|
||||||
size="small"
|
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
title={i18n.t("save_slot_2")}
|
title={i18n.t("save_slot_2")}
|
||||||
onPress={() => handleSave("SLOT2")}
|
onPress={() => handleSave("SLOT2")}
|
||||||
disabled={buyInAmount === null}
|
disabled={buyInAmount === null}
|
||||||
size="small"
|
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
title={i18n.t("load_slot_1")}
|
title={i18n.t("load_slot_1")}
|
||||||
onPress={() => handleLoad("SLOT1")}
|
onPress={() => handleLoad("SLOT1")}
|
||||||
size="small"
|
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
title={i18n.t("load_slot_2")}
|
title={i18n.t("load_slot_2")}
|
||||||
onPress={() => handleLoad("SLOT2")}
|
onPress={() => handleLoad("SLOT2")}
|
||||||
size="small"
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
</Section>
|
</Section>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useMemo, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { View, Text, TextInput, useColorScheme } from "react-native";
|
import { View, Text, TextInput } from "react-native";
|
||||||
import styles, { COLORS } from "@/styles/styles";
|
import styles, { COLORS } from "@/styles/styles";
|
||||||
import Button from "@/containers/Button";
|
import Button from "@/containers/Button";
|
||||||
import i18n from "@/i18n/i18n";
|
import i18n from "@/i18n/i18n";
|
||||||
@ -10,14 +10,6 @@ interface BuyInSelectorProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultBuyInOptions = [10, 25, 50];
|
const defaultBuyInOptions = [10, 25, 50];
|
||||||
const MIN = 1;
|
|
||||||
const MAX = 200;
|
|
||||||
|
|
||||||
const parseRoundClamp = (num: string): number => {
|
|
||||||
const parsed = parseFloat(num);
|
|
||||||
const rounded = Math.round(parsed);
|
|
||||||
return Math.min(Math.max(rounded, MIN), MAX);
|
|
||||||
};
|
|
||||||
|
|
||||||
const BuyInSelector: React.FC<BuyInSelectorProps> = ({
|
const BuyInSelector: React.FC<BuyInSelectorProps> = ({
|
||||||
setBuyInAmount,
|
setBuyInAmount,
|
||||||
@ -25,17 +17,11 @@ const BuyInSelector: React.FC<BuyInSelectorProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [customAmount, setCustomAmount] = useState("");
|
const [customAmount, setCustomAmount] = useState("");
|
||||||
const [buyInAmount, setBuyInAmountState] = useState<number | null>(null);
|
const [buyInAmount, setBuyInAmountState] = useState<number | null>(null);
|
||||||
const colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleCustomAmountChange = (value: string) => {
|
const handleCustomAmountChange = (value: string) => {
|
||||||
const numericValue = parseRoundClamp(value);
|
const numericValue = parseFloat(value);
|
||||||
if (!isNaN(numericValue) && numericValue >= 0) {
|
if (!isNaN(numericValue) && numericValue >= 0) {
|
||||||
setCustomAmount(numericValue.toString());
|
setCustomAmount(value);
|
||||||
setBuyInAmountState(numericValue);
|
setBuyInAmountState(numericValue);
|
||||||
setBuyInAmount(numericValue);
|
setBuyInAmount(numericValue);
|
||||||
} else {
|
} else {
|
||||||
@ -57,24 +43,25 @@ const BuyInSelector: React.FC<BuyInSelectorProps> = ({
|
|||||||
{defaultBuyInOptions.map((amount) => (
|
{defaultBuyInOptions.map((amount) => (
|
||||||
<Button
|
<Button
|
||||||
key={amount}
|
key={amount}
|
||||||
|
color={buyInAmount === amount ? COLORS.PRIMARY : COLORS.SECONDARY}
|
||||||
onPress={() => handleBuyInSelection(amount)}
|
onPress={() => handleBuyInSelection(amount)}
|
||||||
title={`${selectedCurrency} ${amount}`}
|
title={`${selectedCurrency} ${amount}`}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
<Text style={styles.p}>{i18n.t("custom_buy_in")}</Text>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
style={[styles.input, { color: colors.TEXT }]}
|
style={styles.input}
|
||||||
placeholderTextColor={colors.TEXT}
|
|
||||||
value={customAmount}
|
value={customAmount}
|
||||||
maxLength={3}
|
|
||||||
onChangeText={handleCustomAmountChange}
|
onChangeText={handleCustomAmountChange}
|
||||||
placeholder={`${i18n.t("custom_buy_in")} ${MIN} - ${MAX}`}
|
placeholder={i18n.t("enter_custom_buy_in")}
|
||||||
keyboardType="numeric"
|
keyboardType="numeric"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Text style={[styles.h2, { color: colors.TEXT }]}>
|
<Text style={styles.h2}>
|
||||||
{`${i18n.t("selected_buy_in")} `}
|
{`${i18n.t("selected_buy_in")}: `}
|
||||||
{buyInAmount !== null
|
{buyInAmount !== null
|
||||||
? `${selectedCurrency} ${buyInAmount}`
|
? `${selectedCurrency} ${buyInAmount}`
|
||||||
: i18n.t("none")}
|
: i18n.t("none")}
|
||||||
|
@ -16,8 +16,6 @@ const ChipDetection = ({
|
|||||||
Record<string, number>
|
Record<string, number>
|
||||||
>({});
|
>({});
|
||||||
|
|
||||||
const chipColors = ["white", "red", "green", "blue", "black"];
|
|
||||||
|
|
||||||
const requestCameraPermissions = async () => {
|
const requestCameraPermissions = async () => {
|
||||||
const cameraPermission = await ImagePicker.requestCameraPermissionsAsync();
|
const cameraPermission = await ImagePicker.requestCameraPermissionsAsync();
|
||||||
return cameraPermission.granted;
|
return cameraPermission.granted;
|
||||||
@ -94,26 +92,16 @@ const ChipDetection = ({
|
|||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
if (!response.ok || !result.choices || !result.choices[0].message) {
|
if (!response.ok || !result.choices || !result.choices[0].message) {
|
||||||
throw new Error(i18n.t("invalid_response"));
|
throw new Error(i18n.t("invalid_response")); // Translate invalid response error
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawContent = result.choices[0].message.content.trim();
|
const rawContent = result.choices[0].message.content.trim();
|
||||||
const cleanJSON = rawContent.replace(/```json|```/g, "").trim();
|
const cleanJSON = rawContent.replace(/```json|```/g, "").trim();
|
||||||
const parsedData: Record<string, number> = JSON.parse(cleanJSON);
|
const parsedData: Record<string, number> = JSON.parse(cleanJSON);
|
||||||
|
|
||||||
const filteredData = Object.entries(parsedData)
|
const filteredData = Object.fromEntries(
|
||||||
.filter(([color]) => chipColors.includes(color))
|
Object.entries(parsedData).filter(([_, count]) => count > 0)
|
||||||
.sort(
|
);
|
||||||
([colorA], [colorB]) =>
|
|
||||||
chipColors.indexOf(colorA) - chipColors.indexOf(colorB)
|
|
||||||
)
|
|
||||||
.reduce(
|
|
||||||
(acc, [color, count]) => {
|
|
||||||
acc[color] = count;
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{} as Record<string, number>
|
|
||||||
);
|
|
||||||
|
|
||||||
setLastDetectedChips(filteredData);
|
setLastDetectedChips(filteredData);
|
||||||
updateChipCount(filteredData);
|
updateChipCount(filteredData);
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { View, Text, Alert } from "react-native";
|
import { View, Text, StyleSheet } from "react-native";
|
||||||
import { ColorValue } from "react-native";
|
import { ColorValue } from "react-native";
|
||||||
import i18n from "@/i18n/i18n";
|
import i18n from "@/i18n/i18n";
|
||||||
import styles, { COLORS } from "@/styles/styles";
|
import styles from "@/styles/styles";
|
||||||
import { MaterialIcons } from "@expo/vector-icons";
|
|
||||||
|
|
||||||
interface ChipDistributionSummaryProps {
|
interface ChipDistributionSummaryProps {
|
||||||
playerCount: number;
|
playerCount: number;
|
||||||
@ -13,8 +12,6 @@ interface ChipDistributionSummaryProps {
|
|||||||
selectedCurrency: string;
|
selectedCurrency: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const reverseFib: number[] = [8, 5, 3, 2, 1];
|
|
||||||
|
|
||||||
const ChipDistributionSummary = ({
|
const ChipDistributionSummary = ({
|
||||||
playerCount,
|
playerCount,
|
||||||
buyInAmount,
|
buyInAmount,
|
||||||
@ -23,15 +20,11 @@ const ChipDistributionSummary = ({
|
|||||||
selectedCurrency = "$",
|
selectedCurrency = "$",
|
||||||
}: ChipDistributionSummaryProps) => {
|
}: ChipDistributionSummaryProps) => {
|
||||||
const validDenominations: validDenomination[] = [
|
const validDenominations: validDenomination[] = [
|
||||||
0.05, 0.1, 0.25, 1, 5, 10, 20, 50, 100,
|
0.05, 0.1, 0.25, 0.5, 1, 2, 2.5, 5, 10, 20, 50, 100,
|
||||||
];
|
];
|
||||||
const [denominations, setDenominations] = useState<validDenomination[]>([]);
|
const [denominations, setDenominations] = useState<validDenomination[]>([]);
|
||||||
const [distributions, setDistributions] = useState<number[]>([]);
|
const [distributions, setDistributions] = useState<number[]>([]);
|
||||||
|
|
||||||
const showAlert = () => {
|
|
||||||
Alert.alert(i18n.t("warning"), i18n.t("chip_value_warn"));
|
|
||||||
};
|
|
||||||
|
|
||||||
type validDenomination =
|
type validDenomination =
|
||||||
| 0.05
|
| 0.05
|
||||||
| 0.1
|
| 0.1
|
||||||
@ -43,112 +36,120 @@ const ChipDistributionSummary = ({
|
|||||||
| 5
|
| 5
|
||||||
| 10
|
| 10
|
||||||
| 20
|
| 20
|
||||||
| 25
|
|
||||||
| 50
|
| 50
|
||||||
| 100;
|
| 100;
|
||||||
|
|
||||||
const findFloorDenomination = (target: number): validDenomination => {
|
const findFloorDenomination = (target: number): validDenomination => {
|
||||||
let current: validDenomination = validDenominations[0];
|
let current: validDenomination = validDenominations[0];
|
||||||
validDenominations.forEach((value, _) => {
|
validDenominations.forEach((value, index) => {
|
||||||
if (value < target) current = value;
|
if (value < target) current = value;
|
||||||
});
|
});
|
||||||
return current;
|
return current;
|
||||||
};
|
};
|
||||||
|
|
||||||
const round = useCallback((num: number) => Math.round(num * 100) / 100, []);
|
const maxDenomination = useMemo(() => {
|
||||||
|
if (totalChipsCount.length > 3) {
|
||||||
// Bound for the value of the highest chip
|
return findFloorDenomination(buyInAmount / 3);
|
||||||
// This is somewhat arbitray and imperfect, but 1/3 to 1/5 is reasonable depending on the number of colors.
|
} else {
|
||||||
// Could be possibly improved based on value of buy in amount
|
return findFloorDenomination(buyInAmount / 4);
|
||||||
const maxDenomination: validDenomination = useMemo(() => {
|
|
||||||
let max: validDenomination;
|
|
||||||
switch (totalChipsCount.length) {
|
|
||||||
case 5:
|
|
||||||
case 4:
|
|
||||||
max = findFloorDenomination(buyInAmount / 3);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
max = findFloorDenomination(buyInAmount / 4);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
case 1:
|
|
||||||
default:
|
|
||||||
max = findFloorDenomination(buyInAmount / 5);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return max;
|
}, [totalChipsCount]);
|
||||||
}, [totalChipsCount, buyInAmount]);
|
|
||||||
|
|
||||||
const potValue = useMemo(
|
const potValue = useMemo(
|
||||||
() => buyInAmount * playerCount,
|
() => buyInAmount * playerCount,
|
||||||
[buyInAmount, playerCount]
|
[buyInAmount, playerCount]
|
||||||
);
|
);
|
||||||
|
|
||||||
// The total value of all chips distributed to a single player. Ideally should be equal to buyInAmount
|
|
||||||
const totalValue = useMemo(() => {
|
const totalValue = useMemo(() => {
|
||||||
let value = 0;
|
let value = 0;
|
||||||
for (let i = 0; i < distributions.length; i++) {
|
for (let i = 0; i < totalChipsCount.length; i++) {
|
||||||
value += distributions[i] * denominations[i];
|
value += distributions[i] * denominations[i];
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}, [distributions, denominations]);
|
}, [distributions, denominations]);
|
||||||
|
|
||||||
// Maximum quantity of each chip color which may be distributed to a single player before running out
|
|
||||||
const maxPossibleDistribution = useMemo(
|
const maxPossibleDistribution = useMemo(
|
||||||
() => totalChipsCount.map((v) => Math.floor(v / playerCount)),
|
() => totalChipsCount.map((v) => Math.floor(v / playerCount)),
|
||||||
[totalChipsCount, playerCount]
|
[totalChipsCount, playerCount]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Dynamically set denominations and distributions from changing inputs
|
const redenominate = useCallback(
|
||||||
|
(
|
||||||
|
invalidDenomination: validDenomination[],
|
||||||
|
shuffleIndex: number
|
||||||
|
): validDenomination[] => {
|
||||||
|
let moved = false;
|
||||||
|
const newDenomination: validDenomination[] = [];
|
||||||
|
for (let i = invalidDenomination.length - 1; i >= 0; i--) {
|
||||||
|
if (i > shuffleIndex) {
|
||||||
|
newDenomination.push(invalidDenomination[i]);
|
||||||
|
} else if (i == shuffleIndex) {
|
||||||
|
newDenomination.push(invalidDenomination[i]);
|
||||||
|
} else if (i < shuffleIndex && !moved) {
|
||||||
|
const nextLowestDenominationIndex = Math.max(
|
||||||
|
validDenominations.indexOf(invalidDenomination[i]) - 1,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
newDenomination.push(validDenominations[nextLowestDenominationIndex]);
|
||||||
|
moved = true;
|
||||||
|
} else {
|
||||||
|
newDenomination.push(invalidDenomination[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newDenomination.reverse();
|
||||||
|
return newDenomination;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let testDenomination: validDenomination[] = [];
|
let testDenomination: validDenomination[] = [];
|
||||||
const totalNumColors = totalChipsCount.length;
|
const numColors = totalChipsCount.length;
|
||||||
|
|
||||||
// Start with max denominations, then push on the next adjacent lower denomination
|
|
||||||
testDenomination.push(maxDenomination);
|
|
||||||
let currentDenominationIndex: number =
|
|
||||||
validDenominations.indexOf(maxDenomination);
|
|
||||||
for (
|
|
||||||
let i = totalNumColors - 2;
|
|
||||||
i >= 0 && currentDenominationIndex > 0;
|
|
||||||
i = i - 1
|
|
||||||
) {
|
|
||||||
currentDenominationIndex -= 1;
|
|
||||||
const currentDemoniation = validDenominations[currentDenominationIndex];
|
|
||||||
testDenomination.push(currentDemoniation);
|
|
||||||
}
|
|
||||||
testDenomination.reverse();
|
|
||||||
let numColors = testDenomination.length;
|
|
||||||
|
|
||||||
const testDistribution: number[] = [];
|
const testDistribution: number[] = [];
|
||||||
for (let i = 0; i < numColors; ++i) {
|
for (let i = 0; i < numColors; ++i) {
|
||||||
testDistribution.push(0);
|
testDistribution.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distribute the chips using the test denomination with a reverse fibbonaci preference
|
testDenomination.push(maxDenomination);
|
||||||
// Not optimal, nor correct under all inputs but works for most inputs
|
let currentDenominationIndex: number =
|
||||||
// Algorithm could be improved with more complexity and optimization (re-tries, redenominating, etc.)
|
validDenominations.indexOf(maxDenomination);
|
||||||
|
for (let i = numColors - 2; i >= 0; i = i - 1) {
|
||||||
|
currentDenominationIndex -= 1;
|
||||||
|
const currentDemoniation = validDenominations[currentDenominationIndex];
|
||||||
|
testDenomination.push(currentDemoniation);
|
||||||
|
}
|
||||||
|
testDenomination.reverse();
|
||||||
|
|
||||||
let remainingValue = buyInAmount;
|
let remainingValue = buyInAmount;
|
||||||
let stop = false;
|
let fail = true;
|
||||||
while (remainingValue > 0 && !stop) {
|
let failCount = 0;
|
||||||
let distributed = false;
|
while (fail && failCount < 1) {
|
||||||
for (let i = numColors - 1; i >= 0; i = i - 1) {
|
let stop = false;
|
||||||
for (
|
while (remainingValue > 0 && !stop) {
|
||||||
let j = reverseFib[i];
|
let distributed = false;
|
||||||
j > 0 &&
|
for (let i = numColors - 1; i >= 0; i = i - 1) {
|
||||||
remainingValue >= testDenomination[i] &&
|
if (testDistribution[i] < maxPossibleDistribution[i]) {
|
||||||
testDistribution[i] < maxPossibleDistribution[i];
|
if (remainingValue >= testDenomination[i]) {
|
||||||
j = j - 1
|
testDistribution[i] = testDistribution[i] + 1;
|
||||||
) {
|
remainingValue = remainingValue - testDenomination[i];
|
||||||
testDistribution[i] = testDistribution[i] + 1;
|
distributed = true;
|
||||||
remainingValue = round(remainingValue - testDenomination[i]);
|
}
|
||||||
distributed = true;
|
}
|
||||||
|
}
|
||||||
|
if (distributed == false) {
|
||||||
|
stop = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (distributed == false) {
|
if (remainingValue !== 0) {
|
||||||
stop = true;
|
const redenominateIndex = failCount % numColors;
|
||||||
|
testDenomination = redenominate(testDenomination, redenominateIndex);
|
||||||
|
failCount += 1;
|
||||||
|
fail = true;
|
||||||
|
} else {
|
||||||
|
fail = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setDenominations(testDenomination);
|
setDenominations(testDenomination);
|
||||||
setDistributions(testDistribution);
|
setDistributions(testDistribution);
|
||||||
}, [totalChipsCount, maxDenomination, buyInAmount, playerCount]);
|
}, [totalChipsCount, maxDenomination, buyInAmount, playerCount]);
|
||||||
@ -156,39 +157,24 @@ const ChipDistributionSummary = ({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
{distributions.map((distribution, index) => {
|
{totalChipsCount.map((_, index) => (
|
||||||
return (
|
<View style={{ flexDirection: "row" }} key={index}>
|
||||||
distribution > 0 && (
|
<Text
|
||||||
<View style={{ flexDirection: "row" }} key={index}>
|
style={{
|
||||||
<Text
|
...styles.h2,
|
||||||
style={{
|
color: colors[index],
|
||||||
...styles.h2,
|
...(colors[index] === "white" && styles.shadow),
|
||||||
fontWeight: "bold",
|
}}
|
||||||
color: colors[index],
|
>
|
||||||
...(colors[index] === "white" && styles.shadow),
|
{`${distributions[index]} ${i18n.t("chips")}: ${selectedCurrency}${denominations[index]} ${i18n.t("each")}`}
|
||||||
}}
|
</Text>
|
||||||
>
|
</View>
|
||||||
{`${distribution} ${i18n.t("chips")}: ${selectedCurrency}${denominations[index]} ${i18n.t("each")}`}
|
))}
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
</View>
|
||||||
<View style={{ flexDirection: "row", justifyContent: "space-between" }}>
|
<View style={{ flexDirection: "row", justifyContent: "space-between" }}>
|
||||||
<View style={[styles.container, { flexDirection: "row", gap: 1 }]}>
|
<Text style={styles.p}>
|
||||||
<Text style={styles.p}>
|
{i18n.t("total_value")}: {selectedCurrency} {totalValue}
|
||||||
{i18n.t("total_value")}: {selectedCurrency} {round(totalValue)}{" "}
|
</Text>
|
||||||
</Text>
|
|
||||||
{round(totalValue) !== buyInAmount && (
|
|
||||||
<MaterialIcons
|
|
||||||
name="warning"
|
|
||||||
size={20}
|
|
||||||
color={COLORS.WARNING}
|
|
||||||
onPress={showAlert}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
<Text style={styles.p}>
|
<Text style={styles.p}>
|
||||||
{selectedCurrency} {potValue} {i18n.t("pot")}
|
{selectedCurrency} {potValue} {i18n.t("pot")}
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -14,7 +14,6 @@ import styles from "@/styles/styles";
|
|||||||
import i18n from "@/i18n/i18n";
|
import i18n from "@/i18n/i18n";
|
||||||
|
|
||||||
const colors: ColorValue[] = ["white", "red", "green", "blue", "black"];
|
const colors: ColorValue[] = ["white", "red", "green", "blue", "black"];
|
||||||
const defaults = [100, 50, 50, 50, 50];
|
|
||||||
|
|
||||||
const ChipInputModal = ({
|
const ChipInputModal = ({
|
||||||
showModal,
|
showModal,
|
||||||
@ -30,11 +29,12 @@ const ChipInputModal = ({
|
|||||||
const color: ColorValue = useMemo(() => showModal[1], [showModal]);
|
const color: ColorValue = useMemo(() => showModal[1], [showModal]);
|
||||||
const colorIdx = useMemo(() => colors.indexOf(color), [color]);
|
const colorIdx = useMemo(() => colors.indexOf(color), [color]);
|
||||||
|
|
||||||
const [value, setValue] = useState<number | undefined>();
|
const [value, setValue] = useState<number | undefined>(); // value may be undefined initially
|
||||||
|
|
||||||
|
// Reset the color value when the specific color this modal is for, changes. The same modal is shared/reused in all cases.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue(totalChipsCount[colorIdx]);
|
setValue(totalChipsCount[colorIdx]);
|
||||||
}, [colorIdx, totalChipsCount]);
|
}, [colorIdx]);
|
||||||
|
|
||||||
const shadow = useMemo(() => color === "white", [color]);
|
const shadow = useMemo(() => color === "white", [color]);
|
||||||
|
|
||||||
@ -126,12 +126,12 @@ const ChipsSelector = ({
|
|||||||
false,
|
false,
|
||||||
colors[0],
|
colors[0],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const colorsUsed = useMemo(
|
const colorsUsed = useMemo(
|
||||||
() => colors.slice(0, numberOfChips),
|
() => colors.filter((v, i) => i < numberOfChips),
|
||||||
[numberOfChips]
|
[numberOfChips]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Callback for ChipInputModal to update the chips in the parent's state.
|
||||||
const update = useCallback(
|
const update = useCallback(
|
||||||
(color: ColorValue, count: number) => {
|
(color: ColorValue, count: number) => {
|
||||||
const newTotalChipsCount = totalChipsCount.slice();
|
const newTotalChipsCount = totalChipsCount.slice();
|
||||||
@ -139,18 +139,20 @@ const ChipsSelector = ({
|
|||||||
newTotalChipsCount[colorIndex] = count;
|
newTotalChipsCount[colorIndex] = count;
|
||||||
setTotalChipsCount(newTotalChipsCount);
|
setTotalChipsCount(newTotalChipsCount);
|
||||||
},
|
},
|
||||||
[totalChipsCount, setTotalChipsCount]
|
[numberOfChips, totalChipsCount, setTotalChipsCount]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// When the number of chips changes (dec or inc), update the array being careful to add in sensible default values where they belong
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (numberOfChips !== totalChipsCount.length) {
|
if (numberOfChips !== totalChipsCount.length) {
|
||||||
let newTotalChipsCount = totalChipsCount.slice();
|
let newTotalChipsCount = totalChipsCount.slice();
|
||||||
|
|
||||||
if (numberOfChips < totalChipsCount.length) {
|
if (numberOfChips < totalChipsCount.length) {
|
||||||
newTotalChipsCount = newTotalChipsCount.slice(0, numberOfChips);
|
newTotalChipsCount = newTotalChipsCount.slice(0, numberOfChips);
|
||||||
} else if (numberOfChips > totalChipsCount.length) {
|
} else if (numberOfChips > totalChipsCount.length) {
|
||||||
for (let colorIndex = 0; colorIndex < numberOfChips; ++colorIndex) {
|
for (let colorIndex = 0; colorIndex < numberOfChips; ++colorIndex) {
|
||||||
if (colorIndex >= newTotalChipsCount.length) {
|
if (colorIndex >= newTotalChipsCount.length) {
|
||||||
const defaultTotal = defaults[colorIndex];
|
const defaultTotal = 100 - colorIndex * 20;
|
||||||
newTotalChipsCount.push(defaultTotal);
|
newTotalChipsCount.push(defaultTotal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,27 +168,24 @@ const ChipsSelector = ({
|
|||||||
onPress={() => {
|
onPress={() => {
|
||||||
setNumberOfChips(Math.max(1, numberOfChips - 1));
|
setNumberOfChips(Math.max(1, numberOfChips - 1));
|
||||||
}}
|
}}
|
||||||
disabled={numberOfChips === 1}
|
disabled={numberOfChips == 1}
|
||||||
/>
|
/>
|
||||||
<View style={[styles.container, { flexDirection: "row" }]}>
|
<View style={[styles.container, { flexDirection: "row" }]}>
|
||||||
{colorsUsed.map((color) => {
|
{colorsUsed.map((color) => (
|
||||||
const chipCount = totalChipsCount[colors.indexOf(color)] ?? 0;
|
<Chip
|
||||||
return (
|
key={color.toString()}
|
||||||
<Chip
|
color={color}
|
||||||
key={color.toString()}
|
count={totalChipsCount[colors.indexOf(color)] ?? 0}
|
||||||
color={color}
|
setShowModal={setShowModal}
|
||||||
count={chipCount}
|
/>
|
||||||
setShowModal={setShowModal}
|
))}
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
</View>
|
||||||
<Button
|
<Button
|
||||||
title="+"
|
title="+"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
setNumberOfChips(Math.min(5, numberOfChips + 1));
|
setNumberOfChips(Math.min(5, numberOfChips + 1));
|
||||||
}}
|
}}
|
||||||
disabled={numberOfChips === 5}
|
disabled={numberOfChips == 5}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ChipInputModal
|
<ChipInputModal
|
||||||
@ -199,4 +198,35 @@ const ChipsSelector = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const styles1 = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
marginBottom: 20,
|
||||||
|
gap: 10,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontWeight: "bold",
|
||||||
|
margin: "auto",
|
||||||
|
fontSize: 18,
|
||||||
|
},
|
||||||
|
chipContainer: {
|
||||||
|
padding: 20,
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-evenly",
|
||||||
|
backgroundColor: "#bbb",
|
||||||
|
},
|
||||||
|
chip: {
|
||||||
|
textAlign: "center",
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: "bold",
|
||||||
|
},
|
||||||
|
buttonContainer: {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "space-evenly",
|
||||||
|
},
|
||||||
|
button: {},
|
||||||
|
});
|
||||||
|
|
||||||
export default ChipsSelector;
|
export default ChipsSelector;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { Picker } from "@react-native-picker/picker";
|
||||||
|
import styles from "@/styles/styles";
|
||||||
import i18n from "@/i18n/i18n";
|
import i18n from "@/i18n/i18n";
|
||||||
import { Picker, PickerItem } from "@/containers/Picker";
|
|
||||||
|
|
||||||
interface CurrencySelectorProps {
|
interface CurrencySelectorProps {
|
||||||
selectedCurrency: string;
|
selectedCurrency: string;
|
||||||
@ -15,13 +16,14 @@ const CurrencySelector: React.FC<CurrencySelectorProps> = ({
|
|||||||
<>
|
<>
|
||||||
<Picker
|
<Picker
|
||||||
selectedValue={selectedCurrency}
|
selectedValue={selectedCurrency}
|
||||||
onValueChange={(itemValue) => setSelectedCurrency(itemValue.toString())}
|
onValueChange={(itemValue) => setSelectedCurrency(itemValue)}
|
||||||
|
style={styles.picker}
|
||||||
testID="currency-picker" // ✅ Add testID here
|
testID="currency-picker" // ✅ Add testID here
|
||||||
>
|
>
|
||||||
<PickerItem label={i18n.t("usd")} value="$" />
|
<Picker.Item label={i18n.t("usd")} value="$" />
|
||||||
<PickerItem label={i18n.t("euro")} value="€" />
|
<Picker.Item label={i18n.t("euro")} value="€" />
|
||||||
<PickerItem label={i18n.t("pound")} value="£" />
|
<Picker.Item label={i18n.t("pound")} value="£" />
|
||||||
<PickerItem label={i18n.t("inr")} value="₹" />
|
<Picker.Item label={i18n.t("inr")} value="₹" />
|
||||||
</Picker>
|
</Picker>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
import React, { useMemo } from "react";
|
import React from "react";
|
||||||
import { View, Text, useColorScheme } from "react-native";
|
import { View, Text } from "react-native";
|
||||||
import Button from "@/containers/Button";
|
import Button from "@/containers/Button";
|
||||||
import styles, { COLORS } from "@/styles/styles";
|
import styles from "@/styles/styles";
|
||||||
|
|
||||||
interface PlayerSelectorProps {
|
interface PlayerSelectorProps {
|
||||||
playerCount: number;
|
playerCount: number;
|
||||||
setPlayerCount: React.Dispatch<React.SetStateAction<number>>;
|
setPlayerCount: React.Dispatch<React.SetStateAction<number>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MIN = 2;
|
const MIN = 2;
|
||||||
const MAX = 8;
|
const MAX = 8;
|
||||||
|
|
||||||
const PlayerSelector: React.FC<PlayerSelectorProps> = ({
|
const PlayerSelector: React.FC<PlayerSelectorProps> = ({
|
||||||
playerCount,
|
playerCount,
|
||||||
setPlayerCount,
|
setPlayerCount,
|
||||||
@ -22,27 +20,21 @@ const PlayerSelector: React.FC<PlayerSelectorProps> = ({
|
|||||||
const decreasePlayers = () => {
|
const decreasePlayers = () => {
|
||||||
if (playerCount > MIN) setPlayerCount(playerCount - 1);
|
if (playerCount > MIN) setPlayerCount(playerCount - 1);
|
||||||
};
|
};
|
||||||
const colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
|
<>
|
||||||
<Button
|
<Button
|
||||||
title="-"
|
title="-"
|
||||||
onPress={decreasePlayers}
|
onPress={decreasePlayers}
|
||||||
disabled={playerCount <= MIN}
|
disabled={playerCount <= MIN}
|
||||||
/>
|
/>
|
||||||
<Text style={[styles.h1, { color: colors.TEXT }]}>{playerCount}</Text>
|
<Text style={styles.h1}>{playerCount}</Text>
|
||||||
<Button
|
<Button
|
||||||
title="+"
|
title="+"
|
||||||
onPress={increasePlayers}
|
onPress={increasePlayers}
|
||||||
disabled={playerCount >= MAX}
|
disabled={playerCount >= MAX}
|
||||||
/>
|
/>
|
||||||
</View>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,9 +39,7 @@ describe("BuyInSelector Component", () => {
|
|||||||
expect(getByText("$ 10")).toBeTruthy();
|
expect(getByText("$ 10")).toBeTruthy();
|
||||||
expect(getByText("$ 25")).toBeTruthy();
|
expect(getByText("$ 25")).toBeTruthy();
|
||||||
expect(getByText("$ 50")).toBeTruthy();
|
expect(getByText("$ 50")).toBeTruthy();
|
||||||
expect(
|
expect(getByPlaceholderText("Enter custom buy-in")).toBeTruthy();
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200")
|
|
||||||
).toBeTruthy();
|
|
||||||
expect(queryByText(/Selected Buy-in:.*None/i)).toBeTruthy();
|
expect(queryByText(/Selected Buy-in:.*None/i)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -55,36 +53,24 @@ describe("BuyInSelector Component", () => {
|
|||||||
it("sets a custom buy-in amount correctly", () => {
|
it("sets a custom buy-in amount correctly", () => {
|
||||||
const { getByPlaceholderText } = renderComponent();
|
const { getByPlaceholderText } = renderComponent();
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "100");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
|
||||||
"100"
|
|
||||||
);
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(100);
|
expect(setBuyInAmount).toHaveBeenCalledWith(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("bound and validate custom amount if invalid input is entered", () => {
|
it("resets custom amount if invalid input is entered", () => {
|
||||||
const { getByPlaceholderText } = renderComponent();
|
const { getByPlaceholderText } = renderComponent();
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "-10");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
expect(setBuyInAmount).toHaveBeenCalledWith(25); // Default reset
|
||||||
"-10"
|
|
||||||
);
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(1); // Min value
|
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "abc");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
expect(setBuyInAmount).toHaveBeenCalledWith(25);
|
||||||
"abc"
|
|
||||||
);
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clears the custom amount when selecting a predefined option", () => {
|
it("clears the custom amount when selecting a predefined option", () => {
|
||||||
const { getByPlaceholderText, getByText } = renderComponent();
|
const { getByPlaceholderText, getByText } = renderComponent();
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "100");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
|
||||||
"100"
|
|
||||||
);
|
|
||||||
fireEvent.press(getByText("$ 50"));
|
fireEvent.press(getByText("$ 50"));
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(50);
|
expect(setBuyInAmount).toHaveBeenCalledWith(50);
|
||||||
});
|
});
|
||||||
@ -92,22 +78,13 @@ describe("BuyInSelector Component", () => {
|
|||||||
it("handles valid and invalid input for custom amount correctly", () => {
|
it("handles valid and invalid input for custom amount correctly", () => {
|
||||||
const { getByPlaceholderText } = renderComponent();
|
const { getByPlaceholderText } = renderComponent();
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "75");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
|
||||||
"75"
|
|
||||||
);
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(75);
|
expect(setBuyInAmount).toHaveBeenCalledWith(75);
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "-5");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
expect(setBuyInAmount).toHaveBeenCalledWith(25);
|
||||||
"-5"
|
|
||||||
);
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(1);
|
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "abc");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
|
||||||
"abc"
|
|
||||||
);
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(25);
|
expect(setBuyInAmount).toHaveBeenCalledWith(25);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -121,7 +98,7 @@ describe("BuyInSelector Component", () => {
|
|||||||
|
|
||||||
it("resets to default buy-in when custom input is cleared", () => {
|
it("resets to default buy-in when custom input is cleared", () => {
|
||||||
const { getByPlaceholderText } = renderComponent();
|
const { getByPlaceholderText } = renderComponent();
|
||||||
const input = getByPlaceholderText("Or, enter a custom amount: 1 - 200");
|
const input = getByPlaceholderText("Enter custom buy-in");
|
||||||
|
|
||||||
fireEvent.changeText(input, "75");
|
fireEvent.changeText(input, "75");
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(75);
|
expect(setBuyInAmount).toHaveBeenCalledWith(75);
|
||||||
@ -133,10 +110,7 @@ describe("BuyInSelector Component", () => {
|
|||||||
it("updates state correctly when selecting predefined buy-in after entering a custom amount", () => {
|
it("updates state correctly when selecting predefined buy-in after entering a custom amount", () => {
|
||||||
const { getByPlaceholderText, getByText } = renderComponent();
|
const { getByPlaceholderText, getByText } = renderComponent();
|
||||||
|
|
||||||
fireEvent.changeText(
|
fireEvent.changeText(getByPlaceholderText("Enter custom buy-in"), "200");
|
||||||
getByPlaceholderText("Or, enter a custom amount: 1 - 200"),
|
|
||||||
"200"
|
|
||||||
);
|
|
||||||
expect(setBuyInAmount).toHaveBeenCalledWith(200);
|
expect(setBuyInAmount).toHaveBeenCalledWith(200);
|
||||||
|
|
||||||
fireEvent.press(getByText("$ 10"));
|
fireEvent.press(getByText("$ 10"));
|
||||||
|
@ -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 "@/util/CalculatorState";
|
import { saveState, loadState, PokerState } from "../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.ts", () => {
|
describe("CalculatorState.tsx", () => {
|
||||||
const mockState: PokerState = {
|
const mockState: PokerState = {
|
||||||
playerCount: 4,
|
playerCount: 4,
|
||||||
buyInAmount: 50,
|
buyInAmount: 50,
|
@ -40,7 +40,7 @@ describe("ChipDetection", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks(); // Reset all mocks to prevent test contamination
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders correctly", () => {
|
it("renders correctly", () => {
|
||||||
@ -83,11 +83,7 @@ describe("ChipDetection", () => {
|
|||||||
fireEvent.press(getByText(/take a photo/i));
|
fireEvent.press(getByText(/take a photo/i));
|
||||||
|
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
expect(mockUpdateChipCount).toHaveBeenCalledWith({
|
expect(mockUpdateChipCount).toHaveBeenCalledWith({ red: 5, green: 3 })
|
||||||
red: 5,
|
|
||||||
green: 3,
|
|
||||||
blue: 0,
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -148,7 +144,7 @@ describe("ChipDetection", () => {
|
|||||||
choices: [
|
choices: [
|
||||||
{
|
{
|
||||||
message: {
|
message: {
|
||||||
content: JSON.stringify({ red: 5, green: 3, blue: 0 }),
|
content: JSON.stringify({ red: 5, green: 3 }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -167,7 +163,6 @@ describe("ChipDetection", () => {
|
|||||||
expect(mockUpdateChipCount).toHaveBeenCalledWith({
|
expect(mockUpdateChipCount).toHaveBeenCalledWith({
|
||||||
red: 5,
|
red: 5,
|
||||||
green: 3,
|
green: 3,
|
||||||
blue: 0,
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Alert } from "react-native";
|
import { render } from "@testing-library/react-native";
|
||||||
|
|
||||||
import { fireEvent, render } from "@testing-library/react-native";
|
|
||||||
import ChipDistributionSummary from "../ChipDistributionSummary";
|
import ChipDistributionSummary from "../ChipDistributionSummary";
|
||||||
|
|
||||||
jest.mock("@expo/vector-icons", () => {
|
|
||||||
const { Text } = require("react-native");
|
|
||||||
return {
|
|
||||||
MaterialIcons: () => <Text>TestIcon</Text>,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("ChipDistributionSummary Component", () => {
|
describe("ChipDistributionSummary Component", () => {
|
||||||
test("renders correctly with valid data", () => {
|
test("renders correctly with valid data", () => {
|
||||||
const playerCount = 4;
|
const playerCount = 4;
|
||||||
const totalChipsCount = [100, 80, 60, 40, 20];
|
const totalChipsCount = [100, 80, 60, 40, 20];
|
||||||
const buyInAmount = 20;
|
const buyInAmount = 20;
|
||||||
const expectedDistribution = [16, 12, 8, 6, 2];
|
const expectedDistribution = [2, 2, 1, 2, 2];
|
||||||
const expectedDenominations = [0.05, 0.1, 0.25, 1, 5];
|
const expectedDenominations = [0.5, 1, 2, 2.5, 5];
|
||||||
|
|
||||||
const { getByText } = render(
|
const { getByText } = render(
|
||||||
<ChipDistributionSummary
|
<ChipDistributionSummary
|
||||||
@ -37,23 +28,46 @@ describe("ChipDistributionSummary Component", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("renders warning message when needed", async () => {
|
test.skip("renders fallback message when no valid distribution", () => {
|
||||||
const { getByText } = render(
|
const { getByText } = render(
|
||||||
<ChipDistributionSummary
|
<ChipDistributionSummary
|
||||||
playerCount={6}
|
playerCount={0}
|
||||||
buyInAmount={25}
|
buyInAmount={20}
|
||||||
selectedCurrency={"$"}
|
selectedCurrency={"$"}
|
||||||
totalChipsCount={[100, 50]}
|
totalChipsCount={[]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const warning = getByText("TestIcon");
|
expect(getByText("No valid distribution calculated yet.")).toBeTruthy();
|
||||||
expect(warning).toBeTruthy();
|
});
|
||||||
|
|
||||||
jest.spyOn(Alert, "alert");
|
test.skip("scales down chips if exceeding MAX_CHIPS", () => {
|
||||||
fireEvent.press(warning);
|
const playerCount = 2;
|
||||||
expect(Alert.alert).toHaveBeenCalledWith(
|
let totalChipsCount = [300, 400, 500, 600, 700];
|
||||||
"Warning",
|
const MAX_CHIPS = 500;
|
||||||
`Be advised that the value of the distributed chips does not equal the buy-in for these inputs.\n\nHowever, results shown are fair to all players`
|
const totalChips = totalChipsCount.reduce((sum, count) => sum + count, 0);
|
||||||
|
|
||||||
|
if (totalChips > MAX_CHIPS) {
|
||||||
|
const scaleFactor = MAX_CHIPS / totalChips;
|
||||||
|
totalChipsCount = totalChipsCount.map((count) =>
|
||||||
|
Math.round(count * scaleFactor)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const expectedDistribution = [30, 40, 50, 60, 70]; // Adjust as per actual component calculations
|
||||||
|
|
||||||
|
const { getByText } = render(
|
||||||
|
<ChipDistributionSummary
|
||||||
|
playerCount={playerCount}
|
||||||
|
buyInAmount={100}
|
||||||
|
totalChipsCount={totalChipsCount}
|
||||||
|
selectedCurrency={"$"}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expect(getByText("Distribution & Denomination")).toBeTruthy();
|
||||||
|
|
||||||
|
expectedDistribution.forEach((count) => {
|
||||||
|
expect(getByText(new RegExp(`^${count}\\s+chips:`, "i"))).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,9 @@ import {
|
|||||||
userEvent,
|
userEvent,
|
||||||
render,
|
render,
|
||||||
screen,
|
screen,
|
||||||
|
waitForElementToBeRemoved,
|
||||||
fireEvent,
|
fireEvent,
|
||||||
|
act,
|
||||||
} from "@testing-library/react-native";
|
} from "@testing-library/react-native";
|
||||||
import ChipsSelector from "@/components/ChipsSelector";
|
import ChipsSelector from "@/components/ChipsSelector";
|
||||||
|
|
||||||
@ -80,16 +82,27 @@ describe("tests for ChipsSelector", () => {
|
|||||||
TOTAL_CHIPS_COUNT[4],
|
TOTAL_CHIPS_COUNT[4],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
// skip: There is a jest/DOM issue with the button interaction, despite working correctly in-app. Documented to resolve.
|
||||||
it("test dec/inc buttons", async () => {
|
it.skip("test dec/inc buttons", async () => {
|
||||||
rend();
|
rend();
|
||||||
|
|
||||||
|
const blue = screen.getByText(TOTAL_CHIPS_COUNT[3].toString());
|
||||||
|
const black = screen.getByText(TOTAL_CHIPS_COUNT[4].toString());
|
||||||
const decrement = screen.getByRole("button", { name: /-/i });
|
const decrement = screen.getByRole("button", { name: /-/i });
|
||||||
const increment = screen.getByRole("button", { name: /\+/i });
|
const increment = screen.getByRole("button", { name: /\+/i });
|
||||||
|
|
||||||
fireEvent.press(decrement);
|
fireEvent.press(decrement);
|
||||||
expect(mockSetNumberOfChips).toHaveBeenCalledWith(4);
|
fireEvent.press(decrement);
|
||||||
|
|
||||||
|
// Test that elements are removed after fireEvent
|
||||||
|
await waitForElementToBeRemoved(() => blue);
|
||||||
|
await waitForElementToBeRemoved(() => black);
|
||||||
|
|
||||||
fireEvent.press(increment);
|
fireEvent.press(increment);
|
||||||
expect(mockSetNumberOfChips).toHaveBeenCalledWith(4);
|
fireEvent.press(increment);
|
||||||
|
|
||||||
|
// Test that new elements re-appear, correctly
|
||||||
|
const blue1 = screen.getByText(TOTAL_CHIPS_COUNT[3].toString());
|
||||||
|
const black1 = screen.getByText(TOTAL_CHIPS_COUNT[4].toString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,14 +3,14 @@ import {
|
|||||||
savePersistentState,
|
savePersistentState,
|
||||||
loadPersistentState,
|
loadPersistentState,
|
||||||
PokerState,
|
PokerState,
|
||||||
} from "@/util/PersistentState";
|
} from "../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.ts", () => {
|
describe("PersistentState.tsx", () => {
|
||||||
const mockState: PokerState = {
|
const mockState: PokerState = {
|
||||||
playerCount: 4,
|
playerCount: 4,
|
||||||
buyInAmount: 50,
|
buyInAmount: 50,
|
@ -1,82 +1,9 @@
|
|||||||
|
import { ButtonProps, Button } from "react-native";
|
||||||
import { COLORS } from "@/styles/styles";
|
import { COLORS } from "@/styles/styles";
|
||||||
import React, { useMemo } from "react";
|
|
||||||
import {
|
|
||||||
Text,
|
|
||||||
TouchableOpacity,
|
|
||||||
StyleSheet,
|
|
||||||
useColorScheme,
|
|
||||||
} from "react-native";
|
|
||||||
|
|
||||||
interface ButtonProps {
|
// More styling can be done, or swap this out with more flexible component like a TouchableOpacity if needed
|
||||||
title: string;
|
const AppButton = (props: ButtonProps) => (
|
||||||
onPress: () => void;
|
<Button color={COLORS.PRIMARY} {...props} />
|
||||||
disabled?: boolean;
|
);
|
||||||
size?: "normal" | "small";
|
|
||||||
}
|
|
||||||
|
|
||||||
const Button: React.FC<ButtonProps> = ({
|
export default AppButton;
|
||||||
title,
|
|
||||||
onPress,
|
|
||||||
disabled,
|
|
||||||
size = "normal",
|
|
||||||
}) => {
|
|
||||||
const colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={onPress}
|
|
||||||
disabled={disabled}
|
|
||||||
accessibilityRole="button"
|
|
||||||
style={[
|
|
||||||
size == "normal" ? styles.button : styles.buttonSmall,
|
|
||||||
{ backgroundColor: colors.PRIMARY },
|
|
||||||
disabled && styles.disabled,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Text
|
|
||||||
style={[
|
|
||||||
size == "normal" ? styles.buttonText : styles.buttonTextSmall,
|
|
||||||
{ color: colors.TEXT },
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
button: {
|
|
||||||
paddingVertical: 10,
|
|
||||||
paddingHorizontal: 20,
|
|
||||||
borderRadius: 8,
|
|
||||||
marginHorizontal: 5,
|
|
||||||
marginVertical: 5,
|
|
||||||
},
|
|
||||||
buttonText: {
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: "bold",
|
|
||||||
textAlign: "center",
|
|
||||||
},
|
|
||||||
buttonSmall: {
|
|
||||||
paddingVertical: 5,
|
|
||||||
paddingHorizontal: 10,
|
|
||||||
borderRadius: 8,
|
|
||||||
marginHorizontal: 2,
|
|
||||||
marginVertical: 2,
|
|
||||||
},
|
|
||||||
buttonTextSmall: {
|
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: "bold",
|
|
||||||
textAlign: "center",
|
|
||||||
},
|
|
||||||
disabled: {
|
|
||||||
opacity: 0.5,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Button;
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
import styles, { COLORS } from "@/styles/styles";
|
|
||||||
import { PickerItemProps, PickerProps } from "@react-native-picker/picker";
|
|
||||||
import { useMemo } from "react";
|
|
||||||
import { useColorScheme, View } from "react-native";
|
|
||||||
import { Picker as RNPicker } from "@react-native-picker/picker";
|
|
||||||
|
|
||||||
export const PickerItem: React.FC<PickerItemProps> = (props) => {
|
|
||||||
const colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<RNPicker.Item
|
|
||||||
style={[
|
|
||||||
styles.pickerItem,
|
|
||||||
{ color: colors.TEXT, backgroundColor: colors.PRIMARY },
|
|
||||||
]}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Picker: React.FC<PickerProps> = (props) => {
|
|
||||||
const colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={styles.pickerWrapper}>
|
|
||||||
<RNPicker
|
|
||||||
style={[
|
|
||||||
styles.picker,
|
|
||||||
{
|
|
||||||
color: colors.TEXT,
|
|
||||||
backgroundColor: colors.PRIMARY,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
dropdownIconColor={colors.TEXT}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
@ -1,7 +1,7 @@
|
|||||||
import { View, Text, StyleSheet, useColorScheme } from "react-native";
|
import { View, Text, StyleSheet } from "react-native";
|
||||||
import React, { useMemo } from "react";
|
import React from "react";
|
||||||
import { MaterialIcons } from "@expo/vector-icons";
|
import { MaterialIcons } from "@expo/vector-icons";
|
||||||
import globalStyles, { COLORS } from "@/styles/styles";
|
import globalStyles from "@/styles/styles";
|
||||||
|
|
||||||
const titleCase = (input: string) =>
|
const titleCase = (input: string) =>
|
||||||
input
|
input
|
||||||
@ -23,12 +23,6 @@ const Section = ({
|
|||||||
orientation?: "row" | "column";
|
orientation?: "row" | "column";
|
||||||
contentStyle?: object;
|
contentStyle?: object;
|
||||||
}) => {
|
}) => {
|
||||||
const colorScheme = useColorScheme();
|
|
||||||
const darkMode = useMemo(() => colorScheme === "dark", [colorScheme]);
|
|
||||||
const colors = useMemo(
|
|
||||||
() => (darkMode ? COLORS.DARK : COLORS.LIGHT),
|
|
||||||
[darkMode]
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<View style={styles.header}>
|
<View style={styles.header}>
|
||||||
@ -36,11 +30,9 @@ const Section = ({
|
|||||||
style={styles.icon}
|
style={styles.icon}
|
||||||
name={iconName}
|
name={iconName}
|
||||||
size={30}
|
size={30}
|
||||||
color={colors.TEXT}
|
color={"black"}
|
||||||
/>
|
/>
|
||||||
<Text style={[styles.title, { color: colors.TEXT }]}>
|
<Text style={styles.title}>{titleCase(title)}</Text>
|
||||||
{titleCase(title)}
|
|
||||||
</Text>
|
|
||||||
</View>
|
</View>
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
|
10
i18n/en.json
10
i18n/en.json
@ -8,7 +8,8 @@
|
|||||||
"inr": "INR (₹)",
|
"inr": "INR (₹)",
|
||||||
"select_number_of_players": "Select the Number of Players:",
|
"select_number_of_players": "Select the Number of Players:",
|
||||||
"select_buyin_amount": "Select Buy-in Amount:",
|
"select_buyin_amount": "Select Buy-in Amount:",
|
||||||
"custom_buy_in": "Or, enter a custom amount:",
|
"custom_buy_in": "Or enter a custom amount:",
|
||||||
|
"enter_custom_buy_in": "Enter custom buy-in",
|
||||||
"selected_buy_in": "Selected Buy-in:",
|
"selected_buy_in": "Selected Buy-in:",
|
||||||
"none": "None",
|
"none": "None",
|
||||||
"pick_an_image": "Pick an image",
|
"pick_an_image": "Pick an image",
|
||||||
@ -36,7 +37,6 @@
|
|||||||
"failed_to_save_state": "Failed to save state.",
|
"failed_to_save_state": "Failed to save state.",
|
||||||
"state_loaded_from": "State loaded from",
|
"state_loaded_from": "State loaded from",
|
||||||
"info": "Info",
|
"info": "Info",
|
||||||
"warning": "Warning",
|
|
||||||
"no_saved_state_found": "No saved state found.",
|
"no_saved_state_found": "No saved state found.",
|
||||||
"automatic_chip_detection": "Automatic Chip Detection",
|
"automatic_chip_detection": "Automatic Chip Detection",
|
||||||
"manual_chip_adjustment": "Manual Chip Adjustment",
|
"manual_chip_adjustment": "Manual Chip Adjustment",
|
||||||
@ -45,10 +45,6 @@
|
|||||||
"save_slot_2": "Save\nSlot 2",
|
"save_slot_2": "Save\nSlot 2",
|
||||||
"load_slot_1": "Load\nSlot 1",
|
"load_slot_1": "Load\nSlot 1",
|
||||||
"load_slot_2": "Load\nSlot 2",
|
"load_slot_2": "Load\nSlot 2",
|
||||||
"please_select_valid_buyin": "Please select a valid buy-in amount",
|
"please_select_valid_buyin": "Please select a valid buy-in amount"
|
||||||
"chip_value_warn": "Be advised that the value of the distributed chips does not equal the buy-in for these inputs.\n\nHowever, results shown are fair to all players",
|
|
||||||
"appearance": "Appearance",
|
|
||||||
"switch_to_dark_mode": "Switch to Dark Mode",
|
|
||||||
"switch_to_light_mode": "Switch to Light Mode"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
i18n/es.json
10
i18n/es.json
@ -8,7 +8,8 @@
|
|||||||
"inr": "INR (₹)",
|
"inr": "INR (₹)",
|
||||||
"select_number_of_players": "Seleccionar número de jugadores:",
|
"select_number_of_players": "Seleccionar número de jugadores:",
|
||||||
"select_buyin_amount": "Seleccionar cantidad de buy-in:",
|
"select_buyin_amount": "Seleccionar cantidad de buy-in:",
|
||||||
"custom_buy_in": "O, ingresa una cantidad personalizada:",
|
"custom_buy_in": "O ingresa una cantidad personalizada:",
|
||||||
|
"enter_custom_buy_in": "Ingresar buy-in personalizado",
|
||||||
"selected_buy_in": "Buy-in seleccionado:",
|
"selected_buy_in": "Buy-in seleccionado:",
|
||||||
"none": "Ninguno",
|
"none": "Ninguno",
|
||||||
"pick_an_image": "Elige una imagen",
|
"pick_an_image": "Elige una imagen",
|
||||||
@ -37,7 +38,6 @@
|
|||||||
"failed_to_save_state": "No se pudo guardar el estado.",
|
"failed_to_save_state": "No se pudo guardar el estado.",
|
||||||
"state_loaded_from": "Estado cargado desde",
|
"state_loaded_from": "Estado cargado desde",
|
||||||
"info": "Información",
|
"info": "Información",
|
||||||
"warning": "Advertencia",
|
|
||||||
"no_saved_state_found": "No se encontró estado guardado.",
|
"no_saved_state_found": "No se encontró estado guardado.",
|
||||||
"automatic_chip_detection": "Detección automática de fichas",
|
"automatic_chip_detection": "Detección automática de fichas",
|
||||||
"manual_chip_adjustment": "Ajuste manual de fichas",
|
"manual_chip_adjustment": "Ajuste manual de fichas",
|
||||||
@ -46,10 +46,6 @@
|
|||||||
"save_slot_2": "Guardar\nSlot 2",
|
"save_slot_2": "Guardar\nSlot 2",
|
||||||
"load_slot_1": "Cargar\nSlot 1",
|
"load_slot_1": "Cargar\nSlot 1",
|
||||||
"load_slot_2": "Cargar\nSlot 2",
|
"load_slot_2": "Cargar\nSlot 2",
|
||||||
"please_select_valid_buyin": "Por favor seleccione una cantidad de buy-in válida",
|
"please_select_valid_buyin": "Por favor seleccione una cantidad de buy-in válida"
|
||||||
"chip_value_warn": "Tenga en cuenta que el valor de las fichas distribuidas no es igual al buy-in para estas entradas.\n\nSin embargo, los resultados que se muestran son justos para todos los jugadores.",
|
|
||||||
"appearance": "Apariencia",
|
|
||||||
"switch_to_dark_mode": "Cambiar a Modo Oscuro",
|
|
||||||
"switch_to_light_mode": "Cambiar a Modo Claro"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -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",
|
||||||
|
@ -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,7 +31,6 @@
|
|||||||
"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",
|
||||||
@ -48,7 +47,8 @@
|
|||||||
"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",
|
||||||
|
@ -1,23 +1,16 @@
|
|||||||
import { StyleSheet } from "react-native";
|
import { StyleSheet } from "react-native";
|
||||||
|
|
||||||
export const COLORS = {
|
export const COLORS = {
|
||||||
WARNING: "#c79c28",
|
PRIMARY: "#007bff",
|
||||||
LIGHT: {
|
SECONDARY: "#6c757d",
|
||||||
TEXT: "black",
|
SUCCESS: "#28a745",
|
||||||
PRIMARY: "lightgrey",
|
DANGER: "#dc3545",
|
||||||
SECONDARY: "azure",
|
WARNING: "#ffc107",
|
||||||
BACKGROUND: "ghostwhite",
|
|
||||||
DISABLED: "gray",
|
|
||||||
},
|
|
||||||
DARK: {
|
|
||||||
TEXT: "white",
|
|
||||||
PRIMARY: "black",
|
|
||||||
SECONDARY: "teal",
|
|
||||||
BACKGROUND: "dimgrey",
|
|
||||||
DISABLED: "gray",
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const lightStyles = StyleSheet.create({});
|
||||||
|
const darkStyles = StyleSheet.create({});
|
||||||
|
|
||||||
const GlobalStyles = StyleSheet.create({
|
const GlobalStyles = StyleSheet.create({
|
||||||
scrollView: {},
|
scrollView: {},
|
||||||
scrollViewContent: {
|
scrollViewContent: {
|
||||||
@ -32,7 +25,7 @@ const GlobalStyles = StyleSheet.create({
|
|||||||
gap: 10,
|
gap: 10,
|
||||||
},
|
},
|
||||||
|
|
||||||
h1: { fontSize: 19, fontWeight: "bold" },
|
h1: { fontSize: 20, fontWeight: "bold" },
|
||||||
h2: { fontSize: 18, fontWeight: "normal" },
|
h2: { fontSize: 18, fontWeight: "normal" },
|
||||||
p: {
|
p: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
@ -58,15 +51,9 @@ const GlobalStyles = StyleSheet.create({
|
|||||||
textShadowRadius: 10,
|
textShadowRadius: 10,
|
||||||
},
|
},
|
||||||
picker: {
|
picker: {
|
||||||
borderRadius: 10,
|
height: 50,
|
||||||
height: 55,
|
|
||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
pickerItem: {},
|
|
||||||
pickerWrapper: {
|
|
||||||
borderRadius: 10,
|
|
||||||
overflow: "hidden",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default GlobalStyles;
|
export default GlobalStyles;
|
||||||
|
Loading…
Reference in New Issue
Block a user