mirror of
https://github.com/mudabbir-ahmad/MAD-Treasure-Hunt.git
synced 2026-10-08 03:00:20 +00:00
Add comments for code structure clarity; enhance readability across multiple components
This commit is contained in:
1 parent
d67522a71d
commit
9b9f13eb6a
29 files changed
+391
-217
No files matched your search
@@ -18,9 +18,7 @@ const Stack = createNativeStackNavigator();
|
|||||||
|
|
||||||
const AuthStack = () => (
|
const AuthStack = () => (
|
||||||
<Stack.Navigator
|
<Stack.Navigator
|
||||||
screenOptions={{
|
screenOptions={{headerShown: false}}
|
||||||
headerShown: false,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Stack.Screen name="LoginScreen" component={LoginScreen}/>
|
<Stack.Screen name="LoginScreen" component={LoginScreen}/>
|
||||||
<Stack.Screen name="RegisterScreen" component={RegisterScreen}/>
|
<Stack.Screen name="RegisterScreen" component={RegisterScreen}/>
|
||||||
@@ -29,9 +27,7 @@ const AuthStack = () => (
|
|||||||
|
|
||||||
const GameStack = () => (
|
const GameStack = () => (
|
||||||
<Stack.Navigator
|
<Stack.Navigator
|
||||||
screenOptions={{
|
screenOptions={{headerShown: false}}
|
||||||
headerShown: false,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Stack.Screen name="GameTypeScreen" component={GameTypeScreen}/>
|
<Stack.Screen name="GameTypeScreen" component={GameTypeScreen}/>
|
||||||
<Stack.Screen name="JoinPrivateGameScreen" component={JoinPrivateGameScreen}/>
|
<Stack.Screen name="JoinPrivateGameScreen" component={JoinPrivateGameScreen}/>
|
||||||
@@ -47,9 +43,7 @@ const GameStack = () => (
|
|||||||
|
|
||||||
const AdminStack = () => (
|
const AdminStack = () => (
|
||||||
<Stack.Navigator
|
<Stack.Navigator
|
||||||
screenOptions={{
|
screenOptions={{headerShown: false}}
|
||||||
headerShown: false,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Stack.Screen name="AdminHubScreen" component={AdminHubScreen}/>
|
<Stack.Screen name="AdminHubScreen" component={AdminHubScreen}/>
|
||||||
<Stack.Screen name="ManageSubgroupsScreen" component={ManageSubgroupsScreen}/>
|
<Stack.Screen name="ManageSubgroupsScreen" component={ManageSubgroupsScreen}/>
|
||||||
@@ -65,9 +59,7 @@ export const App = () => {
|
|||||||
return (
|
return (
|
||||||
<NavigationContainer>
|
<NavigationContainer>
|
||||||
<Stack.Navigator
|
<Stack.Navigator
|
||||||
screenOptions={{
|
screenOptions={{headerShown: false}}
|
||||||
headerShown: false,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Stack.Screen name="Auth" component={AuthStack}/>
|
<Stack.Screen name="Auth" component={AuthStack}/>
|
||||||
<Stack.Screen name="Game" component={GameStack}/>
|
<Stack.Screen name="Game" component={GameStack}/>
|
||||||
@@ -78,4 +70,3 @@ export const App = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
||||||
@@ -3,10 +3,7 @@
|
|||||||
"main": "node_modules/expo/AppEntry.js",
|
"main": "node_modules/expo/AppEntry.js",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"api": "node server/server.js",
|
|
||||||
"api:standalone": "npm --prefix server start",
|
|
||||||
"start": "expo start",
|
"start": "expo start",
|
||||||
"start:api": "npm run api",
|
|
||||||
"android": "expo run:android",
|
"android": "expo run:android",
|
||||||
"ios": "expo run:ios",
|
"ios": "expo run:ios",
|
||||||
"web": "expo start --web",
|
"web": "expo start --web",
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
const API = {};
|
||||||
|
|
||||||
|
API.get = (endpoint) => callFetch(endpoint, 'GET');
|
||||||
|
API.post = (endpoint, data) => callFetch(endpoint, 'POST', data);
|
||||||
|
API.put = (endpoint, data) => callFetch(endpoint, 'PUT', data);
|
||||||
|
API.delete = (endpoint) => callFetch(endpoint, 'DELETE');
|
||||||
|
|
||||||
|
export default API;
|
||||||
|
|
||||||
|
const callFetch = async (endpoint, method, dataObj = null) => {
|
||||||
|
// Build request object
|
||||||
|
let requestObj = {method: method}; // GET, POST, PUT or DELETE
|
||||||
|
if (dataObj)
|
||||||
|
requestObj = {
|
||||||
|
...requestObj,
|
||||||
|
headers: {'Content-type': 'application/json'},
|
||||||
|
body: JSON.stringify(dataObj),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Call the fetch and process the return
|
||||||
|
try {
|
||||||
|
let result = null;
|
||||||
|
const response = await fetch(endpoint, requestObj);
|
||||||
|
if (response.status !== 204) result = await response.json();
|
||||||
|
return response.status >= 200 && response.status < 300
|
||||||
|
? {isSuccess: true, result}
|
||||||
|
: {isSuccess: false, message: `${result.message}`};
|
||||||
|
} catch (error) {
|
||||||
|
return {isSuccess: false, message: error.message};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import {useEffect, useState} from "react";
|
||||||
|
import API from "./API";
|
||||||
|
|
||||||
|
|
||||||
|
const useLoad = (loadEndpoint) => {
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
|
const [records, setRecords] = useState([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
// Loader ----------------------
|
||||||
|
const loadRecords = async (endpoint) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
const response = await API.get(endpoint);
|
||||||
|
if (response.isSuccess) setRecords(response.result);
|
||||||
|
setIsLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadRecords(loadEndpoint);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// return ----------------------
|
||||||
|
|
||||||
|
return [records, setRecords, isLoading, loadRecords];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useLoad;
|
||||||
|
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
import {Pressable, StyleSheet, Text, View} from "react-native";
|
import {Pressable, StyleSheet, Text, View} from "react-native";
|
||||||
|
|
||||||
export const Button = ({ label, icon, onClick, styleLabel, styleButton }) => {
|
export const Button = ({ label, icon, onClick, styleLabel, styleButton }) => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Pressable onPress={onClick} style={[styles.button, styleButton]}>
|
<Pressable onPress={onClick} style={[styles.button, styleButton]}>
|
||||||
{icon ? icon : null}
|
{icon ? icon : null}
|
||||||
@@ -10,6 +15,11 @@ export const Button = ({ label, icon, onClick, styleLabel, styleButton }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ButtonTray = ({ children }) => {
|
export const ButtonTray = ({ children }) => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return <View style={styles.buttonTray}>{children}</View>;
|
return <View style={styles.buttonTray}>{children}</View>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ import React from 'react';
|
|||||||
import MapView, {Circle, Marker} from 'react-native-maps';
|
import MapView, {Circle, Marker} from 'react-native-maps';
|
||||||
|
|
||||||
const AdminCacheEditorView = ({ userLocation, caches, onAddCache, onMoveCache }) => {
|
const AdminCacheEditorView = ({ userLocation, caches, onAddCache, onMoveCache }) => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
if (!userLocation) {
|
if (!userLocation) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,13 @@ import React, {useEffect, useState} from 'react';
|
|||||||
import {StyleSheet, Text, View} from 'react-native';
|
import {StyleSheet, Text, View} from 'react-native';
|
||||||
|
|
||||||
const ClaimTimerView = ({ cache, onClaimSuccess, isClaiming }) => {
|
const ClaimTimerView = ({ cache, onClaimSuccess, isClaiming }) => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [timeLeft, setTimeLeft] = useState(5);
|
const [timeLeft, setTimeLeft] = useState(5);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let timer;
|
let timer;
|
||||||
if (isClaiming && timeLeft > 0) {
|
if (isClaiming && timeLeft > 0) {
|
||||||
@@ -16,6 +21,8 @@ const ClaimTimerView = ({ cache, onClaimSuccess, isClaiming }) => {
|
|||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [isClaiming, timeLeft, cache, onClaimSuccess]);
|
}, [isClaiming, timeLeft, cache, onClaimSuccess]);
|
||||||
|
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
if (!isClaiming) {
|
if (!isClaiming) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -45,4 +52,3 @@ const styles = StyleSheet.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default ClaimTimerView;
|
export default ClaimTimerView;
|
||||||
|
|
||||||
@@ -3,9 +3,12 @@ import MapView, {Circle} from 'react-native-maps';
|
|||||||
import ClaimTimerView from './ClaimTimerView';
|
import ClaimTimerView from './ClaimTimerView';
|
||||||
|
|
||||||
const PlayerMapView = ({ userLocation, visibleCache, isClaiming, onClaimSuccess }) => {
|
const PlayerMapView = ({ userLocation, visibleCache, isClaiming, onClaimSuccess }) => {
|
||||||
if (!userLocation) {
|
// Initialisation -------------
|
||||||
return null;
|
// State ----------------------
|
||||||
}
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
if (!userLocation) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import {Pressable, StyleSheet, Text, View} from 'react-native';
|
import {Pressable, StyleSheet, Text, View} from 'react-native';
|
||||||
|
|
||||||
const BottomNavbar = ({ navigation, routeName }) => {
|
const BottomNavbar = ({ navigation, routeName }) => {
|
||||||
|
// Initialisation ------------
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{
|
{
|
||||||
label: 'Map',
|
label: 'Map',
|
||||||
@@ -19,6 +21,10 @@ const BottomNavbar = ({ navigation, routeName }) => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
{tabs.map((tab) => {
|
{tabs.map((tab) => {
|
||||||
@@ -71,4 +77,3 @@ const styles = StyleSheet.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default BottomNavbar;
|
export default BottomNavbar;
|
||||||
|
|
||||||
@@ -5,18 +5,18 @@ import TopNavbar from "./TopNavbar";
|
|||||||
import BottomNavbar from "./BottomNavbar";
|
import BottomNavbar from "./BottomNavbar";
|
||||||
|
|
||||||
const Screen = ({ children, style }) => {
|
const Screen = ({ children, style }) => {
|
||||||
|
// Initialisation -------------
|
||||||
|
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const titleMap = {
|
const titleMap = {
|
||||||
LoginScreen: "Login",
|
|
||||||
RegisterScreen: "Register",
|
|
||||||
GameTypeScreen: "Game Type",
|
GameTypeScreen: "Game Type",
|
||||||
JoinPrivateGameScreen: "Join Private Game",
|
JoinPrivateGameScreen: "Join Private Game",
|
||||||
ManagePrivateGameScreen: "Manage Private Game",
|
ManagePrivateGameScreen: "Manage Private Game",
|
||||||
CreateGameScreen: "Create Game",
|
CreateGameScreen: "Create Game",
|
||||||
ManageGameScreen: "Manage Game",
|
ManageGameScreen: "Manage Game",
|
||||||
GameLobbyScreen: "Leaderboard",
|
GameLobbyScreen: "Game Lobby",
|
||||||
LeaderboardScreen: "Leaderboard",
|
LeaderboardScreen: "Leaderboard",
|
||||||
TeamScreen: "Current Team",
|
TeamScreen: "Current Team",
|
||||||
MapScreen: "Map",
|
MapScreen: "Map",
|
||||||
@@ -24,15 +24,21 @@ const Screen = ({ children, style }) => {
|
|||||||
ManageSubgroupsScreen: "Manage Subgroups",
|
ManageSubgroupsScreen: "Manage Subgroups",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const routeName = route.name;
|
const routeName = route.name;
|
||||||
const showBack = routeName !== "LoginScreen" && navigation.canGoBack();
|
const isAuthScreen = routeName === "LoginScreen" || routeName === "RegisterScreen";
|
||||||
|
const showBack = !isAuthScreen && navigation.canGoBack();
|
||||||
const pageTitle = titleMap[routeName] || "Treasure Hunt";
|
const pageTitle = titleMap[routeName] || "Treasure Hunt";
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.screen, style]}>
|
<View style={[styles.screen, style]}>
|
||||||
<TopNavbar title={pageTitle} showBack={showBack} navigation={navigation} />
|
{!isAuthScreen && <TopNavbar title={pageTitle} showBack={showBack} navigation={navigation} />}
|
||||||
<View style={styles.content}>{children}</View>
|
<View style={styles.content}>{children}</View>
|
||||||
<BottomNavbar navigation={navigation} routeName={routeName} />
|
{!isAuthScreen && <BottomNavbar navigation={navigation} routeName={routeName} />}
|
||||||
<StatusBar style="light" />
|
<StatusBar style="light" />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ import {Pressable, StyleSheet, Text, View} from 'react-native';
|
|||||||
import {clearSession} from '../../hooks/SessionStore';
|
import {clearSession} from '../../hooks/SessionStore';
|
||||||
|
|
||||||
const TopNavbar = ({title, showBack, navigation}) => {
|
const TopNavbar = ({title, showBack, navigation}) => {
|
||||||
|
// Initialisation ------------
|
||||||
|
|
||||||
const routeName = navigation.getState()?.routes?.[navigation.getState().index]?.name;
|
const routeName = navigation.getState()?.routes?.[navigation.getState().index]?.name;
|
||||||
const showLogout = routeName !== 'LoginScreen' && routeName !== 'RegisterScreen';
|
const showLogout = routeName !== 'LoginScreen' && routeName !== 'RegisterScreen';
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
if (navigation.canGoBack()) {
|
if (navigation.canGoBack()) navigation.goBack();
|
||||||
navigation.goBack();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
@@ -19,6 +22,8 @@ const TopNavbar = ({ title, showBack, navigation }) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<View style={styles.leftSlot}>
|
<View style={styles.leftSlot}>
|
||||||
@@ -87,4 +92,3 @@ const styles = StyleSheet.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default TopNavbar;
|
export default TopNavbar;
|
||||||
|
|
||||||
@@ -2,12 +2,19 @@ import React from 'react';
|
|||||||
import {StyleSheet, Text} from 'react-native';
|
import {StyleSheet, Text} from 'react-native';
|
||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const AdminHubScreen = () => (
|
const AdminHubScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Admin Hub</Text>
|
<Text style={styles.title}>Admin Hub</Text>
|
||||||
<Text style={styles.body}>Admin hub setup goes here.</Text>
|
<Text style={styles.body}>Admin hub setup goes here.</Text>
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {justifyContent: 'center', alignItems: 'center'},
|
container: {justifyContent: 'center', alignItems: 'center'},
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ import React from 'react';
|
|||||||
import {StyleSheet, Text} from 'react-native';
|
import {StyleSheet, Text} from 'react-native';
|
||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const CreateGameScreen = () => (
|
const CreateGameScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Create Game</Text>
|
<Text style={styles.title}>Create Game</Text>
|
||||||
<Text style={styles.body}>Create game setup goes here.</Text>
|
<Text style={styles.body}>Create game setup goes here.</Text>
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {justifyContent: 'center', alignItems: 'center'},
|
container: {justifyContent: 'center', alignItems: 'center'},
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ import React from 'react';
|
|||||||
import {StyleSheet, Text} from 'react-native';
|
import {StyleSheet, Text} from 'react-native';
|
||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const GameLobbyScreen = () => (
|
const GameLobbyScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Game Lobby</Text>
|
<Text style={styles.title}>Game Lobby</Text>
|
||||||
<Text style={styles.body}>Game lobby setup goes here.</Text>
|
<Text style={styles.body}>Game lobby setup goes here.</Text>
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {justifyContent: 'center', alignItems: 'center'},
|
container: {justifyContent: 'center', alignItems: 'center'},
|
||||||
|
|||||||
@@ -4,32 +4,38 @@ import useGameHook from '../../hooks/useGameHook';
|
|||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const GameTypeScreen = ({navigation}) => {
|
const GameTypeScreen = ({navigation}) => {
|
||||||
|
// Initialisation ------------
|
||||||
|
|
||||||
const {getGameTypes} = useGameHook();
|
const {getGameTypes} = useGameHook();
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [gameTypes, setGameTypes] = useState([]);
|
const [gameTypes, setGameTypes] = useState([]);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isMounted = true;
|
let isMounted = true;
|
||||||
|
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
const types = await getGameTypes();
|
const types = await getGameTypes();
|
||||||
if (isMounted) {
|
if (isMounted) setGameTypes(types || []);
|
||||||
setGameTypes(types || []);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
load();
|
load();
|
||||||
|
return () => { isMounted = false; };
|
||||||
|
}, []);
|
||||||
|
|
||||||
return () => {
|
// View -----------------------
|
||||||
isMounted = false;
|
|
||||||
};
|
|
||||||
}, [getGameTypes]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Select Game Type</Text>
|
<Text style={styles.title}>Select Game Type</Text>
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
{gameTypes && gameTypes.map((type) => (
|
{gameTypes && gameTypes.map((type) => (
|
||||||
<Pressable key={type} style={styles.button} onPress={() => navigation.navigate('GameLobbyScreen')}>
|
<Pressable
|
||||||
|
key={type}
|
||||||
|
style={styles.button}
|
||||||
|
onPress={() => navigation.navigate('GameLobbyScreen')}
|
||||||
|
>
|
||||||
<Text style={styles.buttonText}>{type}</Text>
|
<Text style={styles.buttonText}>{type}</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
))}
|
||||||
@@ -65,4 +71,3 @@ const styles = StyleSheet.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default GameTypeScreen;
|
export default GameTypeScreen;
|
||||||
|
|
||||||
@@ -3,6 +3,11 @@ import {StyleSheet, Text} from 'react-native';
|
|||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const JoinPrivateGameScreen = () => {
|
const JoinPrivateGameScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Join Private Game</Text>
|
<Text style={styles.title}>Join Private Game</Text>
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ import React from 'react';
|
|||||||
import {StyleSheet, Text} from 'react-native';
|
import {StyleSheet, Text} from 'react-native';
|
||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const LeaderboardScreen = () => (
|
const LeaderboardScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Leaderboard</Text>
|
<Text style={styles.title}>Leaderboard</Text>
|
||||||
<Text style={styles.body}>Leaderboard view goes here.</Text>
|
<Text style={styles.body}>Leaderboard view goes here.</Text>
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {justifyContent: 'center', alignItems: 'center'},
|
container: {justifyContent: 'center', alignItems: 'center'},
|
||||||
@@ -16,4 +23,3 @@ const styles = StyleSheet.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default LeaderboardScreen;
|
export default LeaderboardScreen;
|
||||||
|
|
||||||
@@ -5,9 +5,16 @@ import Screen from '../layout/Screen';
|
|||||||
import {Button, ButtonTray} from '../UI/Button';
|
import {Button, ButtonTray} from '../UI/Button';
|
||||||
|
|
||||||
const LoginScreen = ({ navigation }) => {
|
const LoginScreen = ({ navigation }) => {
|
||||||
|
// Initialisation ------------->
|
||||||
|
|
||||||
const { email, password, error, isLoading, setEmail, setPassword, login } = useAuthHook();
|
const { email, password, error, isLoading, setEmail, setPassword, login } = useAuthHook();
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async () => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const user = await login();
|
const user = await login();
|
||||||
@@ -22,6 +29,8 @@ const LoginScreen = ({ navigation }) => {
|
|||||||
navigation.reset({ index: 0, routes: [{ name: 'Game' }] });
|
navigation.reset({ index: 0, routes: [{ name: 'Game' }] });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
@@ -107,4 +116,3 @@ const styles = StyleSheet.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default LoginScreen;
|
export default LoginScreen;
|
||||||
|
|
||||||
@@ -7,13 +7,20 @@ import useGameHook from '../../hooks/useGameHook';
|
|||||||
import {getSession} from '../../hooks/SessionStore';
|
import {getSession} from '../../hooks/SessionStore';
|
||||||
|
|
||||||
const ManageGameScreen = () => {
|
const ManageGameScreen = () => {
|
||||||
|
// Initialisation ------------
|
||||||
|
|
||||||
const session = getSession();
|
const session = getSession();
|
||||||
const {getCaches, upsertCache} = useGameHook();
|
const {getCaches, upsertCache} = useGameHook();
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [userLocation, setUserLocation] = useState(null);
|
const [userLocation, setUserLocation] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [cacheRecords, setCacheRecords] = useState([]);
|
const [cacheRecords, setCacheRecords] = useState([]);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
const loadCaches = useCallback(async () => {
|
const loadCaches = useCallback(async () => {
|
||||||
if (!session.currentGid) {
|
if (!session.currentGid) {
|
||||||
setCacheRecords([]);
|
setCacheRecords([]);
|
||||||
@@ -21,15 +28,12 @@ const ManageGameScreen = () => {
|
|||||||
}
|
}
|
||||||
const rows = await getCaches(session.currentGid, null);
|
const rows = await getCaches(session.currentGid, null);
|
||||||
setCacheRecords(rows || []);
|
setCacheRecords(rows || []);
|
||||||
}, [getCaches, session.currentGid]);
|
}, [session.currentGid]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { loadCaches(); }, [loadCaches]);
|
||||||
loadCaches();
|
|
||||||
}, [loadCaches]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let locationSub;
|
let locationSub;
|
||||||
|
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
const {status} = await Location.requestForegroundPermissionsAsync();
|
const {status} = await Location.requestForegroundPermissionsAsync();
|
||||||
if (status !== 'granted') {
|
if (status !== 'granted') {
|
||||||
@@ -37,37 +41,23 @@ const ManageGameScreen = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const current = await Location.getCurrentPositionAsync({accuracy: Location.Accuracy.Balanced});
|
const current = await Location.getCurrentPositionAsync({accuracy: Location.Accuracy.Balanced});
|
||||||
setUserLocation({latitude: current.coords.latitude, longitude: current.coords.longitude});
|
setUserLocation({latitude: current.coords.latitude, longitude: current.coords.longitude});
|
||||||
|
|
||||||
locationSub = await Location.watchPositionAsync(
|
locationSub = await Location.watchPositionAsync(
|
||||||
{
|
{accuracy: Location.Accuracy.Balanced, distanceInterval: 1, timeInterval: 1000},
|
||||||
accuracy: Location.Accuracy.Balanced,
|
|
||||||
distanceInterval: 1,
|
|
||||||
timeInterval: 1000,
|
|
||||||
},
|
|
||||||
(next) => {
|
(next) => {
|
||||||
setUserLocation({latitude: next.coords.latitude, longitude: next.coords.longitude});
|
setUserLocation({latitude: next.coords.latitude, longitude: next.coords.longitude});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
return () => { if (locationSub) locationSub.remove(); };
|
||||||
return () => {
|
|
||||||
if (locationSub) {
|
|
||||||
locationSub.remove();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleAddCache = async (coordinate) => {
|
const handleAddCache = async (coordinate) => {
|
||||||
if (!session.currentGid) {
|
if (!session.currentGid) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
await upsertCache({
|
await upsertCache({
|
||||||
gid: session.currentGid,
|
gid: session.currentGid,
|
||||||
latitude: coordinate.latitude,
|
latitude: coordinate.latitude,
|
||||||
@@ -80,13 +70,9 @@ const ManageGameScreen = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleMoveCache = async (cacheId, coordinate) => {
|
const handleMoveCache = async (cacheId, coordinate) => {
|
||||||
if (!session.currentGid) {
|
if (!session.currentGid) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
const current = cacheRecords.find((cache) => cache.id === cacheId);
|
const current = cacheRecords.find((cache) => cache.id === cacheId);
|
||||||
if (!current) {
|
if (!current) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
await upsertCache({
|
await upsertCache({
|
||||||
gid: session.currentGid,
|
gid: session.currentGid,
|
||||||
cacheId,
|
cacheId,
|
||||||
@@ -99,6 +85,8 @@ const ManageGameScreen = () => {
|
|||||||
await loadCaches();
|
await loadCaches();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
if (!session.currentGid) {
|
if (!session.currentGid) {
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.center}>
|
<Screen style={styles.center}>
|
||||||
@@ -146,24 +134,11 @@ const ManageGameScreen = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {padding: 0},
|
||||||
padding: 0,
|
mapWrap: {flex: 1},
|
||||||
},
|
center: {justifyContent: 'center', alignItems: 'center'},
|
||||||
mapWrap: {
|
body: {color: '#4b5563', fontSize: 15},
|
||||||
flex: 1,
|
error: {color: '#dc2626', fontSize: 15},
|
||||||
},
|
|
||||||
center: {
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
color: '#4b5563',
|
|
||||||
fontSize: 15,
|
|
||||||
},
|
|
||||||
error: {
|
|
||||||
color: '#dc2626',
|
|
||||||
fontSize: 15,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default ManageGameScreen;
|
export default ManageGameScreen;
|
||||||
@@ -3,6 +3,11 @@ import {StyleSheet, Text} from 'react-native';
|
|||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const ManagePrivateGameScreen = () => {
|
const ManagePrivateGameScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Manage Private Game</Text>
|
<Text style={styles.title}>Manage Private Game</Text>
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ import React from 'react';
|
|||||||
import {StyleSheet, Text} from 'react-native';
|
import {StyleSheet, Text} from 'react-native';
|
||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const ManageSubgroupsScreen = () => (
|
const ManageSubgroupsScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Manage Subgroups</Text>
|
<Text style={styles.title}>Manage Subgroups</Text>
|
||||||
<Text style={styles.body}>Manage subgroups setup goes here.</Text>
|
<Text style={styles.body}>Manage subgroups setup goes here.</Text>
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {justifyContent: 'center', alignItems: 'center'},
|
container: {justifyContent: 'center', alignItems: 'center'},
|
||||||
|
|||||||
@@ -15,8 +15,13 @@ const toHeading = ({ x, y }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const MapScreen = () => {
|
const MapScreen = () => {
|
||||||
|
// Initialisation ------------
|
||||||
|
|
||||||
const session = getSession();
|
const session = getSession();
|
||||||
const {getCaches, claimCache} = useGameHook();
|
const {getCaches, claimCache} = useGameHook();
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [userLocation, setUserLocation] = useState(null);
|
const [userLocation, setUserLocation] = useState(null);
|
||||||
const [heading, setHeading] = useState(null);
|
const [heading, setHeading] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -24,8 +29,7 @@ const MapScreen = () => {
|
|||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
|
||||||
const activeCaches = useMemo(() => (
|
const activeCaches = useMemo(() => (
|
||||||
cacheRecords.map(
|
cacheRecords.map((cache) => new Cache(
|
||||||
(cache) => new Cache(
|
|
||||||
cache.id,
|
cache.id,
|
||||||
cache.coordinates.latitude,
|
cache.coordinates.latitude,
|
||||||
cache.coordinates.longitude,
|
cache.coordinates.longitude,
|
||||||
@@ -33,13 +37,14 @@ const MapScreen = () => {
|
|||||||
cache.clue,
|
cache.clue,
|
||||||
cache.groupId,
|
cache.groupId,
|
||||||
cache.subgroupId,
|
cache.subgroupId,
|
||||||
),
|
))
|
||||||
)
|
|
||||||
), [cacheRecords]);
|
), [cacheRecords]);
|
||||||
|
|
||||||
const subgroupFilter = session.currentSGid;
|
const subgroupFilter = session.currentSGid;
|
||||||
const {visibleCache, isClaiming, setIsClaiming} = usePlayerGame(userLocation, heading, activeCaches);
|
const {visibleCache, isClaiming, setIsClaiming} = usePlayerGame(userLocation, heading, activeCaches);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
const loadCaches = useCallback(async () => {
|
const loadCaches = useCallback(async () => {
|
||||||
if (!session.currentGid) {
|
if (!session.currentGid) {
|
||||||
setCacheRecords([]);
|
setCacheRecords([]);
|
||||||
@@ -47,11 +52,9 @@ const MapScreen = () => {
|
|||||||
}
|
}
|
||||||
const rows = await getCaches(session.currentGid, subgroupFilter);
|
const rows = await getCaches(session.currentGid, subgroupFilter);
|
||||||
setCacheRecords(rows || []);
|
setCacheRecords(rows || []);
|
||||||
}, [getCaches, session.currentGid, subgroupFilter]);
|
}, [session.currentGid, subgroupFilter]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => { loadCaches(); }, [loadCaches]);
|
||||||
loadCaches();
|
|
||||||
}, [loadCaches]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let locationSub;
|
let locationSub;
|
||||||
@@ -64,45 +67,31 @@ const MapScreen = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const current = await Location.getCurrentPositionAsync({accuracy: Location.Accuracy.Balanced});
|
const current = await Location.getCurrentPositionAsync({accuracy: Location.Accuracy.Balanced});
|
||||||
setUserLocation({latitude: current.coords.latitude, longitude: current.coords.longitude});
|
setUserLocation({latitude: current.coords.latitude, longitude: current.coords.longitude});
|
||||||
|
|
||||||
locationSub = await Location.watchPositionAsync(
|
locationSub = await Location.watchPositionAsync(
|
||||||
{
|
{accuracy: Location.Accuracy.Balanced, distanceInterval: 1, timeInterval: 1000},
|
||||||
accuracy: Location.Accuracy.Balanced,
|
|
||||||
distanceInterval: 1,
|
|
||||||
timeInterval: 1000,
|
|
||||||
},
|
|
||||||
(next) => {
|
(next) => {
|
||||||
setUserLocation({latitude: next.coords.latitude, longitude: next.coords.longitude});
|
setUserLocation({latitude: next.coords.latitude, longitude: next.coords.longitude});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Magnetometer.setUpdateInterval(500);
|
Magnetometer.setUpdateInterval(500);
|
||||||
headingSub = Magnetometer.addListener((data) => {
|
headingSub = Magnetometer.addListener((data) => { setHeading(toHeading(data)); });
|
||||||
setHeading(toHeading(data));
|
|
||||||
});
|
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (locationSub) {
|
if (locationSub) locationSub.remove();
|
||||||
locationSub.remove();
|
if (headingSub) headingSub.remove();
|
||||||
}
|
|
||||||
if (headingSub) {
|
|
||||||
headingSub.remove();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleClaim = async (cacheId) => {
|
const handleClaim = async (cacheId) => {
|
||||||
if (!session.currentGid) {
|
if (!session.currentGid) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
await claimCache({
|
await claimCache({
|
||||||
gid: session.currentGid,
|
gid: session.currentGid,
|
||||||
cacheId,
|
cacheId,
|
||||||
@@ -113,6 +102,8 @@ const MapScreen = () => {
|
|||||||
await loadCaches();
|
await loadCaches();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
if (!session.currentGid) {
|
if (!session.currentGid) {
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.center}>
|
<Screen style={styles.center}>
|
||||||
@@ -160,24 +151,11 @@ const MapScreen = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {padding: 0},
|
||||||
padding: 0,
|
mapWrap: {flex: 1},
|
||||||
},
|
center: {justifyContent: 'center', alignItems: 'center'},
|
||||||
mapWrap: {
|
body: {color: '#4b5563', fontSize: 15},
|
||||||
flex: 1,
|
error: {color: '#dc2626', fontSize: 15},
|
||||||
},
|
|
||||||
center: {
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
body: {
|
|
||||||
color: '#4b5563',
|
|
||||||
fontSize: 15,
|
|
||||||
},
|
|
||||||
error: {
|
|
||||||
color: '#dc2626',
|
|
||||||
fontSize: 15,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default MapScreen;
|
export default MapScreen;
|
||||||
@@ -5,30 +5,26 @@ import Screen from '../layout/Screen';
|
|||||||
import {Button, ButtonTray} from '../UI/Button';
|
import {Button, ButtonTray} from '../UI/Button';
|
||||||
|
|
||||||
const RegisterScreen = ({navigation}) => {
|
const RegisterScreen = ({navigation}) => {
|
||||||
|
// Initialisation ------------
|
||||||
|
|
||||||
const {
|
const {
|
||||||
username,
|
username, email, password, confirmPassword, accountType,
|
||||||
email,
|
error, isLoading,
|
||||||
password,
|
setUsername, setEmail, setPassword, setConfirmPassword, setAccountType,
|
||||||
confirmPassword,
|
|
||||||
accountType,
|
|
||||||
error,
|
|
||||||
isLoading,
|
|
||||||
setUsername,
|
|
||||||
setEmail,
|
|
||||||
setPassword,
|
|
||||||
setConfirmPassword,
|
|
||||||
setAccountType,
|
|
||||||
register,
|
register,
|
||||||
} = useAuthHook();
|
} = useAuthHook();
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
const handleRegister = async () => {
|
const handleRegister = async () => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const user = await register();
|
const user = await register();
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
if (!user) {
|
if (!user) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (user.IsAcceptedAdmin) {
|
if (user.IsAcceptedAdmin) {
|
||||||
navigation.reset({index: 0, routes: [{name: 'Admin'}]});
|
navigation.reset({index: 0, routes: [{name: 'Admin'}]});
|
||||||
return;
|
return;
|
||||||
@@ -36,6 +32,8 @@ const RegisterScreen = ({ navigation }) => {
|
|||||||
navigation.reset({index: 0, routes: [{name: 'Game'}]});
|
navigation.reset({index: 0, routes: [{name: 'Game'}]});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<View style={styles.content}>
|
<View style={styles.content}>
|
||||||
@@ -80,14 +78,18 @@ const RegisterScreen = ({ navigation }) => {
|
|||||||
onPress={() => setAccountType('Individual')}
|
onPress={() => setAccountType('Individual')}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
>
|
>
|
||||||
<Text style={[styles.typeText, accountType === 'Individual' && styles.typeTextActive]}>Individual</Text>
|
<Text style={[styles.typeText, accountType === 'Individual' && styles.typeTextActive]}>
|
||||||
|
Individual
|
||||||
|
</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<Pressable
|
<Pressable
|
||||||
style={[styles.typeButton, accountType === 'Business/School' && styles.typeButtonActive]}
|
style={[styles.typeButton, accountType === 'Business/School' && styles.typeButtonActive]}
|
||||||
onPress={() => setAccountType('Business/School')}
|
onPress={() => setAccountType('Business/School')}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
>
|
>
|
||||||
<Text style={[styles.typeText, accountType === 'Business/School' && styles.typeTextActive]}>Business</Text>
|
<Text style={[styles.typeText, accountType === 'Business/School' && styles.typeTextActive]}>
|
||||||
|
Business
|
||||||
|
</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ import React from 'react';
|
|||||||
import {StyleSheet, Text} from 'react-native';
|
import {StyleSheet, Text} from 'react-native';
|
||||||
import Screen from '../layout/Screen';
|
import Screen from '../layout/Screen';
|
||||||
|
|
||||||
const TeamScreen = () => (
|
const TeamScreen = () => {
|
||||||
|
// Initialisation -------------
|
||||||
|
// State ----------------------
|
||||||
|
// Handlers -------------------
|
||||||
|
// View -----------------------
|
||||||
|
|
||||||
|
return (
|
||||||
<Screen style={styles.container}>
|
<Screen style={styles.container}>
|
||||||
<Text style={styles.title}>Team Management</Text>
|
<Text style={styles.title}>Team Management</Text>
|
||||||
<Text style={styles.body}>Team management setup goes here.</Text>
|
<Text style={styles.body}>Team management setup goes here.</Text>
|
||||||
</Screen>
|
</Screen>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {justifyContent: 'center', alignItems: 'center'},
|
container: {justifyContent: 'center', alignItems: 'center'},
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// --- Session Store ---
|
||||||
|
|
||||||
const session = {
|
const session = {
|
||||||
currentUid: null,
|
currentUid: null,
|
||||||
currentGid: null,
|
currentGid: null,
|
||||||
@@ -7,6 +9,8 @@ const session = {
|
|||||||
isAcceptedAdmin: false,
|
isAcceptedAdmin: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// --- Handlers ---
|
||||||
|
|
||||||
const setSessionUser = (user) => {
|
const setSessionUser = (user) => {
|
||||||
session.currentUid = user?.Uid ?? null;
|
session.currentUid = user?.Uid ?? null;
|
||||||
session.currentGid = user?.Gid ?? null;
|
session.currentGid = user?.Gid ?? null;
|
||||||
|
|||||||
+2
-21
@@ -1,22 +1,3 @@
|
|||||||
import Constants from 'expo-constants';
|
const API_BASE_URL = 'http://localhost:3000';
|
||||||
|
|
||||||
const hostFromExpo = Constants.expoConfig?.hostUri?.split(':')[0] || null;
|
export default API_BASE_URL;
|
||||||
const apiBaseUrl = 'http://localhost:3000'; // Shirish, i need to deploy the database first so... wait until that... sorry buddy...
|
|
||||||
// if you want you can run your own db locally i can send you the files for it just ask :(((
|
|
||||||
|
|
||||||
const postJson = async (path, payload) => {
|
|
||||||
const response = await fetch(`${apiBaseUrl}${path}`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
const result = await response.json();
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(result.message || 'Request failed');
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const postDb = async (action, payload = {}) => {
|
|
||||||
return postJson('/db', { action, payload });
|
|
||||||
};
|
|
||||||
+28
-17
@@ -1,8 +1,16 @@
|
|||||||
import {useState} from 'react';
|
import {useState} from 'react';
|
||||||
import {postDb} from './dbLink';
|
import API from '../components/API/API';
|
||||||
|
import API_BASE_URL from './dbLink';
|
||||||
import {clearSession, setSessionUser} from './SessionStore';
|
import {clearSession, setSessionUser} from './SessionStore';
|
||||||
|
|
||||||
const useAuthHook = () => {
|
const useAuthHook = () => {
|
||||||
|
// Initialisation ------------
|
||||||
|
|
||||||
|
const loginEndpoint = `${API_BASE_URL}/auth/login`;
|
||||||
|
const registerEndpoint = `${API_BASE_URL}/auth/register`;
|
||||||
|
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [username, setUsername] = useState('');
|
const [username, setUsername] = useState('');
|
||||||
@@ -11,40 +19,41 @@ const useAuthHook = () => {
|
|||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
const login = async () => {
|
const login = async () => {
|
||||||
setError('');
|
setError('');
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
const response = await API.post(loginEndpoint, {
|
||||||
const user = await postDb('login', { email: email.trim(), password });
|
email: email.trim(),
|
||||||
setSessionUser(user);
|
password,
|
||||||
|
});
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
return user;
|
if (response.isSuccess) {
|
||||||
} catch (e) {
|
setSessionUser(response.result);
|
||||||
setError(e.message);
|
return response.result;
|
||||||
setIsLoading(false);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
setError(response.message);
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const register = async () => {
|
const register = async () => {
|
||||||
setError('');
|
setError('');
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
const response = await API.post(registerEndpoint, {
|
||||||
const user = await postDb('register', {
|
|
||||||
username: username.trim(),
|
username: username.trim(),
|
||||||
email: email.trim().toLowerCase(),
|
email: email.trim().toLowerCase(),
|
||||||
password,
|
password,
|
||||||
confirmPassword,
|
confirmPassword,
|
||||||
accountType,
|
accountType,
|
||||||
});
|
});
|
||||||
setSessionUser(user);
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
return user;
|
if (response.isSuccess) {
|
||||||
} catch (e) {
|
setSessionUser(response.result);
|
||||||
setError(e.message);
|
return response.result;
|
||||||
setIsLoading(false);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
setError(response.message);
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
@@ -57,6 +66,8 @@ const useAuthHook = () => {
|
|||||||
setError('');
|
setError('');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Return ---------------------
|
||||||
|
|
||||||
return {
|
return {
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
|
|||||||
+84
-15
@@ -1,33 +1,102 @@
|
|||||||
import {postDb} from './dbLink';
|
import API from '../components/API/API';
|
||||||
|
import API_BASE_URL from './dbLink';
|
||||||
|
|
||||||
const useGameHook = () => {
|
const useGameHook = () => {
|
||||||
const request = async (action, payload = {}) => postDb(action, payload);
|
// Initialisation ------------
|
||||||
|
|
||||||
const getGameTypes = async () => request('getGameTypes');
|
const gameTypesEndpoint = `${API_BASE_URL}/game-types`;
|
||||||
|
const groupsEndpoint = `${API_BASE_URL}/groups`;
|
||||||
|
const subgroupMembershipsEndpoint = `${API_BASE_URL}/subgroup-memberships`;
|
||||||
|
const teamsEndpoint = `${API_BASE_URL}/teams`;
|
||||||
|
const teamMembersEndpoint = `${API_BASE_URL}/team-members`;
|
||||||
|
const gameDataEndpoint = `${API_BASE_URL}/game-data`;
|
||||||
|
const adminWaitlistEndpoint = `${API_BASE_URL}/admin-waitlist`;
|
||||||
|
|
||||||
const getCreatedPrivateGame = async (userId) => request('getCreatedPrivateGameByUser', { userId });
|
// Handlers -------------------
|
||||||
|
|
||||||
const createPrivateGame = async (payload) => request('createPrivateGame', payload);
|
const getGameTypes = async () => {
|
||||||
|
const response = await API.get(gameTypesEndpoint);
|
||||||
|
return response.isSuccess ? response.result : [];
|
||||||
|
};
|
||||||
|
|
||||||
const joinPrivateGame = async (payload) => request('joinPrivateGame', payload);
|
const getCreatedPrivateGame = async (userId) => {
|
||||||
|
const response = await API.get(`${groupsEndpoint}?CreatedByUid=${userId}`);
|
||||||
|
return response.isSuccess ? response.result : [];
|
||||||
|
};
|
||||||
|
|
||||||
const joinAsAdmin = async (payload) => request('joinAsAdmin', payload);
|
const createPrivateGame = async (payload) => {
|
||||||
|
const response = await API.post(groupsEndpoint, payload);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
const getLobby = async (gid) => request('getLobby', { gid });
|
const joinPrivateGame = async (payload) => {
|
||||||
|
const response = await API.post(subgroupMembershipsEndpoint, payload);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
const getTeam = async (tid) => request('getTeam', { tid });
|
const joinAsAdmin = async (payload) => {
|
||||||
|
const response = await API.post(adminWaitlistEndpoint, payload);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
const createTeam = async (payload) => request('createTeam', payload);
|
const getLobby = async (gid) => {
|
||||||
|
const response = await API.get(`${groupsEndpoint}/${gid}`);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
const joinTeamByCode = async (payload) => request('joinTeamByCode', payload);
|
const getTeam = async (tid) => {
|
||||||
|
const response = await API.get(`${teamsEndpoint}/${tid}`);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
const getMapPoints = async (gid, sgid = null) => request('getMapPoints', { gid, sgid });
|
const createTeam = async (payload) => {
|
||||||
|
const response = await API.post(teamsEndpoint, payload);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
const getCaches = async (gid, sgid = null) => request('getCaches', { gid, sgid });
|
const joinTeamByCode = async (payload) => {
|
||||||
|
const response = await API.post(teamMembersEndpoint, payload);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
const upsertCache = async (payload) => request('upsertCache', payload);
|
const getMapPoints = async (gid, sgid = null) => {
|
||||||
|
let url = `${gameDataEndpoint}/${gid}/caches`;
|
||||||
|
if (sgid !== null) url += `?SGid=${sgid}`;
|
||||||
|
const response = await API.get(url);
|
||||||
|
return response.isSuccess ? response.result : [];
|
||||||
|
};
|
||||||
|
|
||||||
const claimCache = async (payload) => request('claimCache', payload);
|
const getCaches = async (gid, sgid = null) => {
|
||||||
|
let url = `${gameDataEndpoint}/${gid}/caches`;
|
||||||
|
if (sgid !== null) url += `?SGid=${sgid}`;
|
||||||
|
const response = await API.get(url);
|
||||||
|
return response.isSuccess ? response.result : [];
|
||||||
|
};
|
||||||
|
|
||||||
|
const upsertCache = async (payload) => {
|
||||||
|
if (payload.cacheId) {
|
||||||
|
const response = await API.put(
|
||||||
|
`${gameDataEndpoint}/${payload.gid}/caches/${payload.cacheId}`,
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
}
|
||||||
|
const response = await API.post(
|
||||||
|
`${gameDataEndpoint}/${payload.gid}/caches`,
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const claimCache = async (payload) => {
|
||||||
|
const response = await API.put(
|
||||||
|
`${gameDataEndpoint}/${payload.gid}/caches/${payload.cacheId}`,
|
||||||
|
{ClaimedByUid: payload.uid, ClaimedByTid: payload.tid},
|
||||||
|
);
|
||||||
|
return response.isSuccess ? response.result : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return ---------------------
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getGameTypes,
|
getGameTypes,
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ import {useEffect, useState} from 'react';
|
|||||||
import {isLookingAtCache, isWithinRadius} from '../utils/geoMath';
|
import {isLookingAtCache, isWithinRadius} from '../utils/geoMath';
|
||||||
|
|
||||||
const usePlayerGame = (playerLocation, playerHeading, activeCaches) => {
|
const usePlayerGame = (playerLocation, playerHeading, activeCaches) => {
|
||||||
|
// State ----------------------
|
||||||
|
|
||||||
const [visibleCache, setVisibleCache] = useState(null);
|
const [visibleCache, setVisibleCache] = useState(null);
|
||||||
const [isClaiming, setIsClaiming] = useState(false);
|
const [isClaiming, setIsClaiming] = useState(false);
|
||||||
|
|
||||||
|
// Handlers -------------------
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!playerLocation || playerHeading === null || playerHeading === undefined) {
|
if (!playerLocation || playerHeading === null || playerHeading === undefined) {
|
||||||
setVisibleCache(null);
|
setVisibleCache(null);
|
||||||
@@ -21,16 +25,13 @@ const usePlayerGame = (playerLocation, playerHeading, activeCaches) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTargeted = isLookingAtCache(
|
const isTargeted = isLookingAtCache(playerHeading, playerLocation, nearbyCache.coordinates);
|
||||||
playerHeading,
|
|
||||||
playerLocation,
|
|
||||||
nearbyCache.coordinates,
|
|
||||||
);
|
|
||||||
|
|
||||||
setVisibleCache(nearbyCache);
|
setVisibleCache(nearbyCache);
|
||||||
setIsClaiming(isTargeted);
|
setIsClaiming(isTargeted);
|
||||||
}, [playerLocation, playerHeading, activeCaches]);
|
}, [playerLocation, playerHeading, activeCaches]);
|
||||||
|
|
||||||
|
// Return ---------------------
|
||||||
|
|
||||||
return {visibleCache, isClaiming, setIsClaiming};
|
return {visibleCache, isClaiming, setIsClaiming};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user