Mercurial > code > home > repos > front-door-display
view src/FdCountdown.ts @ 21:a90cb6927c7d default tip
fix countdown queries. Display "now" instead of "In -0.4 hours"
author | drewp@bigasterisk.com |
---|---|
date | Sat, 07 Sep 2024 17:47:36 -0700 |
parents | e8c90d893919 |
children |
line wrap: on
line source
import { LitElement, css, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { sortBy, sortedUniqBy, uniqBy } from "lodash"; import { DataFactory, Quad_Subject, Store } from "n3"; import { shared } from "./shared"; import { EV, fetchGraph, parseGraph, RDF } from "./parseRdf"; import { DisplayEvent } from "./DisplayEvent"; const { namedNode } = DataFactory; @customElement("fd-countdown") export class FdCountdown extends LitElement { static styles = [ shared, css` :host { overflow: hidden; } ol { list-style: none; font-size: 16px; } span.d { opacity: 0.5; } li:has(.until) { color: #666; } li:has(.until-2d) { color: #fff; } li:has(.until-7d) { color: #ccc; } li:has(.until-30d) { color: #999; } li:has(.until)::before { display: inline-block; width: 1.4em; content: ""; } li:has(.until-2d)::before { content: "🌕"; } li:has(.until-7d)::before { content: "🌙"; } li:has(.until-30d)::before { content: "🌑"; } `, ]; @property() evs: DisplayEvent[]; constructor() { super(); this.evs = []; this.load(); setInterval(this.load.bind(this), 5 * 60 * 1000); } async load() { const store = new Store(); const r = await fetchGraph("/gcalendarwatch/graph/calendar/countdown"); await parseGraph(r, (store: Store) => { const graph = namedNode(EV + "gcalendar"); this.evs = []; store.getSubjects(namedNode(RDF + "type"), namedNode(EV + "Event"), graph).forEach((ev: Quad_Subject) => { const de = new DisplayEvent(store, graph, ev); this.evs = [...this.evs, de]; }); this.evs = sortedUniqBy(sortBy(this.evs, "start"), (de) => de.start + de.title); }); } render() { return html`<h1>Coming Soon</h1> <ol> ${this.evs.map((d) => html`<li>${d.inHowLong()}, ${d.title}</li>`)} </ol> `; } }