Skip to content

Commit 3467178

Browse files
committed
classrooms: Show holiday as overlay notice
1 parent d163d0f commit 3467178

File tree

5 files changed

+42
-85
lines changed

5 files changed

+42
-85
lines changed

classrooms/components/App.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// <reference lib="deno.ns" />
55

66
import { useEffect, useRef, useState } from 'preact/hooks'
7+
import { getHolidays } from '../../terms/holidays.ts'
78
import { getTerm, Season, termName } from '../../terms/index.ts'
89
import { Day } from '../../util/Day.ts'
910
import { Time } from '../../util/Time.ts'
@@ -15,13 +16,7 @@ import {
1516
} from '../lib/coursesToClassrooms.ts'
1617
import { northeast, southwest, PADDING, mapPosition } from '../lib/locations.ts'
1718
import { now } from '../lib/now.ts'
18-
import {
19-
Term,
20-
TermCache,
21-
TermError,
22-
TermRequest,
23-
TermResult
24-
} from '../lib/TermCache.ts'
19+
import { Term, TermCache, TermError, TermResult } from '../lib/TermCache.ts'
2520
import { BuildingPanel } from './building/BuildingPanel.tsx'
2621
import { BuildingButton } from './BuildingButton.tsx'
2722
import { DateTimeButton } from './date-time/DateTimeButton.tsx'
@@ -41,6 +36,7 @@ type AppState = {
4136
buildings?: TermBuildings
4237
errors: TermError[]
4338
season: Season
39+
holiday?: string
4440
}
4541

4642
/**
@@ -102,12 +98,13 @@ export function App () {
10298
? 'Loading...'
10399
: state.buildings
104100
? null
105-
: error ??
106-
(state.season === 'WI'
107-
? 'Winter break.'
108-
: state.season === 'SP'
109-
? 'Spring break.'
110-
: 'Summer break.')
101+
: error ?? state.holiday
102+
? `${state.holiday}!`
103+
: state.season === 'WI'
104+
? 'Winter break.'
105+
: state.season === 'SP'
106+
? 'Spring break.'
107+
: 'Summer break.'
111108
)
112109

113110
const [showDatePanel, setShowDatePanel] = useState(false)
@@ -122,9 +119,10 @@ export function App () {
122119
? { year, quarter: 'S3' }
123120
: null
124121
]
125-
if (requests.every(request => request === null)) {
122+
const holiday = getHolidays(date.year)[date.id]
123+
if (holiday || requests.every(request => request === null)) {
126124
// Have the date selector open for the user to select another day
127-
setState({ errors: [], season })
125+
setState({ errors: [], season, holiday })
128126
setViewing(null)
129127
setShowDatePanel(true)
130128
return

classrooms/components/date-time/CalendarRow.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ export function CalendarWeekRow ({
117117
? 'calendar-finals-day'
118118
: ''
119119
} ${day.id === date.id ? 'calendar-selected' : ''} ${
120-
day >= termDays.start &&
121-
day <= termDays.end &&
122-
!holidays.includes(day.id)
120+
day >= termDays.start && day <= termDays.end && !holidays[day.id]
123121
? ''
124122
: 'calendar-break-day'
125123
}`}

classrooms/lib/TermCache.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export type Term = {
1010
quarter: Quarter
1111
}
1212

13-
export type TermRequest = Term | null
1413
/**
1514
* Represents a term result that was unintentionally not retrieved.
1615
* - `unavailable` means the term data successfully loaded.
@@ -24,36 +23,6 @@ export type TermResult = {
2423
request: Term
2524
result: TermCourses
2625
}
27-
export type GetTermsCallbacks = {
28-
requests: TermRequest[]
29-
full?: boolean
30-
onNoRequest: () => void
31-
/**
32-
* Called only when a term needs to be fetched. Called synchronously with
33-
* `getTerms`. Used to show a loading screen.
34-
*
35-
* @param terms - Contains the terms that need to be fetched.
36-
*/
37-
onStartFetch: (terms: Term[]) => void
38-
/**
39-
* Called immediately if all `requests` are `null`. Called synchronously with
40-
* `getTerms`. Used to show that UCSD is on break.
41-
*/
42-
/**
43-
* Called if all of the non-`null` requests gave errors. May be called
44-
* asynchronously after `getTerms`.
45-
*
46-
* @param fetched - True if a term had to be fetched.
47-
*/
48-
onError: (errors: TermError[], fetched: boolean) => void
49-
/**
50-
* Called once all the terms are ready, and at least one term has loaded
51-
* successfully. May be called asynchronously after `getTerms`.
52-
*
53-
* @param fetched - True if a term had to be fetched.
54-
*/
55-
onLoad: (results: TermResult[], errors: TermError[], fetched: boolean) => void
56-
}
5726

