15
|
1 import { LitElement, css, html } from "lit";
|
|
2 import { customElement, property } from "lit/decorators.js";
|
|
3 import { sortBy } from "lodash";
|
|
4 import { DataFactory, Quad_Subject, Store } from "n3";
|
|
5 import { shared } from "./shared";
|
|
6 import { EV, fetchGraph, parseGraph, RDF } from "./parseRdf";
|
|
7 import { DisplayEvent } from "./DisplayEvent";
|
|
8
|
|
9 const { namedNode } = DataFactory;
|
|
10
|
|
11 @customElement("fd-upcoming-events")
|
|
12 export class UpcomingEvents extends LitElement {
|
|
13 static styles = [
|
|
14 shared,
|
|
15 css`
|
|
16 ol {
|
|
17 list-style-type: circle;
|
|
18 font-size: 16px;
|
|
19 background: #cd66bb2e;
|
|
20 padding: 9px;
|
|
21 width: fit-content;
|
|
22 position: relative;
|
|
23 top: -21px;
|
|
24 border-radius: 14px;
|
|
25 }
|
|
26 span.d {
|
|
27 opacity: 0.5;
|
|
28 }
|
|
29 `,
|
|
30 ];
|
|
31 @property() evs: DisplayEvent[];
|
|
32 constructor() {
|
|
33 super();
|
|
34 this.evs = [];
|
|
35 this.load();
|
|
36 setInterval(this.load.bind(this), 5 * 60 * 1000);
|
|
37 }
|
|
38
|
|
39 async load() {
|
|
40 const r = await fetchGraph("/gcalendarwatch/graph/calendar/upcoming");
|
|
41 await parseGraph(r, (store: Store) => {
|
|
42 const graph = namedNode(EV + "gcalendar");
|
|
43 this.evs = [];
|
|
44 store.getSubjects(namedNode(RDF + "type"), namedNode(EV + "Event"), graph).forEach((ev: Quad_Subject) => {
|
|
45 const de = new DisplayEvent(store, graph, ev);
|
|
46 if (de.show()) {
|
|
47 this.evs = [...this.evs, de];
|
|
48 }
|
|
49 });
|
|
50 this.evs = sortBy(this.evs, "start");
|
|
51 });
|
|
52 }
|
|
53
|
|
54 render() {
|
|
55 return html`
|
|
56 <h1 data-text="Calendar">Calendar</h1>
|
|
57 <ol>
|
|
58 ${this.evs.map((d) => html`<li><span class="date">${d.shortDate()}</span> ${d.title}</li>`)}
|
|
59 </ol>
|
|
60 `;
|
|
61 }
|
|
62 }
|