Promote thumbnail carousel selected to a property.

This commit is contained in:
Dermot Duffy
2022-09-25 17:50:40 -07:00
parent 2f34d6e7fa
commit 56465e4f92
3 changed files with 23 additions and 19 deletions
+2 -1
View File
@@ -30,6 +30,7 @@ import { ThumbnailCarouselTap } from './thumbnail-carousel.js';
import './surround-basic.js'; import './surround-basic.js';
import './timeline-core.js'; import './timeline-core.js';
import { ifDefined } from 'lit/directives/if-defined.js';
interface ThumbnailViewContext { interface ThumbnailViewContext {
// Whether or not to fetch thumbnails. // Whether or not to fetch thumbnails.
@@ -171,8 +172,8 @@ export class FrigateCardSurround extends LitElement {
.config=${this.thumbnailConfig} .config=${this.thumbnailConfig}
.view=${this.view} .view=${this.view}
.target=${this.view.target} .target=${this.view.target}
.selected=${this.view.childIndex}
.cameras=${this.cameras} .cameras=${this.cameras}
selected=${ifDefined(this.view.childIndex ?? undefined)}
@frigate-card:view:change=${(ev: CustomEvent) => changeDrawer(ev, 'close')} @frigate-card:view:change=${(ev: CustomEvent) => changeDrawer(ev, 'close')}
@frigate-card:thumbnail-carousel:tap=${( @frigate-card:thumbnail-carousel:tap=${(
ev: CustomEvent<ThumbnailCarouselTap>, ev: CustomEvent<ThumbnailCarouselTap>,
+14 -16
View File
@@ -59,8 +59,8 @@ export class FrigateCardThumbnailCarousel extends LitElement {
@property({ attribute: false }) @property({ attribute: false })
public config?: ThumbnailsControlConfig; public config?: ThumbnailsControlConfig;
@state() @property({ attribute: false, type: Number, reflect: true })
protected _selected: number | null = null; public selected?: number;
protected _carouselOptions?: EmblaOptionsType; protected _carouselOptions?: EmblaOptionsType;
protected _carouselPlugins: EmblaPluginType[] = [ protected _carouselPlugins: EmblaPluginType[] = [
@@ -76,15 +76,6 @@ export class FrigateCardThumbnailCarousel extends LitElement {
this._resizeObserver = new ResizeObserver(this._resizeHandler.bind(this)); this._resizeObserver = new ResizeObserver(this._resizeHandler.bind(this));
} }
@property({ attribute: false })
set selected(selected: number | null) {
this._selected = selected;
this.style.setProperty(
'--frigate-card-carousel-thumbnail-opacity',
selected === null ? '1.0' : '0.4',
);
}
/** /**
* Handle gallery resize. * Handle gallery resize.
*/ */
@@ -116,7 +107,7 @@ export class FrigateCardThumbnailCarousel extends LitElement {
return { return {
containScroll: 'keepSnaps', containScroll: 'keepSnaps',
dragFree: true, dragFree: true,
startIndex: this._selected ?? 0, startIndex: this.selected ?? 0,
}; };
} }
/** /**
@@ -155,6 +146,13 @@ export class FrigateCardThumbnailCarousel extends LitElement {
} }
} }
if (changedProps.has('selected')) {
this.style.setProperty(
'--frigate-card-carousel-thumbnail-opacity',
this.selected === undefined ? '1.0' : '0.4',
);
}
if (!this._carouselOptions) { if (!this._carouselOptions) {
// Want to set the initial carousel options just before the first render // Want to set the initial carousel options just before the first render
// in order to get the startIndex correct in the options. It is not safe // in order to get the startIndex correct in the options. It is not safe
@@ -171,10 +169,10 @@ export class FrigateCardThumbnailCarousel extends LitElement {
updated(changedProperties: PropertyValues): void { updated(changedProperties: PropertyValues): void {
super.updated(changedProperties); super.updated(changedProperties);
if (changedProperties.has('_selected')) { if (changedProperties.has('selected')) {
this.updateComplete.then(() => { this.updateComplete.then(() => {
if (this._selected !== null) { if (this.selected !== undefined) {
this._refCarousel.value?.carouselScrollTo(this._selected); this._refCarousel.value?.carouselScrollTo(this.selected);
} }
}); });
} }
@@ -200,7 +198,7 @@ export class FrigateCardThumbnailCarousel extends LitElement {
const classes = { const classes = {
embla__slide: true, embla__slide: true,
'slide-selected': this._selected === childIndex, 'slide-selected': this.selected === childIndex,
}; };
const cameraConfig = this.view?.camera ? this.cameras?.get(this.view.camera) : null; const cameraConfig = this.view?.camera ? this.cameras?.get(this.view.camera) : null;
+7 -2
View File
@@ -681,7 +681,9 @@ export class FrigateCardTimelineCore extends LitElement {
const window = this._timeline?.getWindow(); const window = this._timeline?.getWindow();
if (window) { if (window) {
if (properties.group) { if (properties.group) {
this._changeViewToRecording(window.end, String(properties.group)); this._changeViewToRecording(
properties.what === 'background' ? properties.time : window.end,
String(properties.group));
} else if (this.mini && this.view?.camera) { } else if (this.mini && this.view?.camera) {
// In mini mode group may not be displayed / used, so just use the camera directly. // In mini mode group may not be displayed / used, so just use the camera directly.
this._changeViewToRecording(window.end, this.view.camera); this._changeViewToRecording(window.end, this.view.camera);
@@ -812,7 +814,10 @@ export class FrigateCardTimelineCore extends LitElement {
: this._timeline.getSelection(); : this._timeline.getSelection();
let childIndex = -1; let childIndex = -1;
const children: FrigateBrowseMediaSource[] = []; const children: FrigateBrowseMediaSource[] = [];
this._dataview?.get({ order: sortTimelineItemsYoungestToOldest }).forEach((item) => { this._dataview?.get({
filter: (item) => item.type !== 'background',
order: sortTimelineItemsYoungestToOldest }
).forEach((item) => {
const cameraID = item.group ? String(item.group) : null; const cameraID = item.group ? String(item.group) : null;
const cameraConfig = cameraID ? this.cameras?.get(cameraID) : null; const cameraConfig = cameraID ? this.cameras?.get(cameraID) : null;
const event = item.event; const event = item.event;