5827
export class TermCache {
5928
#cache: Record<string, TermCourses | 'unavailable' | undefined> = {}

classrooms/lib/coursesToClassrooms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export function coursesToClassrooms (
7979
continue
8080
}
8181
const days = time.days.filter(weekday => {
82-
const day = monday.add(weekday)
83-
if (holidays.includes(day.id)) {
82+
const day = monday.add((weekday + 6) % 7)
83+
if (holidays[day.id]) {
8484
return false
8585
}
8686
if (dateRange && meeting.kind !== 'exam') {

terms/holidays.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,35 @@
11
import { Day } from '../util/Day.ts'
22

3-
const holidayCache: Record<number, number[]> = {}
3+
const holidayCache: Record<number, Record<number, string>> = {}
44

55
/**
6-
* Returns a list of holidays that occur during the given year. Memoized. For
7-
* your convenience, the array contains day IDs rather than `Day` objects so you
8-
* can do `holidays.includes(day.id)`.
6+
* Returns an objecting mapping the day IDs of holidays that occur during the
7+
* given year to their names. Memoized.
98
* https://blink.ucsd.edu/HR/benefits/time-off/holidays.html
109
*/
11-
export function getHolidays (year: number): number[] {
12-
holidayCache[year] ??= [
13-
// New Year's Day
14-
Day.from(year, 1, 1),
15-
// Martin Luther King Jr. Day, observed on the third Monday in January
16-
Day.from(year, 1, 7).monday.add(14),
17-
// Presidents' Day, observed on the third Monday in February
18-
Day.from(year, 2, 7).monday.add(14),
19-
// César Chávez Day: observed on the last Friday in March
20-
Day.from(year, 3, 31).last(5),
21-
// Memorial Day, observed on the last Monday in May
22-
Day.from(year, 5, 31).monday,
23-
// Juneteenth National Independence Day, June
24-
Day.from(year, 6, 19),
25-
// Independence Day
26-
Day.from(year, 7, 4),
27-
// Labor Day (first Monday in September)
28-
Day.from(year, 9, 7).monday,
29-
// Veterans Day
30-
Day.from(year, 9, 11),
31-
// Thanksgiving Day (fourth Thursday of November)
32-
Day.from(year, 11, 7).last(4).add(21),
33-
// Friday after Thanksgiving
34-
Day.from(year, 11, 7).last(4).add(22),
35-
// Winter Break (2 days)
36-
Day.from(year, 12, 24),
37-
Day.from(year, 12, 25),
38-
// New Year's Eve (or equivalent)
39-
Day.from(year, 12, 31)
40-
].map(day => day.id)
10+
export function getHolidays (year: number): Record<number, string> {
11+
holidayCache[year] ??= {
12+
[Day.from(year, 1, 1).id]: "New Year's Day",
13+
// third Monday in January
14+
[Day.from(year, 1, 7).monday.add(14).id]: 'Martin Luther King Jr. Day',
15+
// third Monday in February
16+
[Day.from(year, 2, 7).monday.add(14).id]: "Presidents' Day",
17+
// last Friday in March
18+
[Day.from(year, 3, 31).last(5).id]: 'César Chávez Day',
19+
// last Monday in May
20+
[Day.from(year, 5, 31).monday.id]: 'Memorial Day',
21+
[Day.from(year, 6, 19).id]: 'Juneteenth',
22+
[Day.from(year, 7, 4).id]: 'Independence Day',
23+
// first Monday in September
24+
[Day.from(year, 9, 7).monday.id]: 'Labor Day',
25+
[Day.from(year, 9, 11).id]: 'Veterans Day',
26+
// fourth Thursday of November
27+
[Day.from(year, 11, 7).last(4).add(21).id]: 'Thanksgiving',
28+
[Day.from(year, 11, 7).last(4).add(22).id]: 'Day after Thanksgiving',
29+
[Day.from(year, 12, 24).id]: 'Christmas Eve',
30+
[Day.from(year, 12, 25).id]: 'Christmas',
31+
[Day.from(year, 12, 31).id]: "New Year's Eve"
32+
}
4133
return holidayCache[year]
4234
}
4335

0 commit comments

Comments
 (0)