Spaces:
Runtime error
Runtime error
Greg
Claude Opus 4.7 (1M context)
feat(schedule): fit PDF in single page + use plantel name as title
413032b Download frontend/src/components/ScheduleGrid.tsx from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 5.13 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/components/ScheduleGrid.tsx
- Command line
-
hf download hf://spaces/Talosware/talos-access/frontend/src/components/ScheduleGrid.tsx
-
curl -L -o ScheduleGrid.tsx https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/components/ScheduleGrid.tsx
5.13 kB
| import { type SectionSchedule } from '../services/sectionScheduleService'; | |
| const DAY_NAMES = ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo']; | |
| const COLORS = [ | |
| 'bg-blue-100 border-blue-300 text-blue-700', | |
| 'bg-emerald-100 border-emerald-300 text-emerald-700', | |
| 'bg-amber-100 border-amber-300 text-amber-700', | |
| 'bg-purple-100 border-purple-300 text-purple-700', | |
| 'bg-rose-100 border-rose-300 text-rose-700', | |
| 'bg-cyan-100 border-cyan-300 text-cyan-700', | |
| 'bg-orange-100 border-orange-300 text-orange-700', | |
| 'bg-teal-100 border-teal-300 text-teal-700', | |
| ]; | |
| const FIXED_SLOTS = Array.from({ length: 11 }, (_, i) => { | |
| const h = 7 + i; | |
| const entry = `${String(h).padStart(2, '0')}:00`; | |
| const exit = `${String(h + 1).padStart(2, '0')}:00`; | |
| return { entry, exit }; | |
| }); | |
| export interface ScheduleGridProps { | |
| items: SectionSchedule[]; | |
| showWeekend?: boolean; | |
| compact?: boolean; | |
| } | |
| export default function ScheduleGrid({ items, showWeekend = false, compact = false }: ScheduleGridProps) { | |
| const visibleDays = DAY_NAMES.filter((_, i) => showWeekend || i < 5); | |
| const customSlots: { entry: string; exit: string }[] = []; | |
| const seenCustom = new Set<string>(); | |
| for (const item of items) { | |
| const key = `${item.entry_time}-${item.exit_time}`; | |
| if (seenCustom.has(key)) continue; | |
| seenCustom.add(key); | |
| const isFixed = FIXED_SLOTS.some((s) => s.entry === item.entry_time && s.exit === item.exit_time); | |
| if (!isFixed) customSlots.push({ entry: item.entry_time, exit: item.exit_time }); | |
| } | |
| customSlots.sort((a, b) => a.entry.localeCompare(b.entry)); | |
| const allSlots = [...FIXED_SLOTS, ...customSlots]; | |
| // En compact (print), oculta filas de horas que no tienen ningún bloque en | |
| // ningún día visible. Reduce el alto total para que el PDF entre en 1 página. | |
| const slotsToShow = compact | |
| ? allSlots.filter((slot) => | |
| items.some( | |
| (b) => | |
| b.entry_time === slot.entry && | |
| b.exit_time === slot.exit && | |
| visibleDays.includes(DAY_NAMES[b.day_of_week]) | |
| ) | |
| ) | |
| : allSlots; | |
| const blockPadding = compact ? 'px-1.5 py-1' : 'px-4 py-3'; | |
| const blockText = compact ? 'text-xs' : 'text-base'; | |
| const headerText = compact ? 'text-xs' : 'text-base'; | |
| const slotText = compact ? 'text-xs' : 'text-base'; | |
| const minCellH = compact ? 'min-h-[40px]' : 'min-h-[90px]'; | |
| const gridGap = compact ? 'gap-1' : 'gap-3'; | |
| const timeColWidth = compact ? '80px' : '120px'; | |
| return ( | |
| <div | |
| className={`grid ${gridGap}`} | |
| style={{ gridTemplateColumns: `${timeColWidth} repeat(${visibleDays.length}, 1fr)` }} | |
| > | |
| <div className={`${headerText} text-gray-400 font-medium self-end pb-1 pl-1`}>Hora</div> | |
| {visibleDays.map((d, i) => ( | |
| <div key={i} className={`${headerText} font-semibold text-gray-600 text-center pb-1 border-b-2 border-gray-200`}> | |
| {d.slice(0, 3)} | |
| </div> | |
| ))} | |
| {slotsToShow.map((slot, rowIdx) => ( | |
| <div key={rowIdx} className="contents"> | |
| <div className={`${slotText} text-gray-500 font-mono pt-1 pr-1 text-right self-start ${rowIdx >= FIXED_SLOTS.length ? 'italic' : ''}`}> | |
| {slot.entry}<br /><span className="text-gray-300">{slot.exit}</span> | |
| </div> | |
| {visibleDays.map((dayName, vIdx) => { | |
| const dayIdx = DAY_NAMES.indexOf(dayName); | |
| const cellBlocks = items.filter( | |
| (b) => b.day_of_week === dayIdx && b.entry_time === slot.entry && b.exit_time === slot.exit | |
| ); | |
| return ( | |
| <div | |
| key={vIdx} | |
| className={`${minCellH} rounded-lg border-2 p-2 ${ | |
| cellBlocks.length > 0 | |
| ? 'border-transparent' | |
| : 'border-dashed border-gray-200' | |
| }`} | |
| > | |
| {cellBlocks.map((block, bIdx) => { | |
| const colorClass = block.subject_id | |
| ? COLORS[block.subject_id % COLORS.length] | |
| : 'bg-gray-100 border-gray-200 text-gray-500'; | |
| return ( | |
| <div | |
| key={bIdx} | |
| className={`${blockText} leading-snug font-medium rounded-md ${blockPadding} border mb-1.5 last:mb-0 ${colorClass}`} | |
| title={`${block.entry_time}–${block.exit_time}${block.subject_name ? ` · ${block.subject_name}` : ''}${block.teacher_name ? ` · ${block.teacher_name}` : ''}`} | |
| > | |
| <span className="font-mono">{block.entry_time}–{block.exit_time}</span> | |
| {block.subject_name && ( | |
| <div className={`${compact ? 'text-xs' : 'text-sm'} opacity-75 mt-0.5 leading-tight`}> | |
| {block.subject_name} | |
| {block.teacher_name ? ` — ${block.teacher_name}` : ''} | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| ))} | |
| </div> | |
| ); | |
| } | |