summaryrefslogtreecommitdiffstats
path: root/VegaData/wwwroot/index.js
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-06 12:06:46 +0200
committerivar <i@oiee.no>2025-10-06 12:06:46 +0200
commitf18f3fee8844df98a30c2d248dfca04643dd4365 (patch)
tree599c1b6a97777a84cdcd7fe8333f4718d2e55c85 /VegaData/wwwroot/index.js
downloadvegadata-f18f3fee8844df98a30c2d248dfca04643dd4365.tar.xz
vegadata-f18f3fee8844df98a30c2d248dfca04643dd4365.zip
Initial
Diffstat (limited to 'VegaData/wwwroot/index.js')
-rw-r--r--VegaData/wwwroot/index.js72
1 files changed, 72 insertions, 0 deletions
diff --git a/VegaData/wwwroot/index.js b/VegaData/wwwroot/index.js
new file mode 100644
index 0000000..deb9552
--- /dev/null
+++ b/VegaData/wwwroot/index.js
@@ -0,0 +1,72 @@
+import { Temporal } from "temporal-polyfill"
+import { t } from "./framework.js";
+
+let _
+async function getShows() {
+ if (_) return _
+ const response = await fetch("/shows");
+ _ = await response.json();
+ return _
+}
+
+const ulShows = document.getElementById("ulShows");
+const search = document.getElementById("search");
+const renderShowsBtn = document.getElementById("renderShowsBtn");
+const { timeZoneId: tzId } = Temporal.Now.zonedDateTimeISO();
+renderShowsBtn.addEventListener("click", () => {
+ renderShows()
+ search.value = ""
+});
+
+function dateString(date, small = false) {
+ if (small) return Temporal.Instant.from(date).toZonedDateTimeISO(tzId).toPlainDateTime().toLocaleString('nb-NO', { weekday: "long", calendar: 'gregory', hour: "2-digit", minute: "2-digit", month: 'long', day: 'numeric' })
+ return Temporal.Instant.from(date).toZonedDateTimeISO(tzId).toPlainDateTime().toLocaleString('nb-NO', { weekday: "long", calendar: 'gregory', hour: "2-digit", minute: "2-digit", era: 'long', year: 'numeric', month: 'long', day: 'numeric' })
+}
+
+search.addEventListener("input", e => renderShows(e.currentTarget.value))
+
+async function renderShows(query) {
+ query = query?.trim()
+ const searchParams = new URLSearchParams(location.search);
+ if (!query && searchParams.has("q")) query = searchParams.get("q")
+ searchParams.set("q", query)
+ let lis = [];
+
+ const shows = (await getShows()).reduce((acc, curr) => {
+ const key = curr.title;
+ if (!acc[key]) {
+ acc[key] = [];
+ }
+ acc[key].push(curr);
+ return acc;
+ }, {});
+
+ async function share(show) {
+ const shareData = {
+ title: `${show.title} ${dateString(show.startDateTime, true)} på vega`,
+ text: "",
+ url: `#${show.title}-${show.startDateTime}`,
+ };
+ await navigator.share(shareData);
+ }
+
+ for (const showKey of Object.keys(shows).sort((a, b) => a.localeCompare(b))) {
+ const times = shows[showKey].sort((a, b) => Temporal.PlainDate.compare(Temporal.PlainDate.from(a.startDateTime), Temporal.PlainDate.from(b.startDateTime)))
+ if (query && !showKey.toLowerCase().match(query.toLowerCase())) continue
+ if (times.every(e => e.ticketUrl === "")) continue
+ lis.push(t("li", { class: "show", id: showKey }, [t("span", { class: "title italic" }, showKey), t("ul", undefined, [t("li", undefined,
+ times.filter(e => e.ticketUrl !== "").map(e => t("li", { class: `time time-${e.id}`, id: `${showKey}-${e.startDateTime}` }, [t("a", undefined, [
+ t("div", undefined, [
+ t("span", undefined, dateString(e.startDateTime)),
+ t("span", undefined, `${e.scene} - ${e.tags.join(", ")}`),
+ t("div", { class: "actions" }, [
+ t("a", { href: e.ticketUrl }, "Billetter"),
+ t("button", { onclick: () => share(e) }, "Del tid")
+ ])
+ ])
+ ])])))])]))
+ }
+ ulShows.replaceChildren(...lis);
+}
+renderShows()
+