timetablev2 / frontend /src /components /ScheduleGrid.js
notha99y's picture
init
c398d0b
Raw History Blame Contribute Delete
3.99 kB
import React from 'react';
const ScheduleGrid = ({ scheduleData }) => {
if (!scheduleData || !scheduleData.grid || !scheduleData.time_slots) {
return (
<div className="text-center py-8 text-gray-500 dark:text-gray-400">
No schedule data available for visualization
</div>
);
}
const { grid, time_slots, used_days } = scheduleData;
if (!used_days || used_days.length === 0) {
return (
<div className="text-center py-8 text-gray-500 dark:text-gray-400">
No scheduled classes for this combination
</div>
);
}
return (
<div className="mt-6">
<h4 className="text-lg font-medium mb-4 text-gray-900 dark:text-white">Weekly Schedule</h4>
<div className="overflow-x-auto">
<table className="min-w-full border border-gray-300 dark:border-gray-600">
<thead>
<tr className="bg-gray-50 dark:bg-gray-700">
<th className="border border-gray-300 dark:border-gray-600 px-4 py-2 text-left font-medium text-gray-700 dark:text-gray-300">
Time
</th>
{used_days.map(day => (
<th key={day} className="border border-gray-300 dark:border-gray-600 px-4 py-2 text-center font-medium text-gray-700 dark:text-gray-300">
{day}
</th>
))}
</tr>
</thead>
<tbody>
{time_slots.map((timeSlot, timeIndex) => (
<tr key={timeSlot} className="hover:bg-gray-50 dark:hover:bg-gray-700">
<td className="border border-gray-300 dark:border-gray-600 px-4 py-2 font-medium text-gray-600 dark:text-gray-400 bg-gray-50 dark:bg-gray-700">
{timeSlot}
</td>
{used_days.map(day => {
const cellContent = grid[day] && grid[day][timeIndex] ? grid[day][timeIndex] : '';
return (
<td key={`${day}-${timeIndex}`} className="border border-gray-300 dark:border-gray-600 px-2 py-2 text-center">
{cellContent && (
<div className={`text-xs p-2 rounded ${getCellStyle(cellContent)}`}>
{cellContent}
</div>
)}
</td>
);
})}
</tr>
))}
</tbody>
</table>
</div>
<div className="mt-4 flex flex-wrap gap-4 text-sm text-gray-700 dark:text-gray-300">
<div className="flex items-center">
<div className="w-4 h-4 bg-blue-100 dark:bg-blue-900/30 border border-blue-300 dark:border-blue-700 rounded mr-2"></div>
<span>Lecture (L)</span>
</div>
<div className="flex items-center">
<div className="w-4 h-4 bg-green-100 dark:bg-green-900/30 border border-green-300 dark:border-green-700 rounded mr-2"></div>
<span>Tutorial (T)</span>
</div>
<div className="flex items-center">
<div className="w-4 h-4 bg-purple-100 dark:bg-purple-900/30 border border-purple-300 dark:border-purple-700 rounded mr-2"></div>
<span>Multiple Classes</span>
</div>
</div>
</div>
);
};
const getCellStyle = (content) => {
if (content.includes('|')) {
// Multiple classes in same slot
return 'bg-purple-100 dark:bg-purple-900/30 border-purple-300 dark:border-purple-700 text-purple-800 dark:text-purple-200';
} else if (content.includes(' L')) {
// Lecture
return 'bg-blue-100 dark:bg-blue-900/30 border-blue-300 dark:border-blue-700 text-blue-800 dark:text-blue-200';
} else if (content.includes(' T')) {
// Tutorial
return 'bg-green-100 dark:bg-green-900/30 border-green-300 dark:border-green-700 text-green-800 dark:text-green-200';
}
return 'bg-gray-100 dark:bg-gray-700 border-gray-300 dark:border-gray-600 text-gray-800 dark:text-gray-200';
};
export default ScheduleGrid;