Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prod Deployment #45

Merged
merged 8 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/afdb/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export const getResourcesWithSource = async (topicIds: number[]): Promise<Resour
return resourceResponses.flat();
};

export const getTeachers = async (id?: number, subject?: string): Promise<Teacher[]> => {
export const getTeachers = async (id?: number, subject_id?: number): Promise<Teacher[]> => {
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);
};
Expand Down
14 changes: 7 additions & 7 deletions api/afdb/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`;
Expand Down Expand Up @@ -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;
}
};
Expand Down
2 changes: 1 addition & 1 deletion app/library/class/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -19,7 +19,7 @@ export default function Home() {
const [liveClasses, setLiveClasses] = useState<SessionSchedule[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [quizzes, setQuizzes] = useState<QuizSession[]>([]);
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();
Expand All @@ -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);
}));

Expand Down Expand Up @@ -105,7 +105,7 @@ export default function Home() {
return (
<p className="text-xs italic font-normal mr-4">
Starts at <br />
{sessionStartTimeStr}
{formatTime(sessionStartTimeStr)}
</p>
);
}
Expand All @@ -122,7 +122,7 @@ export default function Home() {
return (
<p className="text-xs italic font-normal mr-4">
Starts at <br />
{sessionStartTimeStr}
{formatTime(sessionStartTimeStr)}
</p>
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 4 additions & 12 deletions utils/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading