import { useEffect, useRef, useState } from 'preact/hooks' import _ from 'lodash' import { differenceInMinutes, startOfDay } from 'date-fns' import { WEEK_DAYS_SHORT, prettyCourseName, usePersistentState, } from '../../utils.jsx' import { layoutEvents, layoutIntervals } from '../../interval-layout.js' import { Popup } from '../Popup.jsx' import { Icon } from '../Icon.jsx' const TransposePopup = ({ onClose }) => { return ( Attenzione! La tabella è stata trasposta! } onClose={onClose} >

A grande richiesta popolare abbiamo trasposto la tabella dell'orario!

Assicurati quindi di leggerla correttamente (dall'alto verso il basso invece che da sinistra verso destra).

Se preferisci utilizzare la versione vecchia, puoi utilizzare il pulsante Trasponi{' '} {' '} nell'origine della tabella per trasporla. Questa scelta verrà salvata nei cookie e verrà ricordata in futuro

) } const NoCourseWarning = () => { return (

Non hai ancora selezionato nessun corso.

Clicca sui corsi nelle altre visuali per selezionarli e visualizzarli nell'orario

) } const Layout = ({ layout, day, colors }) => { return ( <> {layout.map(block => (
{block.events.map((event, index) => (
{event.aule.map(aula => (
{aula.replace(/^Fib /, '')}
))}
))}
))} ) } const ScheduleGrid = ({ orientation, setOrientation, weekStart, weekEnd, dayBlocksLayout, colors, }) => { return (
{[1, 2, 3, 4, 5].map(n => ( <>
{WEEK_DAYS_SHORT[n]}
))} {[9, 11, 14, 16].map(n => (
{n}-{n + 2}
))}
{[9, 11, 13, 14, 16, 18].map(n => ( <> {n * 2 > weekStart && n * 2 < weekEnd && (
)} ))} {Object.entries(dayBlocksLayout).map(([day, layout]) => ( ))}
) } const ScheduleLegend = ({ courses, colors }) => { return (
{courses.map(course => ( <>
{prettyCourseName(course.name)}
))}
) } const ScheduleCard = ({ orientation, setOrientation, weekStart, weekEnd, dayBlocksLayout, courses, colors, }) => { return (
) } export const Schedule = ({ timetables, selection }) => { const [hasSeenTranspose, setHasSeenTranspose] = usePersistentState( 'transpose_info', 'false' ) const [orientation, setOrientation] = usePersistentState( 'orientation', 'original' ) const colorList = [ 'red', 'purple', 'blue', 'yellow', 'green', 'orange', 'lightblue', ] const allEvents = timetables['tutti'] const selectionSet = new Set(selection) const events = allEvents .filter(e => selectionSet.has(e.id)) .map(e => ({ ...e, day: e.start.getDay(), start: differenceInMinutes(e.start, startOfDay(e.start)), end: differenceInMinutes(e.end, startOfDay(e.start)), })) const weekStart = Math.min(...events.map(e => e.start), 9 * 60) / 30 const weekEnd = Math.max(...events.map(e => e.end), 18 * 60) / 30 const relativeEvents = events.map(e => ({ ...e, start: Math.round(e.start / 30 - weekStart), end: Math.round(e.end / 30 - weekStart), })) const courses = _.uniqBy(events, event => event.id) const colors = Object.fromEntries( courses.map((course, index) => { return [course.id, colorList[index % colorList.length]] }) ) const base = { 1: [], 2: [], 3: [], 4: [], 5: [], } const eventsByWeekday = { ...base, ..._.groupBy(relativeEvents, event => event.day), } const dayBlocksLayout = _.mapValues(eventsByWeekday, dayEvents => layoutEvents(dayEvents) ) return ( <> {hasSeenTranspose === 'false' && ( setHasSeenTranspose('true')} /> )}
{selection.length === 0 && }
) }