aboutsummaryrefslogtreecommitdiffstats
path: root/VegaData/wwwroot/index.js
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-07 23:19:14 +0200
committerivar <i@oiee.no>2025-10-07 23:19:14 +0200
commit3d1d21ed0ab9c2a15a964e3d86104279e0d2cc60 (patch)
tree598f7315bfd446c6017a993c9b2691d47eaa0c0f /VegaData/wwwroot/index.js
parent46a1f50c0485b50267d5047f11282213c698491b (diff)
downloadvegadata-3d1d21ed0ab9c2a15a964e3d86104279e0d2cc60.tar.xz
vegadata-3d1d21ed0ab9c2a15a964e3d86104279e0d2cc60.zip
as
Diffstat (limited to 'VegaData/wwwroot/index.js')
-rw-r--r--VegaData/wwwroot/index.js122
1 files changed, 74 insertions, 48 deletions
diff --git a/VegaData/wwwroot/index.js b/VegaData/wwwroot/index.js
index 29fbaeb..1a07ccb 100644
--- a/VegaData/wwwroot/index.js
+++ b/VegaData/wwwroot/index.js
@@ -1,12 +1,10 @@
import { Temporal } from "temporal-polyfill";
-import { t } from "./framework.js";
+import { gqp, sqp, t } from "./framework.js";
let _;
async function getShows() {
- if (_) {
- return _;
- }
+ if (_) return _;
const response = await fetch("/shows");
_ = await response.json();
return _;
@@ -15,46 +13,56 @@ async function getShows() {
const ulShows = document.getElementById("ulShows");
const search = document.getElementById("search");
const renderShowsBtn = document.getElementById("renderShowsBtn");
-const tzId = Temporal.Now.timeZoneId();
+
renderShowsBtn.addEventListener("click", () => {
- renderShows();
+ renderShows("");
search.value = "";
});
function dateString(date, small = false) {
- date = date + "+00:00";
- if (small) {
- return Temporal.Instant.from(date).toPlainDateTime().toLocaleString("nb-NO", {
- weekday: "long",
- calendar: "gregory",
- hour: "2-digit",
- minute: "2-digit",
- month: "long",
- day: "numeric"
- });
- }
- return Temporal.Instant.from(date).toPlainDateTime().toLocaleString("nb-NO", {
+ const instant = Temporal.Instant.from(`${date}Z`)
+ const stringOptions = {
weekday: "long",
- calendar: "gregory",
hour: "2-digit",
+ timeZone: "UTC",
minute: "2-digit",
- era: "long",
- year: "numeric",
month: "long",
+ calendar: "gregory",
day: "numeric"
+ }
+
+ if (small) {
+ return instant.toLocaleString("nb-NO", stringOptions);
+ }
+
+ return instant.toLocaleString("nb-NO", {
+ year: "numeric",
+ era: "long",
+ ...stringOptions
});
}
+function copyLink(e) {
+ if ("clipboard" in navigator) {
+ navigator.clipboard.writeText(`${location.origin}/index.html#${urlId(e)}`)
+ }
+}
+
+function vegascene(e) {
+ if (e.movieVersion.startsWith("KUL")) return `https://www.vegascene.no/teater/${e.movieVersion}`
+ return `https://www.vegascene.no/film/${e.movieVersion}`
+}
+
+if (gqp("q")) search.value = gqp("q")
search.addEventListener("input", e => renderShows(e.currentTarget.value));
-async function renderShows(query) {
+function urlId(e) {
+ return encodeURIComponent(`${e.movieVersion}-${e.startDateTime}`)
+}
+
+async function renderShows(query = search.value) {
query = query?.trim();
- const searchParams = new URLSearchParams(location.search);
- if (!query && searchParams.has("q")) {
- query = searchParams.get("q");
- }
- searchParams.set("q", query);
- let lis = [];
+ sqp({ q: query ?? "" })
const shows = (await getShows()).reduce((acc, curr) => {
const key = curr.title;
@@ -68,34 +76,52 @@ async function renderShows(query) {
async function share(show) {
const shareData = {
title: `${show.title} ${dateString(show.startDateTime, true)} på vega`,
- text: "",
- url: `#${show.title}-${show.startDateTime}`,
+ url: urlId(show),
};
await navigator.share(shareData);
}
+ const lis = [];
+
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;
+ const times = shows[showKey].sort((a, b) => Temporal.PlainDate.compare(Temporal.PlainDate.from(a.startDateTime), Temporal.PlainDate.from(b.startDateTime)))
+ if (query) {
+ const words = [showKey.toLowerCase()]
+ for (const time of times) {
+ words.push(dateString(time.startDateTime))
+ words.push(time.scene)
+ words.push(time.tags.join(" "))
+ }
+ if (!words.some((word) => word.match(query.toLowerCase()))) 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", { title: e.startDateTime }, dateString(e.startDateTime)),
- t("span", undefined, `${e.scene} - ${[e.type, ...e.tags].join(", ")}`),
- t("div", { class: "actions" }, [
- t("a", { href: e.ticketUrl }, "Billetter"),
- t("button", { onclick: () => share(e) }, "Del tid")
- ])
+
+ 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 => {
+ const tagLine = `${e.scene} - ${[e.type, ...e.tags].join(", ")}`
+ return t("li", { class: `time time-${e.id}`, id: urlId(e) }, [
+ t("div", undefined, [
+ t("span", { title: e.startDateTime }, dateString(e.startDateTime)),
+ t("span", undefined, tagLine),
+ t("div", { class: "actions" }, [
+ t("a", { href: e.ticketUrl }, "Billetter"),
+ "share" in navigator ? t("button", { onclick: () => share(e) }, "Del tid") : null,
+ t("button", { onclick: () => copyLink(e) }, "Kopier lenke"),
+ t("a", { href: vegascene(e) }, "Åpne på vegascene.no")
+ ])
+ ])
+ ])
+ }))
])
- ])])))])]));
+ ])
+ )
}
- ulShows.replaceChildren(...lis);
+
+ if (!lis.length) ulShows.replaceChildren(...[t("i", undefined, "Dessverre")])
+ else ulShows.replaceChildren(...lis);
}
renderShows();
-