15
|
1 import { LitElement, css, html } from "lit";
|
|
2 import { customElement, property } from "lit/decorators.js";
|
20
|
3 import { sortBy, sortedUniqBy, uniqBy } from "lodash";
|
15
|
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-countdown")
|
|
12 export class FdCountdown extends LitElement {
|
|
13 static styles = [
|
|
14 shared,
|
|
15 css`
|
20
|
16 :host {
|
|
17 overflow: hidden;
|
|
18 }
|
15
|
19 ol {
|
|
20 list-style: none;
|
|
21 font-size: 16px;
|
|
22 }
|
|
23 span.d {
|
|
24 opacity: 0.5;
|
|
25 }
|
|
26 li:has(.until) {
|
|
27 color: #666;
|
|
28 }
|
|
29 li:has(.until-2d) {
|
|
30 color: #fff;
|
|
31 }
|
|
32 li:has(.until-7d) {
|
|
33 color: #ccc;
|
|
34 }
|
|
35 li:has(.until-30d) {
|
|
36 color: #999;
|
|
37 }
|
|
38 li:has(.until)::before {
|
|
39 display: inline-block;
|
|
40 width: 1.4em;
|
|
41 content: "";
|
|
42 }
|
|
43 li:has(.until-2d)::before {
|
|
44 content: "🌕";
|
|
45 }
|
|
46 li:has(.until-7d)::before {
|
|
47 content: "🌙";
|
|
48 }
|
|
49 li:has(.until-30d)::before {
|
|
50 content: "🌑";
|
|
51 }
|
|
52 `,
|
|
53 ];
|
|
54 @property() evs: DisplayEvent[];
|
|
55 constructor() {
|
|
56 super();
|
|
57 this.evs = [];
|
|
58 this.load();
|
|
59 setInterval(this.load.bind(this), 5 * 60 * 1000);
|
|
60 }
|
|
61 async load() {
|
|
62 const store = new Store();
|
|
63 const r = await fetchGraph("/gcalendarwatch/graph/calendar/countdown");
|
|
64 await parseGraph(r, (store: Store) => {
|
|
65 const graph = namedNode(EV + "gcalendar");
|
|
66 this.evs = [];
|
|
67 store.getSubjects(namedNode(RDF + "type"), namedNode(EV + "Event"), graph).forEach((ev: Quad_Subject) => {
|
|
68 const de = new DisplayEvent(store, graph, ev);
|
|
69 this.evs = [...this.evs, de];
|
|
70 });
|
20
|
71 this.evs = sortedUniqBy(sortBy(this.evs, "start"), (de) => de.start + de.title);
|
15
|
72 });
|
|
73 }
|
|
74 render() {
|
17
|
75 return html`<h1>Coming Soon</h1>
|
15
|
76 <ol>
|
|
77 ${this.evs.map((d) => html`<li>In ${d.inHowLong()}, ${d.title}</li>`)}
|
|
78 </ol> `;
|
|
79 }
|
|
80 }
|