aboutsummaryrefslogtreecommitdiffstats
path: root/VegaData
diff options
context:
space:
mode:
Diffstat (limited to 'VegaData')
-rw-r--r--VegaData/Program.cs2
-rw-r--r--VegaData/wwwroot/index.js130
2 files changed, 80 insertions, 52 deletions
diff --git a/VegaData/Program.cs b/VegaData/Program.cs
index aa475a7..2ab6bb2 100644
--- a/VegaData/Program.cs
+++ b/VegaData/Program.cs
@@ -73,7 +73,7 @@ class DataWorker(IServiceScopeFactory serviceScopeFactory) : BackgroundService
if (refreshData) {
db.Shows.RemoveRange(db.Shows);
await db.SaveChangesAsync(ct);
- File.Copy("data/main.db", $"data/main-{DateTime.UnixEpoch}.db");
+ File.Copy("data/main.db", $"data/main-{DateTime.UtcNow.Ticks}.db");
}
var count = await db.Shows.CountAsync(ct);
diff --git a/VegaData/wwwroot/index.js b/VegaData/wwwroot/index.js
index cde0974..df78dad 100644
--- a/VegaData/wwwroot/index.js
+++ b/VegaData/wwwroot/index.js
@@ -1,74 +1,102 @@
-import { Temporal } from "temporal-polyfill"
+import { Temporal } from "temporal-polyfill";
import { t } from "./framework.js";
-let _
+let _;
+
async function getShows() {
- if (_) return _
- const response = await fetch("/shows");
- _ = await response.json();
- return _
+ 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();
+const {timeZoneId: tzId} = Temporal.Now.zonedDateTimeISO();
renderShowsBtn.addEventListener("click", () => {
- renderShows()
- search.value = ""
+ renderShows();
+ search.value = "";
});
function dateString(date, small = false) {
- console.log(date);
+ console.log(date);
- 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' })
+ 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))
+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 = [];
+ 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;
- }, {});
+ 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);
- }
+ 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", { title: e.startDateTime }, 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);
+ 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", {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")
+ ])
+ ])
+ ])])))])]));
+ }
+ ulShows.replaceChildren(...lis);
}
+
renderShows()