feat: Anna University CGPA formula, credit fixes, academic overview dashboard, lab/theory badges

This commit is contained in:
Shanmuga Krishnan S M
2026-08-19 14:06:20 +05:30
parent 56ce10fc55
commit 596504840e
10 changed files with 2249 additions and 1234 deletions

View File

@@ -62,8 +62,9 @@ function App() {
<Route path="/faculty" element={<Faculty />} />
<Route path="/events" element={<Events />} />
{/* Student Dashboard — Timetable, Staff, Location (IMS Reg No & Password) */}
{/* Student Dashboard & Timetable — Real IMS Reg No & Password */}
<Route path="/dashboard" element={<StudentDashboard />} />
<Route path="/timetable" element={<StudentDashboard />} />
{/* Protected Routes — Require Google Sign-In */}
<Route

View File

@@ -224,43 +224,27 @@ export default function GoogleAuthModal({ isOpen, onClose }: GoogleAuthModalProp
)}
</button>
{/* Quick Demo Fill Buttons */}
{/* Quick Demo Fill Buttons for Admins */}
<div className="pt-3 border-t border-white/10 space-y-1.5">
<span className="text-[10px] text-slate-400 font-semibold block text-center uppercase tracking-wider">
Quick Demo Credentials:
Official Admin Portals:
</span>
<div className="grid grid-cols-2 gap-1.5 text-[11px]">
<button
type="button"
onClick={() => handleQuickFill('2114251001', 'rit@2026')}
className="p-2 rounded-lg bg-slate-950/80 hover:bg-slate-950 border border-white/5 text-left flex items-center justify-between transition-colors cursor-pointer"
>
<span className="truncate">🎓 CSE Student</span>
<span className="text-[9px] text-orange-400 font-mono">Fill</span>
</button>
<button
type="button"
onClick={() => handleQuickFill('2114251002', 'rit@2026')}
className="p-2 rounded-lg bg-slate-950/80 hover:bg-slate-950 border border-white/5 text-left flex items-center justify-between transition-colors cursor-pointer"
>
<span className="truncate">🎓 AI&DS Student</span>
<span className="text-[9px] text-orange-400 font-mono">Fill</span>
</button>
<button
type="button"
onClick={() => handleQuickFill('Transport', 'RIT@2026')}
className="p-2 rounded-lg bg-slate-950/80 hover:bg-slate-950 border border-white/5 text-left flex items-center justify-between transition-colors cursor-pointer"
className="p-2.5 rounded-xl bg-slate-950/80 hover:bg-slate-950 border border-white/5 text-left flex items-center justify-between transition-colors cursor-pointer"
>
<span className="truncate">🚌 Transport Admin</span>
<span className="text-[9px] text-blue-400 font-mono">Fill</span>
<span className="text-[9px] text-blue-400 font-mono">Select</span>
</button>
<button
type="button"
onClick={() => handleQuickFill('Admin', 'RIT@2026')}
className="p-2 rounded-lg bg-slate-950/80 hover:bg-slate-950 border border-white/5 text-left flex items-center justify-between transition-colors cursor-pointer"
className="p-2.5 rounded-xl bg-slate-950/80 hover:bg-slate-950 border border-white/5 text-left flex items-center justify-between transition-colors cursor-pointer"
>
<span className="truncate">⚡ Super Admin</span>
<span className="text-[9px] text-emerald-400 font-mono">Fill</span>
<span className="text-[9px] text-emerald-400 font-mono">Select</span>
</button>
</div>
</div>

View File

