-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEvent.ts
More file actions
43 lines (36 loc) · 1.41 KB
/
Event.ts
File metadata and controls
43 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as dto from './dto';
import * as moment from 'moment';
import CancelledEvent from './CancelledEvent';
import Countdown from './Countdown';
import CurrentEvent from './CurrentEvent';
import FutureEvent from './FutureEvent';
import PastEvent from './PastEvent';
import UiComponent from './UiComponent';
export default class Event implements UiComponent {
constructor(private _event: dto.Event,
private _canceledEvents: Array<number>) {
}
appendTo(entry: HTMLElement | null): void {
const secondsDiff = moment().diff(this._event.datetime, 'seconds');
if (this.isCancelled()) {
new CancelledEvent(this._event).appendTo(entry);
} else if (0 <= secondsDiff && secondsDiff < 4 * 60 * 60) {
new CurrentEvent(this._event).appendTo(entry);
} else if (secondsDiff >= 4 * 60 * 60) {
new PastEvent(this._event).appendTo(entry);
} else {
new FutureEvent(this._event).appendTo(entry);
}
const hashId = "#_" + this._event.timestamp();
if (window.location.hash == hashId) {
window.location.hash = "";
setTimeout(() => { window.location.hash = hashId; }, 0);
}
}
isCancelled(): boolean {
if (!this._canceledEvents) {
return false;
}
return this._canceledEvents.findIndex((c) => c == this._event.datetime.unix()) >= 0;
}
}