diff --git a/api/afdb/library.ts b/api/afdb/library.ts index c9c308d..f982b84 100644 --- a/api/afdb/library.ts +++ b/api/afdb/library.ts @@ -89,10 +89,10 @@ export const getResourcesWithSource = async (topicIds: number[]): Promise => { +export const getTeachers = async (id?: number, subject_id?: number): Promise => { const queryParams = new URLSearchParams(); if (id !== undefined) queryParams.append('id', id.toString()); - if (subject !== undefined) queryParams.append('subject', subject.toString()); + if (subject_id !== undefined) queryParams.append('subject_id', subject_id.toString()); return fetchWithParams('teacher', queryParams); }; diff --git a/api/afdb/session.ts b/api/afdb/session.ts index ad88e77..7f4e242 100644 --- a/api/afdb/session.ts +++ b/api/afdb/session.ts @@ -27,10 +27,10 @@ export const getGroupUser = async (userDbId: number) => { }; -export const getGroupSessions = async (groupTypeId: number) => { +export const getGroupSessions = async (groupId: number) => { try { const queryParams = new URLSearchParams({ - group_type_id: groupTypeId.toString(), + group_id: groupId.toString(), }); const urlWithParams = `${url}/group-session?${queryParams.toString()}`; @@ -85,23 +85,23 @@ export const getSessionSchedule = async (sessionId: number, batchId?: number) => } }; -export const getGroupTypes = async (groupTypeId: number) => { +export const getGroup = async (groupId: number) => { try { const queryParams = new URLSearchParams({ - id: groupTypeId.toString(), + id: groupId.toString(), type: "batch" }); - const urlWithParams = `${url}/group-type?${queryParams.toString()}`; + const urlWithParams = `${url}/group?${queryParams.toString()}`; const response = await fetch(urlWithParams, getFetchConfig(bearerToken)); if (!response.ok) { - throw new Error(`Error in fetching Group Type Details: ${response.statusText}`); + throw new Error(`Error in fetching Group Details: ${response.statusText}`); } const data = await response.json(); return data; } catch (error) { - console.error("Error in fetching Group Type Details:", error); + console.error("Error in fetching Group Details:", error); throw error; } }; diff --git a/app/library/class/page.tsx b/app/library/class/page.tsx index fb827ef..267c598 100644 --- a/app/library/class/page.tsx +++ b/app/library/class/page.tsx @@ -49,7 +49,7 @@ const ClassLibrary = () => { const actualTabName = tabName.toLowerCase(); const subjectData = await getSubjects(actualTabName); const gradeData = await getGrades(selectedGrade); - const teacherData = await getTeachers(undefined, actualTabName); + const teacherData = await getTeachers(undefined, subjectData[0].id); setTeachers(teacherData); if (teacherData.length > 0 && selectedTeacher === undefined) { setSelectedTeacher(teacherData[0].id); diff --git a/app/page.tsx b/app/page.tsx index d0cbeda..70b2016 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -3,7 +3,7 @@ import { useAuth } from "@/services/AuthContext"; import TopBar from "@/components/TopBar"; import BottomNavigationBar from "@/components/BottomNavigationBar"; -import { getGroupUser, getGroupSessions, getGroupTypes, getQuizBatchData, getSessionSchedule } from "@/api/afdb/session"; +import { getGroupUser, getGroupSessions, getGroup, getQuizBatchData, getSessionSchedule } from "@/api/afdb/session"; import { useState, useEffect } from "react"; import { GroupUser, GroupSession, QuizSession, SessionSchedule, MessageDisplayProps } from "./types"; import Link from "next/link"; @@ -19,7 +19,7 @@ export default function Home() { const [liveClasses, setLiveClasses] = useState([]); const [isLoading, setIsLoading] = useState(true); const [quizzes, setQuizzes] = useState([]); - const commonTextClass = "text-gray-700 text-sm md:text-base mx-6 md:mx-8"; + const commonTextClass = "text-gray-700 text-xs md:text-sm mx-3 md:mx-8 whitespace-nowrap w-12"; const infoMessageClass = "flex items-center justify-center text-center h-72 mx-4 pb-40"; const portalBaseUrl = api.portal.frontend.baseUrl; const [batchId, setBatchId] = useState(); @@ -30,16 +30,16 @@ export default function Home() { const groupUserData = await getGroupUser(userDbId!); const groupSessions = await Promise.all(groupUserData.map(async (userData: GroupUser) => { - const groupType = await getGroupTypes(userData.group_type_id); + const group = await getGroup(userData.group_id); - const groupTypeIds = groupType.map((type: any) => type.id); + const groupIds = group.map((type: any) => type.id); - const quizIds = groupType.map((quiz: any) => quiz.child_id.parent_id) + const quizIds = group.map((quiz: any) => quiz.child_id.parent_id) - const batchId = groupType.map((groupTypeData: any) => groupTypeData.child_id.id) + const batchId = group.map((groupData: any) => groupData.child_id.id) setBatchId(batchId[0]) - const groupSessionData = await Promise.all(groupTypeIds.map(async (groupId: number) => { + const groupSessionData = await Promise.all(groupIds.map(async (groupId: number) => { return await getGroupSessions(groupId); })); @@ -105,7 +105,7 @@ export default function Home() { return (

Starts at
- {sessionStartTimeStr} + {formatTime(sessionStartTimeStr)}

); } @@ -122,7 +122,7 @@ export default function Home() { return (

Starts at
- {sessionStartTimeStr} + {formatTime(sessionStartTimeStr)}

); } diff --git a/app/types.ts b/app/types.ts index cb7e20f..283ee2e 100644 --- a/app/types.ts +++ b/app/types.ts @@ -106,12 +106,12 @@ export interface User { export interface GroupSession { session_id: number; - group_type_id: number + group_id: number } export interface GroupUser { user_id: number; - group_type_id: number + group_id: number } export interface Student { diff --git a/utils/dateUtils.ts b/utils/dateUtils.ts index bf5fc33..83e35cf 100644 --- a/utils/dateUtils.ts +++ b/utils/dateUtils.ts @@ -30,21 +30,13 @@ export function formatCurrentTime(dateTimeStr: string) { } export function formatQuizSessionTime(dateTimeStr: string) { - const [time, period] = dateTimeStr.split(' '); - const [hours, minutes, seconds] = time.split(':'); - let hours24 = parseInt(hours, 10); - - if (period && period.toUpperCase() === 'PM') { - hours24 += 12; - } - - const formattedTime = `${String(hours24).padStart(2, "0")}:${minutes}`; - return formattedTime; + const time = new Date(`01/01/2000 ${dateTimeStr}`); + return time.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' }); } export function formatTime(dateTimeStr: string) { - const [hours, minutes] = dateTimeStr.split(':'); - return `${hours}:${minutes}`; + const time = new Date(`2000-01-01T${dateTimeStr}`); + return time.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit', hour12: true }); } export function isSessionActive(endTime: string): boolean {