Minor refactor for consistency.

This commit is contained in:
Dermot Duffy
2021-11-24 17:49:39 -08:00
parent bb36004b6d
commit cbd2505b98
4 changed files with 37 additions and 38 deletions
-27
View File
@@ -1,8 +1,6 @@
import { import {
CSSResultGroup, CSSResultGroup,
LitElement, LitElement,
TemplateResult,
html,
unsafeCSS, unsafeCSS,
PropertyValues, PropertyValues,
} from 'lit'; } from 'lit';
@@ -53,14 +51,6 @@ export class FrigateCardCarousel extends LitElement {
} }
} }
/**
* Get slides to include in the render.
* @returns The slides to include in the render.
*/
protected _getSlides(): TemplateResult[] {
return [];
}
/** /**
* Load the carousel with "slides". * Load the carousel with "slides".
*/ */
@@ -83,23 +73,6 @@ export class FrigateCardCarousel extends LitElement {
} }
} }
/**
* Render the element.
* @returns A template to display to the user.
*/
protected render(): TemplateResult | void {
const slides = this._getSlides();
if (!slides) {
return;
}
return html` <div class="embla">
<div class="embla__viewport">
<div class="embla__container">${slides}</div>
</div>
</div>`;
}
/** /**
* Get element styles. * Get element styles.
*/ */
+1 -1
View File
@@ -45,7 +45,7 @@ export class FrigateCardMenu extends LitElement {
this.style.setProperty('--frigate-card-menu-button-size', menuConfig.button_size); this.style.setProperty('--frigate-card-menu-button-size', menuConfig.button_size);
} }
} }
public _menuConfig?: MenuConfig; protected _menuConfig?: MenuConfig;
@property({ attribute: false }) @property({ attribute: false })
protected expand = false; protected expand = false;
+18 -1
View File
@@ -23,7 +23,7 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel {
this.style.setProperty('--frigate-card-viewer-thumbnail-size', config.size); this.style.setProperty('--frigate-card-viewer-thumbnail-size', config.size);
} }
} }
public _config?: ThumbnailsControlConfig; protected _config?: ThumbnailsControlConfig;
constructor() { constructor() {
super(); super();
@@ -102,6 +102,23 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel {
</div>`; </div>`;
} }
/**
* Render the element.
* @returns A template to display to the user.
*/
protected render(): TemplateResult | void {
const slides = this._getSlides();
if (!slides || !this._config || this._config.mode == 'none') {
return;
}
return html` <div class="embla">
<div class="embla__viewport">
<div class="embla__container">${slides}</div>
</div>
</div>`;
}
/** /**
* Get element styles. * Get element styles.
*/ */
+18 -9
View File
@@ -510,24 +510,21 @@ export class FrigateCardMediaCarousel extends FrigateCardCarousel {
} }
/** /**
* Render the element. * Get slides to include in the render.
* @returns A template to display to the user. * @returns The slides to include in the render.
*/ */
protected render(): TemplateResult | void { protected _getSlides(): TemplateResult[] {
if ( if (
!this.view || !this.view ||
!this.view.target || !this.view.target ||
!this.view.target.children || !this.view.target.children ||
!this.view.target.children.length || !this.view.target.children.length
this.view.childIndex === undefined ||
!this.resolvedMediaCache
) { ) {
return html``; return [];
} }
const slides: TemplateResult[] = [];
this._slideToChild = {}; this._slideToChild = {};
const slides: TemplateResult[] = [];
for (let i = 0; i < this.view.target.children?.length; ++i) { for (let i = 0; i < this.view.target.children?.length; ++i) {
const slide = this._renderMediaItem(this.view.target.children[i], slides.length); const slide = this._renderMediaItem(this.view.target.children[i], slides.length);
@@ -536,6 +533,18 @@ export class FrigateCardMediaCarousel extends FrigateCardCarousel {
slides.push(slide); slides.push(slide);
} }
} }
return slides;
}
/**
* Render the element.
* @returns A template to display to the user.
*/
protected render(): TemplateResult | void {
const slides = this._getSlides();
if (!slides) {
return;
}
const neighbors = this._getMediaNeighbors(); const neighbors = this._getMediaNeighbors();