From 327b322b9583f760cd02ddad7a2a8890df26cc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 23 Jun 2022 01:39:08 +0200 Subject: work --- static/components/vevent.ts | 58 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'static/components/vevent.ts') diff --git a/static/components/vevent.ts b/static/components/vevent.ts index 5852a2ff..abf0f4c0 100644 --- a/static/components/vevent.ts +++ b/static/components/vevent.ts @@ -12,12 +12,13 @@ abstract class ComponentVEvent extends HTMLElement { template: HTMLTemplateElement | null uid: string + instance: string | null - constructor(uid?: string) { + constructor(uid?: string, instance?: string) { super(); this.template = document.getElementById(this.tagName.toLowerCase()) as HTMLTemplateElement | null - let real_uid; + let real_uid, real_instance; if (uid) { // console.log('Got UID directly'); @@ -29,6 +30,7 @@ abstract class ComponentVEvent extends HTMLElement { // console.log('Had UID as direct attribute'); real_uid = this.dataset.uid; } else { + /* TODO when is this case relevant? */ let el = this.closest('[data-uid]') if (el) { // console.log('Found UID higher up in the tree'); @@ -48,7 +50,32 @@ abstract class ComponentVEvent extends HTMLElement { this.uid = real_uid; this.dataset.uid = real_uid; - vcal_objects.get(this.uid)?.register(this); + if (instance) { + real_instance = instance + } else { + if (this.dataset.instance) { + real_instance = this.dataset.instance + } else { + let el = this.closest('[data-instance]') + if (el) { + real_instance = (el as HTMLElement).dataset.instance + if (real_instance === undefined) { + real_instance = null; + } + } else { + real_instance = null + } + } + } + this.instance = real_instance; + if (real_instance) { + this.dataset.instance = real_instance; + } + + /* TODO */ + /* Here, choose different rules depending on if we are repeating or not */ + + vcal_objects.get(this.getKey())?.register(this); /* We DON'T have a redraw here in the general case, since the HTML rendered server-side should be fine enough for us. @@ -56,12 +83,27 @@ abstract class ComponentVEvent extends HTMLElement { should take care of that some other way */ } - connectedCallback() { + getKey(): string { let uid = this.dataset.uid - if (uid) { - let v = vcal_objects.get(uid) - if (v) this.redraw(v); - } + // let instance_id = ev.getProperty('dtstart')!.format('~Y-~m-~dT~H:~M:~S') + let instance = this.dataset.instance + if (!uid) throw new Error("UID missing"); + let key = uid; + /* NOTE proper composite keys would be nice, since this can collide with + a regular key. However, javascript's Map doesn't support lists (or + object) as keys by default. */ + if (instance) key += '---' + instance; + return key; + } + + /* This return different object for different instances */ + getData(): VEvent | undefined { + return vcal_objects.get(this.getKey()) + } + + connectedCallback() { + let v = this.getData(); + if (v) this.redraw(v); } abstract redraw(data: VEvent): void -- cgit v1.2.3