Reset carousel plugins if results change.

This commit is contained in:
Dermot Duffy
2023-01-24 19:36:54 -08:00
parent 191c901952
commit e85d46d84a
2 changed files with 15 additions and 27 deletions
+15 -26
View File
@@ -31,7 +31,6 @@ import { contentsChanged } from '../utils/basic.js';
import { getFullDependentBrowseMediaQueryParametersOrDispatchError } from '../utils/ha/browse-media.js'; import { getFullDependentBrowseMediaQueryParametersOrDispatchError } from '../utils/ha/browse-media.js';
import { ResolvedMediaCache, resolveMedia } from '../utils/ha/resolved-media.js'; import { ResolvedMediaCache, resolveMedia } from '../utils/ha/resolved-media.js';
import { View } from '../view/view.js'; import { View } from '../view/view.js';
import { MediaQueriesResults } from '../view/media-queries-results';
import { MediaQueriesClassifier } from '../view/media-queries-classifier'; import { MediaQueriesClassifier } from '../view/media-queries-classifier';
import { AutoMediaPlugin } from './embla-plugins/automedia.js'; import { AutoMediaPlugin } from './embla-plugins/automedia.js';
import { Lazyload } from './embla-plugins/lazyload.js'; import { Lazyload } from './embla-plugins/lazyload.js';
@@ -174,7 +173,7 @@ export class FrigateCardViewer extends LitElement {
.cameras=${this.cameras} .cameras=${this.cameras}
.viewerConfig=${this.viewerConfig} .viewerConfig=${this.viewerConfig}
.resolvedMediaCache=${this.resolvedMediaCache} .resolvedMediaCache=${this.resolvedMediaCache}
.cameraManager=${this.cameraManager} .cameraManager=${this.cameraManager}
.cardWideConfig=${this.cardWideConfig} .cardWideConfig=${this.cardWideConfig}
> >
</frigate-card-viewer-carousel> </frigate-card-viewer-carousel>
@@ -221,9 +220,6 @@ export class FrigateCardViewerCarousel extends LitElement {
protected _refMediaCarousel: Ref<FrigateCardMediaCarousel> = createRef(); protected _refMediaCarousel: Ref<FrigateCardMediaCarousel> = createRef();
protected _carouselOptions?: EmblaOptionsType;
protected _carouselPlugins?: EmblaPluginType[];
// A task to resolve target media if lazy loading is disabled. // A task to resolve target media if lazy loading is disabled.
protected _mediaResolutionTask = new Task< protected _mediaResolutionTask = new Task<
[ViewerConfig | undefined, Map<string, CameraConfig> | undefined, View | undefined], [ViewerConfig | undefined, Map<string, CameraConfig> | undefined, View | undefined],
@@ -398,11 +394,13 @@ export class FrigateCardViewerCarousel extends LitElement {
return; return;
} }
this.view.evolve({ this.view
view: 'media', .evolve({
query: clipQuery, view: 'media',
queryResults: results, query: clipQuery,
}).dispatchChangeEvent(this); queryResults: results,
})
.dispatchChangeEvent(this);
} }
/** /**
@@ -525,20 +523,6 @@ export class FrigateCardViewerCarousel extends LitElement {
if (changedProps.has('viewerConfig')) { if (changedProps.has('viewerConfig')) {
updateElementStyleFromMediaLayoutConfig(this, this.viewerConfig?.layout); updateElementStyleFromMediaLayoutConfig(this, this.viewerConfig?.layout);
} }
if (!this._carouselOptions || changedProps.has('viewerConfig')) {
this._carouselOptions = {
draggable: this.viewerConfig?.draggable ?? true,
};
}
if (
!this._carouselPlugins ||
changedProps.has('viewerConfig') ||
(changedProps.has('view') &&
this.view?.queryResults?.getResultsCount() !==
changedProps.get('view')?.queryResults?.getResultsCount())
) {
this._carouselPlugins = this._getPlugins();
}
} }
/** /**
@@ -586,8 +570,13 @@ export class FrigateCardViewerCarousel extends LitElement {
return html` <frigate-card-media-carousel return html` <frigate-card-media-carousel
${ref(this._refMediaCarousel)} ${ref(this._refMediaCarousel)}
.carouselOptions=${this._carouselOptions} .carouselOptions=${guard([this.viewerConfig], () => ({
.carouselPlugins=${this._carouselPlugins} draggable: this.viewerConfig?.draggable ?? true,
}))}
.carouselPlugins=${guard(
[this.viewerConfig, this.view?.queryResults?.getResults()],
this._getPlugins.bind(this),
)}
.label=${media.getTitle() ?? undefined} .label=${media.getTitle() ?? undefined}
.titlePopupConfig=${this.viewerConfig?.controls.title} .titlePopupConfig=${this.viewerConfig?.controls.title}
.selected=${this.view?.queryResults?.getSelectedIndex() ?? 0} .selected=${this.view?.queryResults?.getSelectedIndex() ?? 0}
-1
View File
@@ -6,7 +6,6 @@
// - TODO: ts-prune https://camchenry.com/blog/deleting-dead-code-in-typescript // - TODO: ts-prune https://camchenry.com/blog/deleting-dead-code-in-typescript
// Hard: // Hard:
// - TODO: There are circumstances when lazy load doesn't work (e.g. snapshot -> clips re-query)
// - TODO: Implement dragging the timeline seeking forward in both Frigate recordings & events. // - TODO: Implement dragging the timeline seeking forward in both Frigate recordings & events.
// - TODO: Implement gallery. // - TODO: Implement gallery.
// - TODO: Remove FrigateBrowseMediaSource if not necessary (post-gallery). // - TODO: Remove FrigateBrowseMediaSource if not necessary (post-gallery).