Skip to content

Commit

Permalink
Merge pull request #10 from avantifellows/chore/refactor
Browse files Browse the repository at this point in the history
🎨 Code Refactoring
  • Loading branch information
Bahugunajii authored Nov 15, 2023
2 parents a0e0944 + c682cb3 commit 66fd041
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion app/library/contentList.tsx → api/afdb/library.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import './globals.css'
import { Inter } from 'next/font/google'
import { AuthProvider } from './AuthContext'
import { AuthProvider } from '../services/AuthContext'

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
title: 'Avanti Gurukul',
description: 'Generated by create next app',
description: 'A product of Avanti',
}

export default function RootLayout({
Expand All @@ -17,7 +17,7 @@ export default function RootLayout({
return (
<html lang="en">
<AuthProvider>
<body className={inter.className}>{children}</body>
<body className={inter.className}>{children}</body>
</AuthProvider>
</html>
)
Expand Down
2 changes: 1 addition & 1 deletion app/library/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
36 changes: 10 additions & 26 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -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, formatCurrentTime, formatSessionTime } from "@/utils/dateUtils";

export default function Home() {
const { loggedIn, userId } = useAuth();
Expand Down Expand Up @@ -52,28 +54,10 @@ 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);
const currentTimeStr = formatTime(currentTime.toISOString());
const sessionTimeStr = formatSessionTime(data.sessionOccurrence.start_time);
const currentTimeStr = formatCurrentTime(currentTime.toISOString());

if (data.sessionDetail.platform === 'meet') {
if (sessionTimeStr <= currentTimeStr) {
Expand Down Expand Up @@ -137,10 +121,10 @@ export default function Home() {
<div key={index} className="flex mt-4 items-center" >
<div>
<p className="text-gray-700 text-sm md:text-base mx-6 md:mx-8">
{formatTime(data.sessionOccurrence.start_time)}
{formatSessionTime(data.sessionOccurrence.start_time)}
</p>
<p className="text-gray-700 text-sm md:text-base mx-6 md:mx-8">
{formatTime(data.sessionOccurrence.end_time)}
{formatSessionTime(data.sessionOccurrence.end_time)}
</p>
</div>
<div className="bg-card rounded-lg shadow-lg min-h-24 h-auto py-6 relative w-full flex flex-row justify-between mr-4">
Expand All @@ -164,10 +148,10 @@ export default function Home() {
<div key={index} className="flex mt-4 items-center" >
<div>
<p className="text-gray-700 text-sm md:text-base mx-6 md:mx-8">
{formatTime(data.sessionOccurrence.start_time)}
{formatSessionTime(data.sessionOccurrence.start_time)}
</p>
<p className="text-gray-700 text-sm md:text-base mx-6 md:mx-8">
{formatTime(data.sessionOccurrence.end_time)}
{formatSessionTime(data.sessionOccurrence.end_time)}
</p>
</div>
<div className="bg-card rounded-lg shadow-lg min-h-24 h-auto py-6 relative w-full flex flex-row justify-between mr-4">
Expand Down
16 changes: 8 additions & 8 deletions app/reports/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ 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();

return (
<>
{/* {loggedIn ? ( */}
<main className="max-w-xl mx-auto bg-white">
<TopBar />
<Client message="">
<ReportsList />
</Client>
<BottomNavigationBar />
</main>
<main className="max-w-xl mx-auto bg-white">
<TopBar />
<Client message="">
<ReportsList />
</Client>
<BottomNavigationBar />
</main>
{/* ) : (
<main className="max-w-xl mx-auto bg-white">
<TopBar />
Expand Down
4 changes: 2 additions & 2 deletions components/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -12,7 +12,7 @@ const TopBar = () => {
};

const pathname = usePathname();
const routeName = routeNames[pathname] || <p>Welcome <br /> {userName} </p> ;
const routeName = routeNames[pathname] || <p>Welcome <br /> {userName} </p>;

return (
<div className="text-white p-4 h-32 justify-between items-center bg-primary">
Expand Down
2 changes: 1 addition & 1 deletion app/AuthContext.tsx → services/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthContextProps | undefined>(undefined);
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions utils/dateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function isSameDay(date1: Date, date2: Date): boolean {
return (
date1.getDate() === date2.getDate() &&
date1.getMonth() === date2.getMonth() &&
date1.getFullYear() === date2.getFullYear()
);
}

export function formatSessionTime(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}`;
}

export function formatCurrentTime(dateTimeStr: string) {
const date = new Date(dateTimeStr);
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
return `${hours}:${minutes}`;
}

0 comments on commit 66fd041

Please sign in to comment.