diff --git a/app/library/contentList.tsx b/api/afdb/library.ts similarity index 97% rename from app/library/contentList.tsx rename to api/afdb/library.ts index 3db5296..75606a4 100644 --- a/app/library/contentList.tsx +++ b/api/afdb/library.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { Subject, Grade, Chapter, Resource, Topic } from '../types' +import { Subject, Grade, Chapter, Resource, Topic } from '../../app/types' const url = process.env.NEXT_PUBLIC_AF_DB_SERVICE_URL; const bearerToken = process.env.NEXT_PUBLIC_AF_DB_SERVICE_BEARER_TOKEN; diff --git a/app/SessionList.tsx b/api/afdb/session.ts similarity index 100% rename from app/SessionList.tsx rename to api/afdb/session.ts diff --git a/app/layout.tsx b/app/layout.tsx index 7ff3bc2..29bc9af 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,6 +1,6 @@ import './globals.css' import { Inter } from 'next/font/google' -import { AuthProvider } from './AuthContext' +import { AuthProvider } from '../services/AuthContext' const inter = Inter({ subsets: ['latin'] }) @@ -17,7 +17,7 @@ export default function RootLayout({ return ( - {children} + {children} ) diff --git a/app/library/page.tsx b/app/library/page.tsx index 5046e56..f315b82 100644 --- a/app/library/page.tsx +++ b/app/library/page.tsx @@ -5,7 +5,7 @@ import BottomNavigationBar from '@/components/BottomNavigationBar'; import Loading from '../loading'; import TopBar from '@/components/TopBar'; import PrimaryButton from '@/components/Button'; -import { getSubjects, getChapters, getResourcesWithSource, getTopics, getGrades } from './contentList'; +import { getSubjects, getChapters, getResourcesWithSource, getTopics, getGrades } from '../../api/afdb/library'; import { Chapter, Resource, Topic } from '../types'; import { useEffect } from 'react'; import Link from 'next/link'; diff --git a/app/page.tsx b/app/page.tsx index ddb3de8..c6a8737 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,13 +1,15 @@ "use client" -import { useAuth } from "./AuthContext"; + +import { useAuth } from "@/services/AuthContext"; import TopBar from "@/components/TopBar"; import BottomNavigationBar from "@/components/BottomNavigationBar"; -import { getSessionOccurrences, getSessions } from "./SessionList"; +import { getSessionOccurrences, getSessions } from "@/api/afdb/session"; import { useState, useEffect } from "react"; import { LiveClasses } from "./types"; import Link from "next/link"; import PrimaryButton from "@/components/Button"; import Loading from "./loading"; +import { isSameDay, formatTime } from "@/utils/dateUtils"; export default function Home() { const { loggedIn, userId } = useAuth(); @@ -52,24 +54,6 @@ export default function Home() { } } - - - function isSameDay(date1: Date, date2: Date): boolean { - return ( - date1.getDate() === date2.getDate() && - date1.getMonth() === date2.getMonth() && - date1.getFullYear() === date2.getFullYear() - ); - } - - - function formatTime(dateTimeStr: string) { - const date = new Date(dateTimeStr); - const hours = String(date.getUTCHours()).padStart(2, "0"); - const minutes = String(date.getUTCMinutes()).padStart(2, "0"); - return `${hours}:${minutes}`; - } - function renderButton(data: { sessionOccurrence: any, sessionDetail: any }) { const currentTime = new Date(); const sessionTimeStr = formatTime(data.sessionOccurrence.start_time); diff --git a/app/reports/page.tsx b/app/reports/page.tsx index 933b4b6..1390937 100644 --- a/app/reports/page.tsx +++ b/app/reports/page.tsx @@ -5,7 +5,7 @@ import ReportsList from "./reports_list"; import Loading from "../loading"; import BottomNavigationBar from "@/components/BottomNavigationBar"; import TopBar from "@/components/TopBar"; -import { useAuth } from "../AuthContext"; +import { useAuth } from "../../services/AuthContext"; export default function ReportsPage() { const { loggedIn } = useAuth(); @@ -13,13 +13,13 @@ export default function ReportsPage() { return ( <> {/* {loggedIn ? ( */} -
- - - - - -
+
+ + + + + +
{/* ) : (
diff --git a/components/TopBar.tsx b/components/TopBar.tsx index ece359e..e3c0f82 100644 --- a/components/TopBar.tsx +++ b/components/TopBar.tsx @@ -2,7 +2,7 @@ import { usePathname } from "next/navigation"; import CurrentTime from "./CurrentTime"; -import { useAuth } from "@/app/AuthContext"; +import { useAuth } from "@/services/AuthContext"; const TopBar = () => { const { userName } = useAuth(); @@ -12,7 +12,7 @@ const TopBar = () => { }; const pathname = usePathname(); - const routeName = routeNames[pathname] ||

Welcome
{userName}

; + const routeName = routeNames[pathname] ||

Welcome
{userName}

; return (
diff --git a/app/AuthContext.tsx b/services/AuthContext.tsx similarity index 97% rename from app/AuthContext.tsx rename to services/AuthContext.tsx index 9271931..9607de3 100644 --- a/app/AuthContext.tsx +++ b/services/AuthContext.tsx @@ -3,7 +3,7 @@ import React, { createContext, useContext, useState, useEffect } from 'react'; import { verifyToken } from '@/services/validation'; import { useRouter } from 'next/navigation'; -import { AuthContextProps } from './types'; +import { AuthContextProps } from '../app/types'; import { api } from '@/services/url'; const AuthContext = createContext(undefined); diff --git a/services/url.tsx b/services/url.ts similarity index 100% rename from services/url.tsx rename to services/url.ts diff --git a/services/validation.tsx b/services/validation.ts similarity index 100% rename from services/validation.tsx rename to services/validation.ts diff --git a/utils/dateUtils.ts b/utils/dateUtils.ts new file mode 100644 index 0000000..b229da5 --- /dev/null +++ b/utils/dateUtils.ts @@ -0,0 +1,15 @@ +export function isSameDay(date1: Date, date2: Date): boolean { + return ( + date1.getDate() === date2.getDate() && + date1.getMonth() === date2.getMonth() && + date1.getFullYear() === date2.getFullYear() + ); +} + + +export function formatTime(dateTimeStr: string) { + const date = new Date(dateTimeStr); + const hours = String(date.getUTCHours()).padStart(2, "0"); + const minutes = String(date.getUTCMinutes()).padStart(2, "0"); + return `${hours}:${minutes}`; +}