diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index d31af66..06f586e 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -22380,14 +22380,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (this.data[this.config.libraryName] && this.renderedItems < this.data[this.config.libraryName].length && renderMore) { - let count = 0; let maxRenderedItems = this.data[this.config.libraryName].length; - this.data[this.config.libraryName].length; + let itemsPerRow = this.data[this.config.libraryName].length; if (this.maxCount) { maxRenderedItems = this.maxCount; + itemsPerRow = maxRenderedItems; if (this.maxRows) { - Math.round(maxRenderedItems / this.maxRows); + itemsPerRow = Math.ceil(maxRenderedItems / this.maxRows); } + console.log(itemsPerRow); } // eslint-disable-next-line consistent-return const searchValues = lodash.split(this.searchValue, ' '); @@ -22398,11 +22399,11 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.columnsCount = 0; const hasEpisodesResult = hasEpisodes(this.data[this.config.libraryName]); lodash.forEach(this.data[this.config.libraryName], (movieData) => { + renderMore = + (!this.maxCount || this.renderedItems < this.maxCount) && + (!this.maxRenderCount || this.renderedItems < this.maxRenderCount) && + (!this.maxRows || this.renderedRows <= this.maxRows); if (renderMore) { - renderMore = - (!this.maxCount || this.renderedItems < this.maxCount) && - (!this.maxRenderCount || this.renderedItems < this.maxRenderCount) && - (!this.maxRows || this.renderedRows <= this.maxRows); const movieElem = this.getMovieElement(movieData, hasEpisodesResult); let shouldRender = false; if (this.looseSearch) { @@ -22428,11 +22429,14 @@ class PlexMeetsHomeAssistant extends HTMLElement { shouldRender = true; } if (shouldRender) { - count += 1; - if (count > this.renderedItems) { - this.contentContainer.appendChild(movieElem); - if (this.useHorizontalScroll) { - const marginRight = 10; + this.contentContainer.appendChild(movieElem); + if (this.useHorizontalScroll) { + if (this.renderedItems > 0 && this.renderedItems % itemsPerRow === 0) { + this.renderedRows += 1; + movieElem.style.clear = 'both'; + } + const marginRight = 10; + if (this.renderedRows === 1) { if (lodash.isEmpty(this.contentContainer.style.width)) { this.contentContainer.style.width = `${parseFloat(movieElem.style.width) + marginRight}px`; } @@ -22442,8 +22446,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { marginRight}px`; } } - this.renderedItems += 1; } + this.renderedItems += 1; } if (shouldRender && lastRowTop !== movieElem.getBoundingClientRect().top && !this.useHorizontalScroll) { this.renderedRows += 1; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 78c3b1b..7a8f45e 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -610,15 +610,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.renderedItems < this.data[this.config.libraryName].length && renderMore ) { - let count = 0; let maxRenderedItems = this.data[this.config.libraryName].length; let itemsPerRow = this.data[this.config.libraryName].length; if (this.maxCount) { maxRenderedItems = this.maxCount; itemsPerRow = maxRenderedItems; if (this.maxRows) { - itemsPerRow = Math.round(maxRenderedItems / this.maxRows); + itemsPerRow = Math.ceil(maxRenderedItems / this.maxRows); } + console.log(itemsPerRow); } // eslint-disable-next-line consistent-return const searchValues = _.split(this.searchValue, ' '); @@ -630,11 +630,11 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.columnsCount = 0; const hasEpisodesResult = hasEpisodes(this.data[this.config.libraryName]); _.forEach(this.data[this.config.libraryName], (movieData: Record) => { + renderMore = + (!this.maxCount || this.renderedItems < this.maxCount) && + (!this.maxRenderCount || this.renderedItems < this.maxRenderCount) && + (!this.maxRows || this.renderedRows <= this.maxRows); if (renderMore) { - renderMore = - (!this.maxCount || this.renderedItems < this.maxCount) && - (!this.maxRenderCount || this.renderedItems < this.maxRenderCount) && - (!this.maxRows || this.renderedRows <= this.maxRows); const movieElem = this.getMovieElement(movieData, hasEpisodesResult); let shouldRender = false; if (this.looseSearch) { @@ -663,11 +663,14 @@ class PlexMeetsHomeAssistant extends HTMLElement { shouldRender = true; } if (shouldRender) { - count += 1; - if (count > this.renderedItems) { - this.contentContainer.appendChild(movieElem); - if (this.useHorizontalScroll) { - const marginRight = 10; + this.contentContainer.appendChild(movieElem); + if (this.useHorizontalScroll) { + if (this.renderedItems > 0 && this.renderedItems % itemsPerRow === 0) { + this.renderedRows += 1; + movieElem.style.clear = 'both'; + } + const marginRight = 10; + if (this.renderedRows === 1) { if (_.isEmpty(this.contentContainer.style.width)) { this.contentContainer.style.width = `${parseFloat(movieElem.style.width) + marginRight}px`; } else { @@ -676,9 +679,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { marginRight}px`; } } - - this.renderedItems += 1; } + + this.renderedItems += 1; } if (shouldRender && lastRowTop !== movieElem.getBoundingClientRect().top && !this.useHorizontalScroll) { this.renderedRows += 1;