annotate src/main.ts @ 14:899f12179b85

upgrade lit
author drewp@bigasterisk.com
date Thu, 06 Jun 2024 17:51:38 -0700
parents deb0c25655eb
children 20d1fa4250c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
1 import { addHours, endOfToday, endOfTomorrow, format, isAfter, isWithinInterval, parseISO, startOfToday } from "date-fns";
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
2 import { LitElement, TemplateResult, css, html } from "lit";
1
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
3 import { customElement, property } from "lit/decorators.js";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
4 import { sortBy } from "lodash";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
5 import { DataFactory, NamedNode, Parser, Quad_Predicate, Quad_Subject, Store, Term } from "n3";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
6 import { hideFeeds, hideTitles } from "./private";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
7 import { shared } from "./shared";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
8 const { namedNode } = DataFactory;
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
9 export { FdClock } from "./FdClock";
1
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
10 export { WeekGuide } from "./WeekGuide";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
11 const EV = "http://bigasterisk.com/event#";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
12 const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
13
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
14 function getLiteral(store: Store, graph: Term, subj: Quad_Subject, pred: Quad_Predicate, missing: string | null): string {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
15 let out = null;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
16 store.getObjects(subj, pred, graph).forEach((attr) => {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
17 out = attr.value;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
18 });
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
19 if (!out) {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
20 if (missing === null) {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
21 throw new Error();
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
22 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
23 return missing;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
24 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
25 return out;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
26 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
27
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
28 class DisplayEvent {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
29 constructor(private store: Store, private graph: Term, public uri: Quad_Subject) {}
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
30 get title(): string {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
31 return getLiteral(this.store, this.graph, this.uri, namedNode(EV + "title"), "(unnamed)");
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
32 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
33 get start(): string {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
34 return getLiteral(this.store, this.graph, this.uri, namedNode(EV + "start"), null);
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
35 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
36 get feed(): NamedNode {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
37 return namedNode(getLiteral(this.store, this.graph, this.uri, namedNode(EV + "feed"), null));
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
38 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
39 shortDate(): TemplateResult {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
40 const t = parseISO(this.start);
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
41 return html`<span class="d">${format(t, "EEE, MMM d,")}</span> <span class="t">${format(t, "HH:mm")}</span>`;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
42 }
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
43 inHowLong(): TemplateResult {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
44 // returns start()-now, like '5 days'
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
45 const t = parseISO(this.start).valueOf();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
46 const now = Date.now();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
47 const daysAway = (t - now) / 1000 / 86400;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
48 const prec = daysAway < 2 ? 1 : 0;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
49 const cls = "until " + (daysAway < 2 ? "until-2d" : daysAway < 7 ? "until-7d" : daysAway < 30 ? "until-1mo" : "");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
50 return html`<span class="${cls}">${daysAway.toFixed(prec)} days</span>`;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
51 }
1
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
52 show(): boolean {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
53 const now = new Date();
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
54 const t = parseISO(this.start);
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
55
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
56 const start = startOfToday();
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
57 let end = endOfToday();
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
58 if (isAfter(now, addHours(startOfToday(), 18))) {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
59 end = endOfTomorrow();
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
60 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
61
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
62 return isWithinInterval(t, { start, end }) && !hideTitles.has(this.title) && !hideFeeds.has(this.feed.value);
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
63 }
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
64 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
65
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
66 async function fetchGraph(url: string) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
67 return await fetch(url, {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
68 method: "GET",
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
69 headers: {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
70 Accept: "application/json",
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
71 "X-Pomerium-Authorization": document.cookie.substring(document.cookie.indexOf("=") + 1),
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
72 },
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
73 });
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
74 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
75
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
76 async function parseGraph(r: Response, done: (store: Store) => void) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
77 const store = new Store();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
78 const n3txt = await r.text();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
79 const parser = new Parser({ format: "application/trig" });
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
80 parser.parse(n3txt, (error, quad, prefixes) => {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
81 if (quad) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
82 store.addQuad(quad);
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
83 } else {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
84 done(store);
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
85 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
86 });
1
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
87 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
88
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
89 @customElement("fd-upcoming-events")
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
90 export class UpcomingEvents extends LitElement {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
91 static styles = [
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
92 shared,
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
93 css`
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
94 ol {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
95 list-style-type: circle;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
96 font-size: 16px;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
97 background: #cd66bb2e;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
98 padding: 9px;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
99 width: fit-content;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
100 position: relative;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
101 top: -21px;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
102 border-radius: 14px;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
103 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
104 span.d {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
105 opacity: 0.5;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
106 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
107 `,
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
108 ];
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
109 @property() evs: DisplayEvent[];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
110 constructor() {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
111 super();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
112 this.evs = [];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
113 this.load();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
114 setInterval(this.load.bind(this), 5 * 60 * 1000);
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
115 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
116
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
117 async load() {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
118 const r = await fetchGraph("/gcalendarwatch/graph/calendar/upcoming");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
119 await parseGraph(r, (store: Store) => {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
120 const graph = namedNode(EV + "gcalendar");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
121 this.evs = [];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
122 store.getSubjects(namedNode(RDF + "type"), namedNode(EV + "Event"), graph).forEach((ev: Quad_Subject) => {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
123 const de = new DisplayEvent(store, graph, ev);
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
124 if (de.show()) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
125 this.evs = [...this.evs, de];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
126 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
127 });
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
128 this.evs = sortBy(this.evs, "start");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
129 });
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
130 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
131
1
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
132 render() {
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
133 return html`
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
134 <h1 data-text="Calendar">Calendar</h1>
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
135 <ol>
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
136 ${this.evs.map((d) => html`<li><span class="date">${d.shortDate()}</span> ${d.title}</li>`)}
1
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
137 </ol>
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
138 `;
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
139 }
33178e5e356e old updates
drewp@bigasterisk.com
parents:
diff changeset
140 }
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
141
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
142 @customElement("fd-countdown")
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
143 export class FdCountdown extends LitElement {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
144 static styles = [
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
145 shared,
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
146 css`
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
147 ol {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
148 list-style: none;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
149 font-size: 16px;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
150 background: #cd66bb2e;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
151 padding: 9px;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
152 width: fit-content;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
153 position: relative;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
154 top: -21px;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
155 border-radius: 14px;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
156 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
157 span.d {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
158 opacity: 0.5;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
159 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
160 li:has(.until) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
161 color: #666;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
162 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
163 li:has(.until-2d) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
164 color: #fff;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
165 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
166 li:has(.until-7d) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
167 color: #ccc;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
168 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
169 li:has(.until-30d) {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
170 color: #999;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
171 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
172 li:has(.until)::before {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
173 display: inline-block;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
174 width: 1.4em;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
175 content: "";
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
176 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
177 li:has(.until-2d)::before {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
178 content: "🌕";
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
179 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
180 li:has(.until-7d)::before {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
181 content: "🌙";
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
182 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
183 li:has(.until-30d)::before {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
184 content: "🌑";
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
185 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
186 `,
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
187 ];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
188 @property() evs: DisplayEvent[];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
189 constructor() {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
190 super();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
191 this.evs = [];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
192 this.load();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
193 setInterval(this.load.bind(this), 5 * 60 * 1000);
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
194 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
195 async load() {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
196 const store = new Store();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
197 const r = await fetchGraph("/gcalendarwatch/graph/calendar/countdown");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
198 await parseGraph(r, (store: Store) => {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
199 const graph = namedNode(EV + "gcalendar");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
200 this.evs = [];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
201 store.getSubjects(namedNode(RDF + "type"), namedNode(EV + "Event"), graph).forEach((ev: Quad_Subject) => {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
202 const de = new DisplayEvent(store, graph, ev);
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
203 this.evs = [...this.evs, de];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
204 });
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
205 this.evs = sortBy(this.evs, "start");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
206 });
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
207 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
208 render() {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
209 return html`<h1 data-text="Coming Soon">Coming Soon</h1>
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
210 <ol>
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
211 ${this.evs.map((d) => html`<li>In ${d.inHowLong()}, ${d.title}</li>`)}
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
212 </ol> `;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
213 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents: 1
diff changeset
214 }