Spaces:
Runtime error
Runtime error
Greg Claude Sonnet 4.6 commited on
Commit ·
511ff3f
1
Parent(s): 357c065
feat(schedule): add reusable ScheduleGrid read-only component
Browse filesPure read-only grid extracted from ScheduleModal logic. Supports compact
mode (smaller padding/font) for print layout. No click/drag/edit handlers.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
frontend/src/components/ScheduleGrid.tsx
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { type SectionSchedule } from '../services/sectionScheduleService';
|
| 2 |
+
|
| 3 |
+
const DAY_NAMES = ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo'];
|
| 4 |
+
|
| 5 |
+
const COLORS = [
|
| 6 |
+
'bg-blue-100 border-blue-300 text-blue-700',
|
| 7 |
+
'bg-emerald-100 border-emerald-300 text-emerald-700',
|
| 8 |
+
'bg-amber-100 border-amber-300 text-amber-700',
|
| 9 |
+
'bg-purple-100 border-purple-300 text-purple-700',
|
| 10 |
+
'bg-rose-100 border-rose-300 text-rose-700',
|
| 11 |
+
'bg-cyan-100 border-cyan-300 text-cyan-700',
|
| 12 |
+
'bg-orange-100 border-orange-300 text-orange-700',
|
| 13 |
+
'bg-teal-100 border-teal-300 text-teal-700',
|
| 14 |
+
];
|
| 15 |
+
|
| 16 |
+
const FIXED_SLOTS = Array.from({ length: 11 }, (_, i) => {
|
| 17 |
+
const h = 7 + i;
|
| 18 |
+
const entry = `${String(h).padStart(2, '0')}:00`;
|
| 19 |
+
const exit = `${String(h + 1).padStart(2, '0')}:00`;
|
| 20 |
+
return { entry, exit };
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
export interface ScheduleGridProps {
|
| 24 |
+
items: SectionSchedule[];
|
| 25 |
+
showWeekend?: boolean;
|
| 26 |
+
compact?: boolean;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export default function ScheduleGrid({ items, showWeekend = false, compact = false }: ScheduleGridProps) {
|
| 30 |
+
const visibleDays = DAY_NAMES.filter((_, i) => showWeekend || i < 5);
|
| 31 |
+
|
| 32 |
+
const customSlots: { entry: string; exit: string }[] = [];
|
| 33 |
+
const seenCustom = new Set<string>();
|
| 34 |
+
for (const item of items) {
|
| 35 |
+
const key = `${item.entry_time}-${item.exit_time}`;
|
| 36 |
+
if (seenCustom.has(key)) continue;
|
| 37 |
+
seenCustom.add(key);
|
| 38 |
+
const isFixed = FIXED_SLOTS.some((s) => s.entry === item.entry_time && s.exit === item.exit_time);
|
| 39 |
+
if (!isFixed) customSlots.push({ entry: item.entry_time, exit: item.exit_time });
|
| 40 |
+
}
|
| 41 |
+
customSlots.sort((a, b) => a.entry.localeCompare(b.entry));
|
| 42 |
+
const allSlots = [...FIXED_SLOTS, ...customSlots];
|
| 43 |
+
|
| 44 |
+
const blockPadding = compact ? 'px-2 py-2' : 'px-4 py-3';
|
| 45 |
+
const blockText = compact ? 'text-sm' : 'text-base';
|
| 46 |
+
const headerText = compact ? 'text-sm' : 'text-base';
|
| 47 |
+
const slotText = compact ? 'text-sm' : 'text-base';
|
| 48 |
+
const minCellH = compact ? 'min-h-[64px]' : 'min-h-[90px]';
|
| 49 |
+
|
| 50 |
+
return (
|
| 51 |
+
<div
|
| 52 |
+
className="grid gap-3"
|
| 53 |
+
style={{ gridTemplateColumns: `120px repeat(${visibleDays.length}, 1fr)` }}
|
| 54 |
+
>
|
| 55 |
+
<div className={`${headerText} text-gray-400 font-medium self-end pb-2 pl-1`}>Hora</div>
|
| 56 |
+
{visibleDays.map((d, i) => (
|
| 57 |
+
<div key={i} className={`${headerText} font-semibold text-gray-600 text-center pb-2 border-b-2 border-gray-200`}>
|
| 58 |
+
{d.slice(0, 3)}
|
| 59 |
+
</div>
|
| 60 |
+
))}
|
| 61 |
+
{allSlots.map((slot, rowIdx) => (
|
| 62 |
+
<div key={rowIdx} className="contents">
|
| 63 |
+
<div className={`${slotText} text-gray-500 font-mono pt-1.5 pr-1 text-right self-start ${rowIdx >= FIXED_SLOTS.length ? 'italic' : ''}`}>
|
| 64 |
+
{slot.entry}<br /><span className="text-gray-300">{slot.exit}</span>
|
| 65 |
+
</div>
|
| 66 |
+
{visibleDays.map((dayName, vIdx) => {
|
| 67 |
+
const dayIdx = DAY_NAMES.indexOf(dayName);
|
| 68 |
+
const cellBlocks = items.filter(
|
| 69 |
+
(b) => b.day_of_week === dayIdx && b.entry_time === slot.entry && b.exit_time === slot.exit
|
| 70 |
+
);
|
| 71 |
+
return (
|
| 72 |
+
<div
|
| 73 |
+
key={vIdx}
|
| 74 |
+
className={`${minCellH} rounded-lg border-2 p-2 ${
|
| 75 |
+
cellBlocks.length > 0
|
| 76 |
+
? 'border-transparent'
|
| 77 |
+
: 'border-dashed border-gray-200'
|
| 78 |
+
}`}
|
| 79 |
+
>
|
| 80 |
+
{cellBlocks.map((block, bIdx) => {
|
| 81 |
+
const colorClass = block.subject_id
|
| 82 |
+
? COLORS[block.subject_id % COLORS.length]
|
| 83 |
+
: 'bg-gray-100 border-gray-200 text-gray-500';
|
| 84 |
+
return (
|
| 85 |
+
<div
|
| 86 |
+
key={bIdx}
|
| 87 |
+
className={`${blockText} leading-snug font-medium rounded-md ${blockPadding} border mb-1.5 last:mb-0 ${colorClass}`}
|
| 88 |
+
title={`${block.entry_time}–${block.exit_time}${block.subject_name ? ` · ${block.subject_name}` : ''}${block.teacher_name ? ` · ${block.teacher_name}` : ''}`}
|
| 89 |
+
>
|
| 90 |
+
<span className="font-mono">{block.entry_time}–{block.exit_time}</span>
|
| 91 |
+
{block.subject_name && (
|
| 92 |
+
<div className="text-sm opacity-75 mt-0.5">
|
| 93 |
+
{block.subject_name}
|
| 94 |
+
{block.teacher_name ? ` — ${block.teacher_name}` : ''}
|
| 95 |
+
</div>
|
| 96 |
+
)}
|
| 97 |
+
</div>
|
| 98 |
+
);
|
| 99 |
+
})}
|
| 100 |
+
</div>
|
| 101 |
+
);
|
| 102 |
+
})}
|
| 103 |
+
</div>
|
| 104 |
+
))}
|
| 105 |
+
</div>
|
| 106 |
+
);
|
| 107 |
+
}
|