mirror of
https://github.com/mudabbir-ahmad/MAD-Treasure-Hunt.git
synced 2026-10-08 03:00:20 +00:00
31 lines
705 B
JavaScript
31 lines
705 B
JavaScript
import { useEffect, useState } from 'react';
|
|
import { getMapPoints } from '../API/API';
|
|
import { getSession } from '../Model/SessionStore';
|
|
|
|
const useMapViewModel = (groupId = null) => {
|
|
const [points, setPoints] = useState([]);
|
|
const { currentGid, currentSGid } = getSession();
|
|
const resolvedGid = groupId ?? currentGid;
|
|
|
|
useEffect(() => {
|
|
if (!resolvedGid) {
|
|
setPoints([]);
|
|
return;
|
|
}
|
|
let active = true;
|
|
getMapPoints(resolvedGid, currentSGid).then((payload) => {
|
|
if (active) {
|
|
setPoints(payload);
|
|
}
|
|
});
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, [resolvedGid, currentSGid]);
|
|
|
|
return { points };
|
|
};
|
|
|
|
export default useMapViewModel;
|
|
|