From c89dad7c2c34d456e3face293cb4c18dd22e23ea Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 14 Oct 2022 11:45:33 -0400 Subject: [PATCH] Add links to google calendar/iCal --- package.json | 1 + pnpm-lock.yaml | 2 ++ src/common.ts | 11 +++++++---- src/index.ts | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 57e7909..529ba92 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@babel/runtime": "^7.19.0", "@fullcalendar/core": "^5.11.3", "@fullcalendar/icalendar": "^5.11.3", + "@fullcalendar/resource-common": "^5.11.3", "@fullcalendar/resource-timegrid": "^5.11.3", "@fullcalendar/resource-timeline": "^5.11.3", "@fullcalendar/timegrid": "^5.11.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 63051f8..eaf449e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,7 @@ specifiers: '@babel/runtime': ^7.19.0 '@fullcalendar/core': ^5.11.3 '@fullcalendar/icalendar': ^5.11.3 + '@fullcalendar/resource-common': ^5.11.3 '@fullcalendar/resource-timegrid': ^5.11.3 '@fullcalendar/resource-timeline': ^5.11.3 '@fullcalendar/timegrid': ^5.11.3 @@ -29,6 +30,7 @@ dependencies: '@babel/runtime': 7.19.0 '@fullcalendar/core': 5.11.3 '@fullcalendar/icalendar': 5.11.3 + '@fullcalendar/resource-common': 5.11.3 '@fullcalendar/resource-timegrid': 5.11.3 '@fullcalendar/resource-timeline': 5.11.3 '@fullcalendar/timegrid': 5.11.3 diff --git a/src/common.ts b/src/common.ts index cd907a8..445d17e 100644 --- a/src/common.ts +++ b/src/common.ts @@ -86,11 +86,14 @@ export const common_calendarOptions: CalendarOptions = { minute: '2-digit', hour12: false, }, - resources: Object.entries(shops).map(([shop, tools]) => { + resources: Object.entries(shops).map(([shop_name, shop]) => { return { - id: shop, - title: shop, - children: tools.children?.map((tool) => { + id: shop_name, + title: shop_name, + extendedProps: { + calendar: shop.calendar, + }, + children: shop.children?.map((tool) => { return { id: tool, title: tool, diff --git a/src/index.ts b/src/index.ts index e76e5cd..c7f9f08 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ import '@fullcalendar/core'; import { CalendarOptions, EventContentArg } from '@fullcalendar/core'; +import { ResourceLabelContentArg } from '@fullcalendar/resource-common'; import timeGridPlugin from '@fullcalendar/timegrid'; import resourceTimelinePlugin from '@fullcalendar/resource-timeline'; import { createElement } from 'preact'; @@ -24,6 +25,23 @@ const calendarOptions: CalendarOptions = { resourceTimeline: 'day', }, initialView: 'resourceTimeline', + resourceLabelContent: ( + arg: ResourceLabelContentArg, + h: typeof createElement + ) => { + const calendar = arg.resource.extendedProps.calendar; + if (calendar) { + const embed_link = `https://calendar.google.com/calendar/embed?ctz=America%2FNew_York&src=${calendar}`; + const ical_link = `https://calendar.google.com/calendar/ical/${calendar}/public/basic.ics`; + return h( + 'span', + null, + h('a', { href: embed_link }, arg.resource.title), + ' ', + h('a', { href: ical_link }, ' [iCal 📅]') + ); + } + }, eventContent: (arg: EventContentArg, h: typeof createElement) => { if (arg.view.type != 'resourceTimeline') { let resources = arg.event