Skip to content

Commit 4665c77

Browse files
refactor: simplify drawEvents method by removing layout wait logic
This is possible after the last commit.
1 parent 5c5c25d commit 4665c77

1 file changed

Lines changed: 8 additions & 29 deletions

File tree

CALEXT2_WeekSlot.js

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global CellSlot Log Slot */
1+
/* global CellSlot Slot */
22
// eslint-disable-next-line no-unused-vars
33
class WeekSlot extends Slot {
44
constructor (view, period, seq = 0) {
@@ -56,36 +56,15 @@ class WeekSlot extends Slot {
5656
return event.dom;
5757
}
5858

59-
// Helper to wait for DOM to be rendered and have correct sizes
60-
async waitForLayout (selector, tries = 10, delay = 30) {
61-
for (let attempt = 0; attempt < tries; attempt++) {
62-
const el = this.contentDom.querySelector(selector);
63-
if (el) {
64-
const rect = el.getBoundingClientRect();
65-
if (rect.height > 0 && rect.width > 0) {
66-
return rect;
67-
}
68-
}
69-
// eslint-disable-next-line no-await-in-loop, no-promise-executor-return
70-
await new Promise((res) => setTimeout(res, delay));
71-
}
72-
throw new Error("Element layout not ready");
73-
}
59+
drawEvents () {
60+
// Get the first cellSlot content/header for sizing
61+
const firstCellContent = this.contentDom.querySelector(".cellSlot .slotContent");
62+
const firstCellHeader = this.contentDom.querySelector(".cellSlot .slotHeader");
7463

75-
async drawEvents () {
76-
let fcc, fch;
77-
try {
78-
fcc = await this.waitForLayout(".cellSlot .slotContent");
79-
fch = await this.waitForLayout(".cellSlot .slotHeader");
80-
} catch (e) {
81-
Log.warn("Layout not ready for drawEvents:", e);
82-
// Fallback to default values if layout is not ready
83-
fcc = {height: 95};
84-
fch = {height: 28};
85-
}
64+
// Use measured heights
65+
this.timelineDom.style.height = `${firstCellContent.getBoundingClientRect().height}px`;
66+
this.timelineDom.style.top = `${firstCellHeader.getBoundingClientRect().height}px`;
8667

87-
this.timelineDom.style.top = `${fch.height}px`;
88-
this.timelineDom.style.height = `${fcc.height}px`;
8968
const parentPosition = this.timelineDom.getBoundingClientRect();
9069

9170
const fcs = this.contentDom.querySelectorAll(".cellSlot");

0 commit comments

Comments
 (0)