Skip to content

Commit

Permalink
Show calendar with button to synchronize
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Jan 13, 2025
1 parent f565a64 commit 01a7952
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions httpstatic/chan_calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ import {lindt, replace_content, DOM, on} from "https://rosuav.github.io/choc/fac
const {A, BUTTON, H2, IMG, LI, P, SPAN, UL} = lindt; //autoimport
import {simpleconfirm} from "$$static||utils.js$$";

function show_calendar(events, pfx) {
console.log("Events", events);
export function sockmsg_showcalendar(msg) {
console.log("Events", msg.events);
replace_content("#calendar", [
H2([pfx, events.summary]),
P(events.description),
UL(events.items.map(item => item.status !== "cancelled" && LI([ //TODO: Or should it check that status *does* equal confirmed?
H2(["Calendar: ", msg.events.summary]),
P(msg.events.description),
P(BUTTON({id: "calsync", "data-id": msg.calendarid}, "Synchronize with Twitch")),
UL(msg.events.items.map(item => item.status !== "cancelled" && LI([ //TODO: Or should it check that status *does* equal confirmed?
"From " + item.start.dateTime + " to " + item.end.dateTime + ": ",
A({href: item.htmlLink}, item.summary),
]))),
]);
}

export function sockmsg_showcalendar(msg) {
show_calendar(msg.events, "PREVIEW: ");
if (msg.calendarid === DOM("[name=calendarid]").value)
replace_content("#calsync", "Synchronize").dataset.calendarid = msg.calendarid;
}

export function render(data) {
//If you're logged in, replace the login button with your pfp and name.
if (data.google_id) replace_content("#googlestatus", [
Expand All @@ -38,15 +33,8 @@ export function render(data) {
]))));
}

on("click", ".showcal", e => {
const calendarid = e.match.closest_data("id");
ws_sync.send({cmd: "fetchcal", calendarid});
});

on("click", "#calsync", e => {
const calendarid = DOM("[name=calendarid]").value;
ws_sync.send({cmd: (e.match.dataset.calendarid === calendarid) ? "synchronize" : "fetchcal", calendarid});
});
on("click", ".showcal", e => ws_sync.send({cmd: "fetchcal", calendarid: e.match.closest_data("id")}));
on("click", "#calsync", e => ws_sync.send({cmd: "synchronize", calendarid: e.match.closest_data("id")}));

on("click", "#googleoauth", e => ws_sync.send({cmd: "googlelogin"}));
export function sockmsg_googlelogin(msg) {window.open(msg.uri, "login");}

0 comments on commit 01a7952

Please sign in to comment.