Add initial JSON data files and implement core page components for game functionality

This commit is contained in:
bobbert committed 2026-03-17 21:49:44 +00:00
1 parent 81847a9188
commit ca27f8d6ed
54 files changed
+2424 -250

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
import { useState } from 'react';
import { createTeam, getLobby, joinTeam } from '../API/API';
import { getSession, setSessionTeam } from '../Model/SessionStore';
const useLobbyViewModel = () => {
const [teamCode, setTeamCode] = useState('');
const [error, setError] = useState('');
const loadLobby = async () => {
const { currentGid } = getSession();
return getLobby(currentGid);
};
const createLobbyTeam = async ({ teamName }) => {
setError('');
try {
const { currentUid, currentGid } = getSession();
const team = await createTeam({ userId: currentUid, gid: currentGid, teamName });
setSessionTeam(team.Tid);
return team;
} catch (e) {
setError(e.message);
return null;
}
};
const joinLobbyTeam = async () => {
setError('');
try {
const { currentUid } = getSession();
const team = await joinTeam({ userId: currentUid, teamCode: teamCode.trim().toUpperCase() });
setSessionTeam(team.Tid);
return team;
} catch (e) {
setError(e.message);
return null;
}
};
return {
teamCode,
error,
setTeamCode,
loadLobby,
createLobbyTeam,
joinLobbyTeam,
};
};
export default useLobbyViewModel;