rspace-online/modules/rcal/applets.ts

39 lines
1.3 KiB
TypeScript

/**
* rCal applet definitions — Next Event.
*/
import type { AppletDefinition, AppletLiveData } from "../../shared/applet-types";
const nextEvent: AppletDefinition = {
id: "next-event",
label: "Next Event",
icon: "📅",
accentColor: "#2563eb",
ports: [
{ name: "events-in", type: "json", direction: "input" },
{ name: "event-out", type: "json", direction: "output" },
],
renderCompact(data: AppletLiveData): string {
const { snapshot } = data;
const title = (snapshot.title as string) || "No upcoming events";
const time = (snapshot.time as string) || "";
const location = (snapshot.location as string) || "";
return `
<div>
<div style="font-size:13px;font-weight:600;margin-bottom:4px">${title}</div>
${time ? `<div style="font-size:11px;color:#60a5fa;margin-bottom:2px">🕐 ${time}</div>` : ""}
${location ? `<div style="font-size:11px;color:#94a3b8">📍 ${location}</div>` : ""}
${!time && !location ? `<div style="font-size:11px;color:#94a3b8;font-style:italic;margin-top:8px;text-align:center">Connect a calendar feed</div>` : ""}
</div>
`;
},
onInputReceived(portName, value, ctx) {
if (portName === "events-in" && Array.isArray(value) && value.length > 0) {
ctx.emitOutput("event-out", value[0]);
}
},
};
export const calApplets: AppletDefinition[] = [nextEvent];