updated org acc logic, also made priv games joinable by clicking on game item in list

This commit is contained in:
bobbert committed 2026-04-09 18:29:13 +01:00
1 parent 20a2edbbda
commit 2a83d0608f
1 file changed
+70 -7
+70 -7
View File
@@ -14,8 +14,10 @@ import Card from '../UI/Card';
import useGameHook from '../../hooks/useGameHook'; import useGameHook from '../../hooks/useGameHook';
import usePlayerGame from '../../hooks/usePlayerGame'; import usePlayerGame from '../../hooks/usePlayerGame';
import { import {
clearPendingOrgJoin,
getSession, getSession,
setPendingAdmin, setPendingAdmin,
setPendingOrgJoin,
setSelectedCache, setSelectedCache,
setSessionGroup, setSessionGroup,
setSessionMode, setSessionMode,
@@ -58,6 +60,7 @@ const MapScreen = ({navigation, route}) => {
const [subgroups, setSubgroups] = useState([]); const [subgroups, setSubgroups] = useState([]);
const [availableGames, setAvailableGames] = useState([]); const [availableGames, setAvailableGames] = useState([]);
const [gamesLoading, setGamesLoading] = useState(false); const [gamesLoading, setGamesLoading] = useState(false);
const [quickJoiningCode, setQuickJoiningCode] = useState(null);
// Business join flow state // Business join flow state
const [joinStep, setJoinStep] = useState(null); const [joinStep, setJoinStep] = useState(null);
@@ -120,13 +123,37 @@ const MapScreen = ({navigation, route}) => {
setGamesLoading(true); setGamesLoading(true);
const groups = await getGroupsRef.current(); const groups = await getGroupsRef.current();
const individualGames = (groups || []).filter((group) => !group.BusinessOrSchoolName); const individualGames = (groups || []).filter((group) => !group.BusinessOrSchoolName);
setAvailableGames(individualGames); const withCodes = await Promise.all(
individualGames.map(async (group) => {
const subgroupRows = await getSubgroupsRef.current(group.Gid);
const memberSubgroup = (subgroupRows || []).find((row) => !row.IsAdminGroup);
return {
...group,
JoinCode: memberSubgroup?.JoinCode || null,
};
}),
);
setAvailableGames(withCodes.filter((group) => Boolean(group.JoinCode)));
setGamesLoading(false); setGamesLoading(false);
}; };
loadAvailableGames(); loadAvailableGames();
}, [inGame, session.isBusiness]); }, [inGame, session.isBusiness]);
useEffect(() => {
if (!session.isBusiness || inGame) return;
const pending = session.pendingOrgJoin;
if (!pending || pending.Uid !== session.currentUid || !pending.Gid) return;
setOrgCode(pending.OrgCode || '');
setMatchedGroup({
Gid: pending.Gid,
BusinessOrSchoolName: pending.BusinessOrSchoolName || null,
});
setJoinStep('deptCode');
}, [inGame, session.currentUid, session.isBusiness, session.pendingOrgJoin]);
// Default member subgroup SGid for cache creation (first non-admin subgroup) // Default member subgroup SGid for cache creation (first non-admin subgroup)
const departments = useMemo( const departments = useMemo(
() => subgroups.filter((sg) => !sg.IsAdminGroup), () => subgroups.filter((sg) => !sg.IsAdminGroup),
@@ -232,10 +259,9 @@ const MapScreen = ({navigation, route}) => {
}; };
}, [inGame, isPlayer]); }, [inGame, isPlayer]);
const handleJoinGame = async () => { const joinIndividualGameByCode = async (value) => {
if (!gameCode.trim()) return; const code = String(value || '').trim().toUpperCase();
const code = gameCode.trim().toUpperCase(); if (!code) return;
const result = await joinPrivateGame({JoinCode: code, Uid: session.currentUid}); const result = await joinPrivateGame({JoinCode: code, Uid: session.currentUid});
if (!result) return; if (!result) return;
setSessionGroup(result.Gid, result.SGid); setSessionGroup(result.Gid, result.SGid);
@@ -253,6 +279,18 @@ const MapScreen = ({navigation, route}) => {
navigation.navigate('TeamScreen'); navigation.navigate('TeamScreen');
}; };
const handleJoinGame = async () => {
await joinIndividualGameByCode(gameCode);
};
const handleQuickJoinGame = async (group) => {
if (!group?.JoinCode) return;
setQuickJoiningCode(group.JoinCode);
setGameCode(group.JoinCode);
await joinIndividualGameByCode(group.JoinCode);
setQuickJoiningCode(null);
};
const handleEnterGlobal = () => { const handleEnterGlobal = () => {
setSessionMode(GAME_MODE.GLOBAL); setSessionMode(GAME_MODE.GLOBAL);
navigation.navigate('GlobalEventsScreen'); navigation.navigate('GlobalEventsScreen');
@@ -288,6 +326,7 @@ const MapScreen = ({navigation, route}) => {
isBusiness: true, isBusiness: true,
}); });
if (!result) return; if (!result) return;
clearPendingOrgJoin();
setSessionMode(GAME_MODE.REGULAR); setSessionMode(GAME_MODE.REGULAR);
setPendingAdmin(false); setPendingAdmin(false);
const freshUser = await getUser(session.currentUid); const freshUser = await getUser(session.currentUid);
@@ -309,6 +348,12 @@ const MapScreen = ({navigation, route}) => {
return; return;
} }
setMatchedGroup(group); setMatchedGroup(group);
setPendingOrgJoin({
Uid: session.currentUid,
OrgCode: orgCode.trim().toUpperCase(),
Gid: group.Gid,
BusinessOrSchoolName: group.BusinessOrSchoolName || null,
});
setJoinStep('deptCode'); setJoinStep('deptCode');
}; };
@@ -332,6 +377,7 @@ const MapScreen = ({navigation, route}) => {
} }
setSessionGroup(matchedGroup.Gid, null); setSessionGroup(matchedGroup.Gid, null);
setSessionTeam(null); setSessionTeam(null);
clearPendingOrgJoin();
setPendingAdmin(true); setPendingAdmin(true);
setInGame(true); setInGame(true);
setIsAdmin(false); setIsAdmin(false);
@@ -351,6 +397,7 @@ const MapScreen = ({navigation, route}) => {
return; return;
} }
setSessionGroup(result.Gid, result.SGid); setSessionGroup(result.Gid, result.SGid);
clearPendingOrgJoin();
setSessionMode(GAME_MODE.REGULAR); setSessionMode(GAME_MODE.REGULAR);
setPendingAdmin(false); setPendingAdmin(false);
const freshUser = await getUser(session.currentUid); const freshUser = await getUser(session.currentUid);
@@ -479,7 +526,12 @@ const MapScreen = ({navigation, route}) => {
<ButtonTray> <ButtonTray>
<Button <Button
label="Back" label="Back"
onClick={() => { setJoinStep(null); setDeptCode(''); setJoinError(''); }} onClick={() => {
clearPendingOrgJoin();
setJoinStep(null);
setDeptCode('');
setJoinError('');
}}
styleButton={styles.backButton} styleButton={styles.backButton}
styleLabel={styles.backLabel} styleLabel={styles.backLabel}
/> />
@@ -555,10 +607,20 @@ const MapScreen = ({navigation, route}) => {
) : ( ) : (
<ScrollView style={styles.availableGamesList} contentContainerStyle={styles.availableGamesContent}> <ScrollView style={styles.availableGamesList} contentContainerStyle={styles.availableGamesContent}>
{availableGames.map((group) => ( {availableGames.map((group) => (
<Card key={group.Gid} style={styles.availableGameCard}> <Pressable
key={group.Gid}
onPress={() => handleQuickJoinGame(group)}
disabled={quickJoiningCode === group.JoinCode}
>
<Card style={styles.availableGameCard}>
<Text style={styles.availableGameName}>{group.GroupName || `Game ${group.Gid}`}</Text> <Text style={styles.availableGameName}>{group.GroupName || `Game ${group.Gid}`}</Text>
<Text style={styles.availableGameMeta}>Game Code: {group.JoinCode}</Text>
<Text style={styles.availableGameMeta}>Game ID: {group.Gid}</Text> <Text style={styles.availableGameMeta}>Game ID: {group.Gid}</Text>
<Text style={styles.availableGameHint}>
{quickJoiningCode === group.JoinCode ? 'Joining...' : 'Tap to join instantly'}
</Text>
</Card> </Card>
</Pressable>
))} ))}
</ScrollView> </ScrollView>
)} )}
@@ -852,6 +914,7 @@ const styles = StyleSheet.create({
availableGameCard: {marginBottom: 8}, availableGameCard: {marginBottom: 8},
availableGameName: {color: '#cdd6f4', fontSize: 15, fontWeight: '700', marginBottom: 3}, availableGameName: {color: '#cdd6f4', fontSize: 15, fontWeight: '700', marginBottom: 3},
availableGameMeta: {color: '#bac2de', fontSize: 12}, availableGameMeta: {color: '#bac2de', fontSize: 12},
availableGameHint: {color: '#bd93f9', fontSize: 12, fontWeight: '600', marginTop: 6},
createButton: {backgroundColor: '#a6e3a1', borderColor: '#a6e3a1'}, createButton: {backgroundColor: '#a6e3a1', borderColor: '#a6e3a1'},
createLabel: {color: '#1e1e2e', fontWeight: '600'}, createLabel: {color: '#1e1e2e', fontWeight: '600'},
bizTitle: {fontSize: 22, fontWeight: '700', color: '#cdd6f4', marginBottom: 6, textAlign: 'center'}, bizTitle: {fontSize: 22, fontWeight: '700', color: '#cdd6f4', marginBottom: 6, textAlign: 'center'},