diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx index 195b8cf..430124f 100644 --- a/src/components/Api/Api.tsx +++ b/src/components/Api/Api.tsx @@ -302,7 +302,20 @@ export async function GetStudyGroupListFiltered() { return instance .get("/api/v1/study_groups/near/", config) .then((response) => { - console.log("Data:", response.data); + return [true, response.data]; + }) + .catch((error) => { + let error_message = ParseError(error); + return [false, error_message]; + }); +} + +export async function GetStudyGroupList() { + const config = await GetConfig(); + return instance + .get("/api/v1/study_groups/", config) + .then((response) => { + console.log("test", response.data); return [true, response.data]; }) .catch((error) => { diff --git a/src/routes/Home/Home.tsx b/src/routes/Home/Home.tsx index 7e19e6e..f926c26 100644 --- a/src/routes/Home/Home.tsx +++ b/src/routes/Home/Home.tsx @@ -33,6 +33,7 @@ import { GetStudentStatus, GetStudentStatusList, GetStudentStatusListFiltered, + GetStudyGroupList, GetStudyGroupListFiltered, PatchStudentStatus, urlProvider, @@ -242,6 +243,34 @@ export default function Home() { }); }, }); + const [study_groups_global, setStudyGroupsGlobal] = useState< + StudyGroupType[] + >([]); + // Student Status List + const StudyGroupGlobalQuery = useQuery({ + enabled: !studying, + queryKey: ["study_group_list_global"], + queryFn: async () => { + const data = await GetStudyGroupList(); + if (data[0] == false) { + return Promise.reject(new Error(JSON.stringify(data[1]))); + } + return data; + }, + onSuccess: (data: StudyGroupReturnType) => { + if (data[1] && location) { + setStudyGroupsGlobal(data[1]); + } + }, + onError: (error: Error) => { + toast.show(String(error), { + type: "warning", + placement: "top", + duration: 2000, + animationType: "slide-in", + }); + }, + }); function CustomMap() { if (dist && location) { @@ -395,6 +424,76 @@ export default function Home() { ); })} + {study_groups_global.map( + (studygroup: StudyGroupType, index: number) => { + const randomColorWithOpacity = `rgba(${Math.floor( + Math.random() * 256 + )}, ${Math.floor(Math.random() * 256)}, ${Math.floor( + Math.random() * 256 + )}, 0.7)`; + + return ( + + { + toast.hideAll(); + toast.show( + + + Subject: {studygroup.subject} + + + Students Studying: {studygroup.users.length} + + + , + { + type: "normal", + placement: "top", + duration: 2000, + animationType: "slide-in", + style: { + backgroundColor: colors.secondary_2, + borderWidth: 1, + borderColor: colors.primary_1, + }, + } + ); + }} + /> + + + ); + } + )}