Added Event class, which represents a single event in the calendar
This commit is contained in:
parent
e0ca747cf2
commit
c2b6bb6b8e
17
src/Events/Event.ts
Normal file
17
src/Events/Event.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Event as _Event } from "../types";
|
||||||
|
|
||||||
|
export default class Event implements _Event {
|
||||||
|
date: Date;
|
||||||
|
title: string;
|
||||||
|
text?: string;
|
||||||
|
icon?: string;
|
||||||
|
backgroundColor?: string;
|
||||||
|
|
||||||
|
constructor({ date, title, text, icon, backgroundColor }) {
|
||||||
|
this.date = new Date(date);
|
||||||
|
this.title = title;
|
||||||
|
this.text = text;
|
||||||
|
this.icon = icon;
|
||||||
|
this.backgroundColor = backgroundColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/Events/index.ts
Normal file
15
src/Events/index.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import Event from "./Event";
|
||||||
|
|
||||||
|
export default class Events {
|
||||||
|
sortedEvents: Event[];
|
||||||
|
|
||||||
|
constructor(events: Event[]) {
|
||||||
|
this.sortedEvents = this.processEvents(events);
|
||||||
|
}
|
||||||
|
|
||||||
|
processEvents(events): Event[] {
|
||||||
|
const _events = events.map((event) => new Event(event));
|
||||||
|
|
||||||
|
return _events.sort((a, b) => a.date - b.date);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user