mirror of
https://github.com/mudabbir-ahmad/MAD-Treasure-Hunt.git
synced 2026-10-08 03:00:20 +00:00
Add initial JSON data files and implement core page components for game functionality
This commit is contained in:
1 parent
81847a9188
commit
ca27f8d6ed
54 files changed
+2424
-250
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user