Skip to content

Commit ff17212

Browse files
committed
(#96) Turn EventsForDay into DayOff when there are no events for day
1 parent 99da9c3 commit ff17212

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

ts/Event.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ export default class Event implements UiComponent {
2626
}
2727
}
2828

29-
isPast(): boolean {
30-
if (this.isCancelled()) {
31-
return moment().diff(this._event.datetime, 'seconds') > 0;
32-
} else {
33-
return moment().diff(this._event.datetime, 'seconds') >= 4 * 60 * 60;
34-
}
35-
}
36-
3729
isCancelled(): boolean {
3830
return this._canceldEvents.findIndex((c) => c == this._event.datetime.unix()) >= 0;
3931
}

ts/EventsForCurrentPeriod.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import * as html from './html';
33
import * as list from './list';
44
import * as moment from 'moment';
55
import ComponentsList from './ComponentsList';
6+
import ComponentsArray from './ComponentsArray';
67
import Event from './Event';
78
import EventsForDay from './EventsForDay'
89
import UiComponent from './UiComponent';
10+
import DayOff from './DayOff';
911

1012
export default class EventsForCurrentPeriod implements UiComponent {
1113
constructor(private _state: dto.State) {
@@ -14,22 +16,15 @@ export default class EventsForCurrentPeriod implements UiComponent {
1416
appendTo(entry: HTMLElement | null): void {
1517
let day = moment().clone().utc().startOf('day').subtract(2, 'days')
1618

17-
let events = new list.ConcatLists(
18-
new list.MappedList(
19-
new list.ListOfNumbersRange(1, 16),
20-
(_, i) => new EventsForDay(
21-
this._state,
22-
day.clone().add(i, 'days').format("YYYY-MM-DD"),
23-
)
24-
).asArray()
25-
);
26-
2719
new html.Div(
2820
new ComponentsList(
29-
new list.ConcatLists([
30-
new list.SlicedList(new list.FilteredList(events, (e) => e.isPast()), -2),
31-
new list.FilteredList(events, (e) => !e.isPast())
32-
])
21+
new list.MappedList(
22+
new list.ListOfNumbersRange(1, 16),
23+
(_, i) => new EventsForDay(
24+
this._state,
25+
day.clone().add(i, 'days').format("YYYY-MM-DD"),
26+
)
27+
)
3328
),
3429
{"class": "events"}
3530
).appendTo(entry)

ts/EventsForDay.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@ import * as list from './list';
33
import * as moment from 'moment';
44
import Event from './Event'
55
import UiComponent from './UiComponent';
6+
import ComponentsArray from './ComponentsArray';
7+
import DayOff from './DayOff';
68

79
// TODO(#69): EventsForDay can be a concatenation of RecurringEventsForDay and ScheduledEventsForDay objects
8-
export default class EventsForDay implements UiComponent, list.List<Event> {
10+
export default class EventsForDay implements UiComponent {
911
constructor(private _state: dto.State,
1012
private _date: string) {
1113
}
1214

1315
appendTo(entry: HTMLElement | null): void {
14-
this.asArray().forEach((e) => e.appendTo(entry))
16+
const events = this._asArray();
17+
18+
if (events.length > 0) {
19+
new ComponentsArray(events).appendTo(entry);
20+
} else {
21+
new DayOff(this._state, this._date).appendTo(entry);
22+
}
1523
}
1624

17-
asArray(): Array<Event> {
25+
_asArray(): Array<Event> {
1826
let weekday = moment.tz(this._date, this._state.timezone).isoWeekday();
1927
return this._state.projects
2028
.filter(

0 commit comments

Comments
 (0)