From 773b5cf318232ec9b610c2a913ef1447a56c013f Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sat, 23 Jul 2022 14:59:46 -0700 Subject: [PATCH] Performance improvements. --- README.md | 5 ++++ src/components/carousel.ts | 11 ++++++++- src/components/live.ts | 15 ++++++++--- src/components/thumbnail-carousel.ts | 37 ++++++++++++++-------------- src/components/viewer.ts | 5 ++-- 5 files changed, 48 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f0f40285..ed4c207a 100644 --- a/README.md +++ b/README.md @@ -566,6 +566,11 @@ timeline: ### Dimensions Options +These options control the aspect-ratio of the entire card to make placement in +Home Assistant dashboards more stable. Aspect ratio configuration applies once +to the entire card (including the menu, thumbnails, etc), not just to displayed +media. + All configuration is under: ```yaml diff --git a/src/components/carousel.ts b/src/components/carousel.ts index 0cb8fe37..1645d493 100644 --- a/src/components/carousel.ts +++ b/src/components/carousel.ts @@ -87,7 +87,7 @@ export class FrigateCardCarousel extends LitElement { const destroyProperties = [ 'direction', 'carouselOptions', - 'carouselOptions', + 'carouselPlugins', ] as const; if (destroyProperties.some((prop) => changedProps.has(prop))) { this._destroyCarousel(); @@ -255,11 +255,20 @@ export class FrigateCardCarousel extends LitElement { this._scrolling = true; }); this._carousel.on('settle', () => { + // Reinitialize the carousel if a request to reinitialize was made + // during scrolling (instead the request is handled after the scrolling + // has settled). this._scrolling = false; if (this._reInitOnSettle) { this._reInitOnSettle = false; this._carouselReInitInPlace(); } + }) + this._carousel.on('settle', () => { + const selected = this.getCarouselSelected(); + if (selected) { + dispatchFrigateCardEvent(this, 'carousel:settle', selected); + } }); } } diff --git a/src/components/live.ts b/src/components/live.ts index d9a6c5ae..ea4a81db 100644 --- a/src/components/live.ts +++ b/src/components/live.ts @@ -489,8 +489,15 @@ export class FrigateCardLiveCarousel extends LitElement { const [prev, next] = this._getCameraNeighbors(); const title = getCameraTitle(this.hass, this.cameras.get(this.view.camera)); - // guard() is used below to avoid reseting the carousel unless the - // options/plugins actually change. + // Notes on the below: + // - guard() is used to avoid reseting the carousel unless the + // options/plugins actually change. + // - the 'carousel:settle' event is listened for (instead of + // 'carousel:select') to only trigger the view change (which subsequently + // fetches thumbnails) after the carousel has stopped moving. This gives a + // much smoother carousel experience since network fetches are not at the + // same time as carousel movement (at a cost of fetching thumbnails a + // little later). return html` + @frigate-card:carousel:settle=${this._setViewHandler.bind(this)} + > ${slides} `; diff --git a/src/components/viewer.ts b/src/components/viewer.ts index 806bbd29..c55ee3ad 100644 --- a/src/components/viewer.ts +++ b/src/components/viewer.ts @@ -608,8 +608,9 @@ export class FrigateCardViewerCarousel extends LitElement { const neighbors = this._getMediaNeighbors(); const [prev, next] = [neighbors?.previous, neighbors?.next]; - // guard() is used below to avoid reseting the carousel unless the - // options/plugins actually change. + // Notes on the below: + // - guard() is used to avoid reseting the carousel unless the + // options/plugins actually change. return html`