@@ -36,7 +36,7 @@ interface NavItem {
const PRIMARY_LINKS: NavItem[] = [
{ label: 'Home', path: '/', icon: HomeIcon },
{ label: 'Time table', path: '/dashboard', icon: LayoutDashboard },
{ label: 'Student dashboard', path: '/dashboard', icon: LayoutDashboard },
{ label: 'Notes', path: '/notes', icon: BookOpen },
{ label: 'Bus Routes', path: '/bus-routes', icon: Bus },
{ label: 'Faculty Directory', path: '/faculty', icon: UserCheck },
@@ -318,7 +318,7 @@ export default function Navbar() {
className="w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-slate-300 hover:text-white hover:bg-orange-500/15 hover:border-orange-500/20 text-xs font-semibold transition-all cursor-pointer"
>
<GraduationCap className="w-4 h-4 text-orange-400" />
My Time Table
Student Dashboard
</Link>
)}
<button

View File

@@ -200,41 +200,45 @@ export function AuthProvider({ children }: { children: ReactNode }) {
return { success: false, message: 'Please enter both username/register number and password.' };
}
// 1. First, check if credentials match Admin / Transport
try {
const adminRes = await fetch(getBackendUrl('/api/admin/login'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: cleanedUser, password: cleanedPass }),
});
const isAdminUsername = ['admin', 'transport', 'ritadmin', 'superadmin'].includes(cleanedUser.toLowerCase());
if (adminRes.ok) {
const data = await adminRes.json();
if (data.success && data.token && data.role) {
localStorage.setItem(ADMIN_TOKEN_KEY, data.token);
localStorage.setItem(ADMIN_ROLE_KEY, data.role);
localStorage.setItem(ADMIN_USER_KEY, data.username);
// 1. First, check if credentials match Admin / Transport (only for admin accounts)
if (isAdminUsername) {
try {
const adminRes = await fetch(getBackendUrl('/api/admin/login'), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: cleanedUser, password: cleanedPass }),
});
const adminUserObj: AuthUser = {
id: 999999,
name: data.username,
email: data.role === 'ROLE_TRANSPORT' ? 'transport@ritchennai.edu.in' : 'admin@ritchennai.edu.in',
verifiedStudent: false,
role: data.role,
};
setUser(adminUserObj);
setIsAuthModalOpen(false);
if (adminRes.ok) {
const data = await adminRes.json();
if (data.success && data.token && data.role) {
localStorage.setItem(ADMIN_TOKEN_KEY, data.token);
localStorage.setItem(ADMIN_ROLE_KEY, data.role);
localStorage.setItem(ADMIN_USER_KEY, data.username);
return {
success: true,
role: data.role,
redirectTo: '/admin',
message: `${data.username} logged in successfully`,
};
const adminUserObj: AuthUser = {
id: 999999,
name: data.username,
email: data.role === 'ROLE_TRANSPORT' ? 'transport@ritchennai.edu.in' : 'admin@ritchennai.edu.in',
verifiedStudent: false,
role: data.role,
};
setUser(adminUserObj);
setIsAuthModalOpen(false);
return {
success: true,
role: data.role,
redirectTo: '/admin',
message: `${data.username} logged in successfully`,
};
}
}
} catch {
// If admin endpoint fails or is offline, check fallback
}
} catch {
// If admin endpoint fails or is offline, check fallback
}
// Direct local check for Admin credentials fallback
@@ -295,9 +299,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
return {
success: true,
role: 'ROLE_STUDENT',
redirectTo: '/dashboard',
redirectTo: '/timetable',
message: 'Student login successful',
};
} else if (!imsResult.success && imsResult.message) {
return {
success: false,
message: imsResult.message,
};
}
} catch {
// Fallback

View File

@@ -9,6 +9,8 @@ import { getBackendUrl } from '@/lib/utils';
import { StaggerContainer, StaggerItem } from '@/components/AnimatedContainer/AnimatedContainer';
import AnimatedContainer from '@/components/AnimatedContainer/AnimatedContainer';
import { useAuth } from '@/context/AuthContext';
const TRENDING_TAGS = ['hostel', 'academics', 'clubs', 'campus', 'canteen', 'sports', 'placement', 'library', 'cat exam', 'semester', 'labs', 'exams'];
const AVATARS: Record<string, string> = {

View File

@@ -45,11 +45,13 @@ function normalizeDepartmentName(input?: string | null): string | null {
export default function Faculty() {
const [searchParams] = useSearchParams();
const [searchFaculty, setSearchFaculty] = useState('');
const [searchFaculty, setSearchFaculty] = useState(() => searchParams.get('search') || '');
const [sortBy, setSortBy] = useState('Name A-Z');
// Initial department detection (from URL query string or logged-in IMS student session)
const initialDepartment = useMemo(() => {
if (searchParams.has('search')) return 'All Departments';
const queryDept = searchParams.get('dept');
const matchedQuery = normalizeDepartmentName(queryDept);
if (matchedQuery) return matchedQuery;
@@ -65,10 +67,16 @@ export default function Faculty() {
const [selectedDept, setSelectedDept] = useState<string>(initialDepartment);
// Update selectedDept if URL parameter changes
// Update selectedDept and searchFaculty if URL parameter changes
useEffect(() => {
setSelectedDept(initialDepartment);
}, [initialDepartment]);
const querySearch = searchParams.get('search');
if (querySearch !== null) {
setSearchFaculty(querySearch);
setSelectedDept('All Departments');
} else {
setSelectedDept(initialDepartment);
}
}, [searchParams, initialDepartment]);
const studentSession = useMemo(() => getStoredImsSession(), []);
const isStudentDeptAutoFiltered = selectedDept !== 'All Departments' && (

View File

@@ -2,9 +2,10 @@ import { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import {
Trophy, Search, Plus, RefreshCw, ExternalLink, Code2,
Sparkles, Flame, Award, CheckCircle2, Shield, User, Filter, X, Clock
Sparkles, Flame, Award, CheckCircle2, Shield, User, Filter, X, Clock, Lock
} from 'lucide-react';
import { getBackendUrl } from '@/lib/utils';
import { useAuth } from '@/context/AuthContext';
interface LeetcodeProfile {
id: number;
@@ -25,6 +26,7 @@ const DEPARTMENTS = ['All', 'CSE', 'IT', 'AI&DS', 'ECE', 'EEE', 'MECH', 'CIVIL',
const YEARS = ['All', '1st Year', '2nd Year', '3rd Year', '4th Year'];
export default function LeetcodeLeaderboard() {
const { isAuthenticated, openAuthModal } = useAuth();
const [profiles, setProfiles] = useState<LeetcodeProfile[]>([]);
const [loading, setLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState('');
@@ -42,8 +44,36 @@ export default function LeetcodeLeaderboard() {
const [year, setYear] = useState('1st Year');
useEffect(() => {
fetchLeaderboard();
}, []);
if (isAuthenticated) {
fetchLeaderboard();
}
}, [isAuthenticated]);
if (!isAuthenticated) {
return (
<div className="min-h-screen pt-24 pb-16 bg-[#FAF9FC] text-[#1A0B2E] px-4 flex flex-col items-center justify-center text-center">
<div className="w-full max-w-md bg-white border border-[#E9E5EE] rounded-3xl p-8 shadow-xl space-y-5">
<div className="w-16 h-16 rounded-2xl bg-orange-100 text-[#FF6B00] flex items-center justify-center mx-auto border border-orange-200 shadow-md">
<Lock className="w-8 h-8" />
</div>
<div>
<h2 className="text-xl font-extrabold text-[#1A0B2E]" style={{ fontFamily: 'Plus Jakarta Sans, sans-serif' }}>
Student Sign In Required
</h2>
<p className="text-xs text-[#4A3E5E] mt-1.5 leading-relaxed">
RIT LeetCode Arena & Campus Rankings are accessible exclusively to verified RIT students. Please sign in with your student credentials to view the rankings and register your handle.
</p>
</div>
<button
onClick={openAuthModal}
className="w-full py-3.5 px-4 rounded-xl text-white font-bold text-xs bg-gradient-to-r from-[#FF6B00] to-[#F97316] hover:opacity-95 shadow-lg shadow-orange-500/20 transition-all cursor-pointer"
>
Sign In to LeetCode Arena
</button>
</div>
</div>
);
}
const fetchLeaderboard = async () => {
setLoading(true);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff