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,33 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { getTeam } from '../API/API';
|
||||
import { getSession } from '../Model/SessionStore';
|
||||
|
||||
const useTeamViewModel = (teamId = null) => {
|
||||
const [team, setTeam] = useState(null);
|
||||
const resolvedTeamId = teamId ?? getSession().currentTGid;
|
||||
|
||||
useEffect(() => {
|
||||
if (!resolvedTeamId) {
|
||||
setTeam(null);
|
||||
return;
|
||||
}
|
||||
let active = true;
|
||||
getTeam(resolvedTeamId).then((payload) => {
|
||||
if (active) {
|
||||
setTeam(payload);
|
||||
}
|
||||
}).catch(() => {
|
||||
if (active) {
|
||||
setTeam(null);
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [resolvedTeamId]);
|
||||
|
||||
return { team };
|
||||
};
|
||||
|
||||
export default useTeamViewModel;
|
||||
|
||||
Reference in new issue
Block a user