Skip to content

Commit

Permalink
refactor: Improve MoonHorizon component with resize observer for card…
Browse files Browse the repository at this point in the history
… width measurement
  • Loading branch information
ngocjohn committed Nov 9, 2024
1 parent 571a88a commit 5deb0a1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/moon-horizon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class MoonHorizon extends LitElement {
private _timeAnimationFrame: number | null = null;
private _lastTime: string | null = null;
@state() private cardWidth = 0;
@state() private _resizeEntry?: ResizeObserverEntry;

connectedCallback(): void {
super.connectedCallback();
Expand All @@ -63,7 +64,7 @@ export class MoonHorizon extends LitElement {
entries.forEach((entry) => {
// Immediately compute the rect and measure the card on resize
this.measureCard();
console.log('resize entry', entry);
this._resizeEntry = entry;
});
});

Expand All @@ -85,7 +86,6 @@ export class MoonHorizon extends LitElement {
return;
}
// Log card width for debugging
console.log('Card measured:', card.offsetWidth);
this.cardWidth = card.offsetWidth;
}

Expand Down Expand Up @@ -234,6 +234,7 @@ export class MoonHorizon extends LitElement {
onResize: (_chart, size) => {
if (this.cardWidth !== size.width) {
_chart.resize();
_chart.update('none');
}
},
},
Expand Down

0 comments on commit 5deb0a1

Please sign in to comment.