Fix AdminDashboard state declarations and handle offline fetch gracefully in Notes.tsx

This commit is contained in:
Shanmuga Krishnan S M
2026-08-19 08:58:12 +05:30
parent 9a0c601955
commit e15c95fafd
2 changed files with 73 additions and 19 deletions

View File

@@ -89,7 +89,51 @@ export default function AdminDashboard() {
const [loadingLogin, setLoadingLogin] = useState(false);
// Active Tab
const [activeTab, setActiveTab] = useState<'transport' | 'telegram' | 'notes' | 'community' | 'subscribers'>('transport');
const [activeTab, setActiveTab] = useState<'transport' | 'telegram' | 'notes' | 'community' | 'subscribers' | 'faculty' | 'clubs' | 'curriculum'>('transport');
// Faculty State
const [facultyList, setFacultyList] = useState<any[]>([]);
const [loadingFaculty, setLoadingFaculty] = useState(false);
const [facultySearch, setFacultySearch] = useState('');
const [isFacultyModalOpen, setIsFacultyModalOpen] = useState(false);
const [editingFaculty, setEditingFaculty] = useState<any | null>(null);
const [facultyFormData, setFacultyFormData] = useState({
name: '',
designation: 'Assistant Professor',
department: 'Computer Science & Engineering',
email: '',
office: '',
specialization: '',
isClassIncharge: false,
});
// Clubs & Centers State
const [clubsList, setClubsList] = useState<any[]>([]);
const [loadingClubs, setLoadingClubs] = useState(false);
const [clubsSearch, setClubsSearch] = useState('');
const [isClubModalOpen, setIsClubModalOpen] = useState(false);
const [editingClub, setEditingClub] = useState<any | null>(null);
const [clubFormData, setClubFormData] = useState({
name: '',
description: '',
category: 'Center of Excellence',
type: 'Center' as 'Club' | 'Center',
coordinatorName: '',
contactEmail: '',
details: '',
});
// Curriculum & GPA State
const [selectedGpaDept, setSelectedGpaDept] = useState<string>('CSE');
const [selectedGpaSem, setSelectedGpaSem] = useState<number>(1);
const [curriculumMap, setCurriculumMap] = useState<Record<string, Record<number, any[]>>>({});
const [isCourseModalOpen, setIsCourseModalOpen] = useState(false);
const [editingCourseIndex, setEditingCourseIndex] = useState<number | null>(null);
const [courseFormData, setCourseFormData] = useState({
name: '',
credits: 3,
isElective: false,
});
// Transport State
const [routes, setRoutes] = useState<BusRouteItem[]>([]);

View File

@@ -1337,29 +1337,39 @@ export default function Notes() {
useEffect(() => {
const fetchNotes = async () => {
let localFallback = NOTES_DATA;
try {
const saved = localStorage.getItem('RIT_LOCAL_NOTES');
if (saved) {
const parsed = JSON.parse(saved);
if (Array.isArray(parsed) && parsed.length > 0) localFallback = parsed;
}
} catch {}
try {
const response = await fetch(getBackendUrl('/api/notes'));
if (response.ok) {
const data = await response.json();
const mappedData = data.map((n: any) => ({
id: String(n.id),
title: n.title,
subject: n.subject,
department: n.department,
semester: n.semester,
type: n.fileType,
downloads: n.downloadsCount || 0,
fileSize: n.fileSize,
uploadedAt: n.uploadedAt ? n.uploadedAt.split('T')[0] : '',
downloadUrl: n.downloadUrl
}));
setNotes(mappedData);
} else {
setNotes(NOTES_DATA);
if (Array.isArray(data) && data.length > 0) {
const mappedData = data.map((n: any) => ({
id: String(n.id),
title: n.title,
subject: n.subject,
department: n.department,
semester: n.semester,
type: n.fileType || 'notes',
downloads: n.downloadsCount || 0,
fileSize: n.fileSize || '2.4 MB',
uploadedAt: n.uploadedAt ? n.uploadedAt.split('T')[0] : '',
downloadUrl: n.downloadUrl || '#'
}));
setNotes(mappedData);
return;
}
}
} catch (err) {
console.error('Error fetching notes:', err);
setNotes(NOTES_DATA);
setNotes(localFallback);
} catch {
setNotes(localFallback);
}
};
fetchNotes();