Fix AdminDashboard state declarations and handle offline fetch gracefully in Notes.tsx
This commit is contained in:
@@ -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[]>([]);
|
||||
|
||||
@@ -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();
|
||||
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,
|
||||
type: n.fileType || 'notes',
|
||||
downloads: n.downloadsCount || 0,
|
||||
fileSize: n.fileSize,
|
||||
fileSize: n.fileSize || '2.4 MB',
|
||||
uploadedAt: n.uploadedAt ? n.uploadedAt.split('T')[0] : '',
|
||||
downloadUrl: n.downloadUrl
|
||||
downloadUrl: n.downloadUrl || '#'
|
||||
}));
|
||||
setNotes(mappedData);
|
||||
} else {
|
||||
setNotes(NOTES_DATA);
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching notes:', err);
|
||||
setNotes(NOTES_DATA);
|
||||
}
|
||||
setNotes(localFallback);
|
||||
} catch {
|
||||
setNotes(localFallback);
|
||||
}
|
||||
};
|
||||
fetchNotes();
|
||||
|
||||
Reference in New Issue
Block a user