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,56 @@
|
||||
import { useState } from 'react';
|
||||
import { createPrivateGame, joinAsAdmin } from '../API/API';
|
||||
import { getSession, setSessionGroup } from '../Model/SessionStore';
|
||||
|
||||
const useManagePrivateSubtaskViewModel = () => {
|
||||
const [businessOrSchoolName, setBusinessOrSchoolName] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const createNewPrivateGame = async () => {
|
||||
setError('');
|
||||
const { currentUid } = getSession();
|
||||
try {
|
||||
const group = await createPrivateGame({
|
||||
userId: currentUid,
|
||||
groupName: businessOrSchoolName.trim() || 'New Private Game',
|
||||
businessOrSchoolName: businessOrSchoolName.trim() || 'Unnamed Business',
|
||||
isBusiness: true,
|
||||
});
|
||||
setSessionGroup(group.Gid, 0);
|
||||
return group;
|
||||
} catch (e) {
|
||||
setError(e.message);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const joinAdminForPrivate = async () => {
|
||||
setError('');
|
||||
const { currentUid } = getSession();
|
||||
try {
|
||||
const response = await joinAsAdmin({
|
||||
userId: currentUid,
|
||||
businessOrSchoolName: businessOrSchoolName.trim(),
|
||||
});
|
||||
const gid = response?.Gid ?? null;
|
||||
if (gid !== null) {
|
||||
setSessionGroup(gid, 0);
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
setError(e.message);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
businessOrSchoolName,
|
||||
error,
|
||||
setBusinessOrSchoolName,
|
||||
createNewPrivateGame,
|
||||
joinAdminForPrivate,
|
||||
};
|
||||
};
|
||||
|
||||
export default useManagePrivateSubtaskViewModel;
|
||||
|
||||
Reference in new issue
Block a user