Fix: Infinite scroll not working

main 3.6.6
Juraj Nyiri 2 years ago
parent 90e9f237c3
commit 452a9ac993

@ -20275,7 +20275,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.valueUpdated = () => { this.valueUpdated = () => {
const originalConfig = lodash.clone(this.config); const originalConfig = lodash.clone(this.config);
this.config.protocol = this.protocol.value; this.config.protocol = this.protocol.value;
this.config.ip = this.ip.value.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.config.ip = this.ip.value.replace(/^https?:\/\//i, '').replace(/\/$/, '');
this.config.token = this.token.value; this.config.token = this.token.value;
this.config.port = this.port.value; this.config.port = this.port.value;
if (this.loaded) { if (this.loaded) {
@ -20527,7 +20527,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.content.appendChild(this.protocol); this.content.appendChild(this.protocol);
this.ip.label = 'Plex IP Address / Hostname'; this.ip.label = 'Plex IP Address / Hostname';
if (this.config.ip) { if (this.config.ip) {
this.ip.value = this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.ip.value = this.config.ip.replace(/^https?:\/\//i, '').replace(/\/$/, '');
} }
else { else {
this.ip.value = this.config.ip; this.ip.value = this.config.ip;
@ -20559,7 +20559,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.content.appendChild(this.libraryName); this.content.appendChild(this.libraryName);
this.content.appendChild(warningLibrary); this.content.appendChild(warningLibrary);
this.appendChild(this.content); this.appendChild(this.content);
this.plex = new Plex(this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''), this.plexPort, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip.replace(/^https?:\/\//i, '').replace(/\/$/, ''), this.plexPort, this.config.token, this.plexProtocol, this.config.sort);
this.sections = await this.plex.getSections(); this.sections = await this.plex.getSections();
lodash.forEach(this.sections, section => { lodash.forEach(this.sections, section => {
if (lodash.isEqual(section.title, this.config.libraryName) && lodash.isEqual(section.type, 'artist')) { if (lodash.isEqual(section.title, this.config.libraryName) && lodash.isEqual(section.type, 'artist')) {
@ -20581,6 +20581,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.content.appendChild(this.useShuffle); this.content.appendChild(this.useShuffle);
return false; return false;
} }
return true;
}); });
this.livetv = await this.plex.getLiveTV(); this.livetv = await this.plex.getLiveTV();
this.collections = await this.plex.getCollections(); this.collections = await this.plex.getCollections();
@ -21971,11 +21972,12 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.error = ''; this.error = '';
this.contentBGHeight = 0; this.contentBGHeight = 0;
this.initialDataLoaded = false; this.initialDataLoaded = false;
this.haWindow = PlexMeetsHomeAssistant.querySelectorAllShadows('hui-view')[0];
this.renderNewElementsIfNeeded = () => { this.renderNewElementsIfNeeded = () => {
const loadAdditionalRowsCount = 2; // todo: make this configurable const loadAdditionalRowsCount = 2; // todo: make this configurable
const height = getHeight(this.content); const height = getHeight(this.content);
if (!this.detailsShown && if (!this.detailsShown &&
window.innerHeight + window.scrollY > height + getOffset(this.content).top - 300 && window.innerHeight + this.haWindow.scrollTop > height - 300 &&
this.renderedItems > 0 && this.renderedItems > 0 &&
this.renderedItems < this.data[this.config.libraryName].length && this.renderedItems < this.data[this.config.libraryName].length &&
(!this.maxCount || this.renderedItems < this.maxCount) && (!this.maxCount || this.renderedItems < this.maxCount) &&
@ -22018,7 +22020,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.hassObj) { if (this.hassObj) {
this.entityRegistry = await fetchEntityRegistry(this.hassObj.connection); this.entityRegistry = await fetchEntityRegistry(this.hassObj.connection);
} }
window.addEventListener('scroll', () => { window.addEventListener('wheel', () => {
// todo: improve performance by calculating this when needed only // todo: improve performance by calculating this when needed only
if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this) && this.isVisible) { if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this) && this.isVisible) {
const seasonContainers = this.getElementsByClassName('seasonContainer'); const seasonContainers = this.getElementsByClassName('seasonContainer');
@ -23947,6 +23949,17 @@ class PlexMeetsHomeAssistant extends HTMLElement {
return document.createElement('plex-meets-homeassistant-editor'); return document.createElement('plex-meets-homeassistant-editor');
} }
} }
PlexMeetsHomeAssistant.querySelectorAllShadows = (selector, el = document.body) => {
// recurse on childShadows
const childShadows = Array.from(el.querySelectorAll('*'))
.map(el2 => el2.shadowRoot)
.filter(Boolean);
// console.log('[querySelectorAllShadows]', selector, el, `(${childShadows.length} shadowRoots)`);
const childResults = childShadows.map((child) => PlexMeetsHomeAssistant.querySelectorAllShadows(selector, child));
// fuse all results into singular, flat array
const result = Array.from(el.querySelectorAll(selector));
return result.concat(childResults).flat();
};
customElements.define('plex-meets-homeassistant-editor', PlexMeetsHomeAssistantEditor); customElements.define('plex-meets-homeassistant-editor', PlexMeetsHomeAssistantEditor);
customElements.define('plex-meets-homeassistant', PlexMeetsHomeAssistant); customElements.define('plex-meets-homeassistant', PlexMeetsHomeAssistant);
window.customCards = window.customCards || []; window.customCards = window.customCards || [];

File diff suppressed because one or more lines are too long

2102
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -136,7 +136,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
valueUpdated = (): void => { valueUpdated = (): void => {
const originalConfig = _.clone(this.config); const originalConfig = _.clone(this.config);
this.config.protocol = this.protocol.value; this.config.protocol = this.protocol.value;
this.config.ip = this.ip.value.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.config.ip = this.ip.value.replace(/^https?:\/\//i, '').replace(/\/$/, '');
this.config.token = this.token.value; this.config.token = this.token.value;
this.config.port = this.port.value; this.config.port = this.port.value;
if (this.loaded) { if (this.loaded) {
@ -393,7 +393,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.ip.label = 'Plex IP Address / Hostname'; this.ip.label = 'Plex IP Address / Hostname';
if (this.config.ip) { if (this.config.ip) {
this.ip.value = this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.ip.value = this.config.ip.replace(/^https?:\/\//i, '').replace(/\/$/, '');
} else { } else {
this.ip.value = this.config.ip; this.ip.value = this.config.ip;
} }
@ -433,7 +433,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.appendChild(this.content); this.appendChild(this.content);
this.plex = new Plex( this.plex = new Plex(
this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''), this.config.ip.replace(/^https?:\/\//i, '').replace(/\/$/, ''),
this.plexPort, this.plexPort,
this.config.token, this.config.token,
this.plexProtocol, this.plexProtocol,
@ -460,6 +460,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.content.appendChild(this.useShuffle); this.content.appendChild(this.useShuffle);
return false; return false;
} }
return true;
}); });
this.livetv = await this.plex.getLiveTV(); this.livetv = await this.plex.getLiveTV();
this.collections = await this.plex.getCollections(); this.collections = await this.plex.getCollections();

@ -171,6 +171,25 @@ class PlexMeetsHomeAssistant extends HTMLElement {
initialDataLoaded = false; initialDataLoaded = false;
static querySelectorAllShadows = (selector: any, el = document.body) => {
// recurse on childShadows
const childShadows = Array.from(el.querySelectorAll('*'))
.map(el2 => el2.shadowRoot)
.filter(Boolean);
// console.log('[querySelectorAllShadows]', selector, el, `(${childShadows.length} shadowRoots)`);
const childResults: any = childShadows.map((child: any) =>
PlexMeetsHomeAssistant.querySelectorAllShadows(selector, child)
);
// fuse all results into singular, flat array
const result = Array.from(el.querySelectorAll(selector));
return (result.concat(childResults) as any).flat();
};
haWindow = PlexMeetsHomeAssistant.querySelectorAllShadows('hui-view')[0];
set hass(hass: HomeAssistant) { set hass(hass: HomeAssistant) {
this.hassObj = hass; this.hassObj = hass;
@ -188,7 +207,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
const height = getHeight(this.content); const height = getHeight(this.content);
if ( if (
!this.detailsShown && !this.detailsShown &&
window.innerHeight + window.scrollY > height + getOffset(this.content).top - 300 && window.innerHeight + this.haWindow.scrollTop > height - 300 &&
this.renderedItems > 0 && this.renderedItems > 0 &&
this.renderedItems < this.data[this.config.libraryName].length && this.renderedItems < this.data[this.config.libraryName].length &&
(!this.maxCount || this.renderedItems < this.maxCount) && (!this.maxCount || this.renderedItems < this.maxCount) &&
@ -236,7 +255,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.entityRegistry = await fetchEntityRegistry(this.hassObj.connection); this.entityRegistry = await fetchEntityRegistry(this.hassObj.connection);
} }
window.addEventListener('scroll', () => { window.addEventListener('wheel', () => {
// todo: improve performance by calculating this when needed only // todo: improve performance by calculating this when needed only
if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this) && this.isVisible) { if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this) && this.isVisible) {
const seasonContainers = this.getElementsByClassName('seasonContainer') as HTMLCollectionOf<HTMLElement>; const seasonContainers = this.getElementsByClassName('seasonContainer') as HTMLCollectionOf<HTMLElement>;

Loading…
Cancel
Save