Skip to content

Commit 5cbd8ca

Browse files
author
Juraj Nyíri
committed
Fix: Incorrect card width
1 parent 1fa549f commit 5cbd8ca

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

dist/plex-meets-homeassistant.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22499,15 +22499,33 @@ class PlexMeetsHomeAssistant extends HTMLElement {
2249922499
this.searchInputElem.style.display = 'none';
2250022500
}
2250122501
if (this.card) {
22502-
const marginRight = 10; // needs to be equal to .container margin right
22503-
const areaSize = this.card.offsetWidth - parseInt(this.card.style.paddingRight, 10) - parseInt(this.card.style.paddingLeft, 10);
22502+
// Todo: figure why 10.3 works
22503+
const marginRight = 10.3; // needs to be equal to .container margin right
22504+
const getAreaSize = () => {
22505+
if (this.card) {
22506+
return (this.card.getBoundingClientRect().width -
22507+
parseInt(this.card.style.paddingRight, 10) -
22508+
parseInt(this.card.style.paddingLeft, 10));
22509+
}
22510+
return 0;
22511+
};
22512+
const areaSize = getAreaSize();
2250422513
const postersInRow = Math.floor(areaSize / this.minWidth);
2250522514
if (areaSize > 0) {
2250622515
CSS_STYLE.width = areaSize / postersInRow - marginRight;
2250722516
CSS_STYLE.height = CSS_STYLE.width * CSS_STYLE.ratio;
2250822517
const episodesInRow = Math.floor(areaSize / this.minEpisodeWidth);
2250922518
CSS_STYLE.episodeWidth = Math.floor(areaSize / episodesInRow - marginRight);
2251022519
CSS_STYLE.episodeHeight = Math.round(CSS_STYLE.episodeWidth * CSS_STYLE.episodeRatio);
22520+
// hack to make sure cards width is always calculated properly, todo solve better in the future
22521+
setTimeout(() => {
22522+
if (this.card) {
22523+
const newAreaSize = getAreaSize();
22524+
if (newAreaSize !== areaSize) {
22525+
this.renderPage();
22526+
}
22527+
}
22528+
}, 1);
2251122529
}
2251222530
else if (this.renderPageRetries < 10) {
2251322531
// sometimes it loop forever, todo: properly fix!
@@ -23656,6 +23674,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
2365623674
}
2365723675
const container = document.createElement('div');
2365823676
container.className = 'plexMeetsContainer';
23677+
// console.log(CSS_STYLE);
2365923678
container.style.width = `${CSS_STYLE.width}px`;
2366023679
if (this.displayTitleMain || this.displaySubtitleMain) {
2366123680
container.style.marginBottom = '10px';

src/plex-meets-homeassistant.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,20 @@ class PlexMeetsHomeAssistant extends HTMLElement {
756756
}
757757

758758
if (this.card) {
759-
const marginRight = 10; // needs to be equal to .container margin right
760-
const areaSize =
761-
this.card.offsetWidth - parseInt(this.card.style.paddingRight, 10) - parseInt(this.card.style.paddingLeft, 10);
759+
// Todo: figure why 10.3 works
760+
const marginRight = 10.3; // needs to be equal to .container margin right
761+
762+
const getAreaSize = (): number => {
763+
if (this.card) {
764+
return (
765+
this.card.getBoundingClientRect().width -
766+
parseInt(this.card.style.paddingRight, 10) -
767+
parseInt(this.card.style.paddingLeft, 10)
768+
);
769+
}
770+
return 0;
771+
};
772+
const areaSize = getAreaSize();
762773
const postersInRow = Math.floor(areaSize / this.minWidth);
763774
if (areaSize > 0) {
764775
CSS_STYLE.width = areaSize / postersInRow - marginRight;
@@ -767,6 +778,15 @@ class PlexMeetsHomeAssistant extends HTMLElement {
767778

768779
CSS_STYLE.episodeWidth = Math.floor(areaSize / episodesInRow - marginRight);
769780
CSS_STYLE.episodeHeight = Math.round(CSS_STYLE.episodeWidth * CSS_STYLE.episodeRatio);
781+
// hack to make sure cards width is always calculated properly, todo solve better in the future
782+
setTimeout(() => {
783+
if (this.card) {
784+
const newAreaSize = getAreaSize();
785+
if (newAreaSize !== areaSize) {
786+
this.renderPage();
787+
}
788+
}
789+
}, 1);
770790
} else if (this.renderPageRetries < 10) {
771791
// sometimes it loop forever, todo: properly fix!
772792
setTimeout(() => {
@@ -2034,6 +2054,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
20342054

20352055
const container = document.createElement('div');
20362056
container.className = 'plexMeetsContainer';
2057+
// console.log(CSS_STYLE);
20372058
container.style.width = `${CSS_STYLE.width}px`;
20382059

20392060
if (this.displayTitleMain || this.displaySubtitleMain) {

0 commit comments

Comments
 (0)