Add: Calculate items per horizontal row and optimize loops

pull/72/head
Juraj Nyíri 3 years ago
parent db85c47295
commit 943c4ee339

@ -22373,8 +22373,23 @@ class PlexMeetsHomeAssistant extends HTMLElement {
return searchContainer; return searchContainer;
}; };
this.renderMovieElems = () => { this.renderMovieElems = () => {
if (this.data[this.config.libraryName] && this.renderedItems < this.data[this.config.libraryName].length) { let renderMore = (!this.maxCount || this.renderedItems < this.maxCount) &&
(!this.maxRenderCount || this.renderedItems < this.maxRenderCount) &&
(!this.maxRows || this.renderedRows <= this.maxRows);
if (this.data[this.config.libraryName] &&
this.renderedItems < this.data[this.config.libraryName].length &&
renderMore) {
let count = 0; 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);
}
console.log(itemsPerRow);
}
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
const searchValues = lodash.split(this.searchValue, ' '); const searchValues = lodash.split(this.searchValue, ' ');
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
@ -22384,9 +22399,11 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.columnsCount = 0; this.columnsCount = 0;
const hasEpisodesResult = hasEpisodes(this.data[this.config.libraryName]); const hasEpisodesResult = hasEpisodes(this.data[this.config.libraryName]);
lodash.forEach(this.data[this.config.libraryName], (movieData) => { lodash.forEach(this.data[this.config.libraryName], (movieData) => {
if ((!this.maxCount || this.renderedItems < this.maxCount) && if (renderMore) {
(!this.maxRenderCount || this.renderedItems < this.maxRenderCount) && renderMore =
(!this.maxRows || this.renderedRows <= this.maxRows)) { (!this.maxCount || this.renderedItems < this.maxCount) &&
(!this.maxRenderCount || this.renderedItems < this.maxRenderCount) &&
(!this.maxRows || this.renderedRows <= this.maxRows);
const movieElem = this.getMovieElement(movieData, hasEpisodesResult); const movieElem = this.getMovieElement(movieData, hasEpisodesResult);
let shouldRender = false; let shouldRender = false;
if (this.looseSearch) { if (this.looseSearch) {

@ -600,8 +600,26 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}; };
renderMovieElems = (): void => { renderMovieElems = (): void => {
if (this.data[this.config.libraryName] && this.renderedItems < this.data[this.config.libraryName].length) { let renderMore =
(!this.maxCount || this.renderedItems < this.maxCount) &&
(!this.maxRenderCount || this.renderedItems < this.maxRenderCount) &&
(!this.maxRows || this.renderedRows <= this.maxRows);
if (
this.data[this.config.libraryName] &&
this.renderedItems < this.data[this.config.libraryName].length &&
renderMore
) {
let count = 0; 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);
}
console.log(itemsPerRow);
}
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
const searchValues = _.split(this.searchValue, ' '); const searchValues = _.split(this.searchValue, ' ');
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
@ -612,11 +630,11 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.columnsCount = 0; this.columnsCount = 0;
const hasEpisodesResult = hasEpisodes(this.data[this.config.libraryName]); const hasEpisodesResult = hasEpisodes(this.data[this.config.libraryName]);
_.forEach(this.data[this.config.libraryName], (movieData: Record<string, any>) => { _.forEach(this.data[this.config.libraryName], (movieData: Record<string, any>) => {
if ( if (renderMore) {
(!this.maxCount || this.renderedItems < this.maxCount) && renderMore =
(!this.maxRenderCount || this.renderedItems < this.maxRenderCount) && (!this.maxCount || this.renderedItems < this.maxCount) &&
(!this.maxRows || this.renderedRows <= this.maxRows) (!this.maxRenderCount || this.renderedItems < this.maxRenderCount) &&
) { (!this.maxRows || this.renderedRows <= this.maxRows);
const movieElem = this.getMovieElement(movieData, hasEpisodesResult); const movieElem = this.getMovieElement(movieData, hasEpisodesResult);
let shouldRender = false; let shouldRender = false;
if (this.looseSearch) { if (this.looseSearch) {

Loading…
Cancel
Save