diff --git a/src/components/surround-thumbnails.ts b/src/components/surround-thumbnails.ts index ca375539..fdb03974 100644 --- a/src/components/surround-thumbnails.ts +++ b/src/components/surround-thumbnails.ts @@ -21,7 +21,7 @@ import './surround.js'; import surroundThumbnailsStyle from '../scss/surround.scss'; interface FrigateCardThumbnailsSet { - target: FrigateBrowseMediaSource; + target?: FrigateBrowseMediaSource; childIndex?: number; } @@ -93,7 +93,9 @@ export class FrigateCardSurround extends LitElement { return html` ) => { - this._thumbnailTarget = ev.detail.target; + if (ev.detail.target) { + this._thumbnailTarget = ev.detail.target; + } this._thumbnailSelected = ev.detail.childIndex; }} @frigate-card:thumbnails:open=${(ev: CustomEvent) => { @@ -113,8 +115,8 @@ export class FrigateCardSurround extends LitElement { ? html` ) => { this.view ?.evolve({ diff --git a/src/components/thumbnail-carousel.ts b/src/components/thumbnail-carousel.ts index 4fa71dc4..6c28d63c 100644 --- a/src/components/thumbnail-carousel.ts +++ b/src/components/thumbnail-carousel.ts @@ -124,11 +124,11 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel { } super.updated(changedProperties); - if (changedProperties.has('selected')) { + if (changedProperties.has('_selected')) { this.updateComplete.then(() => { if (this._carousel) { - if (this.selected !== undefined && this.selected !== null) { - this.carouselScrollTo(this.selected); + if (this._selected !== undefined && this._selected !== null) { + this.carouselScrollTo(this._selected); } } }); @@ -156,7 +156,7 @@ export class FrigateCardThumbnailCarousel extends FrigateCardCarousel { const classes = { embla__slide: true, - 'slide-selected': this.selected === childIndex, + 'slide-selected': this._selected === childIndex, }; return html` - `; + ) => { + // When a slide is selected in the viewer carousel, send a new event + // from the same source asking for the thumbnails to be updated. + dispatchFrigateCardEvent(ev.composedPath()[0], 'thumbnails:set', { + childIndex: ev.detail.index, + }); + }} + > + + `; } /** @@ -112,82 +122,6 @@ export class FrigateCardViewer extends LitElement { } } -@customElement('frigate-card-viewer-core') -export class FrigateCardViewerCore extends LitElement { - @property({ attribute: false }) - protected hass?: HomeAssistant & ExtendedHomeAssistant; - - @property({ attribute: false }) - protected view?: Readonly; - - // See note on viewerConfig in . - @property({ attribute: false, hasChanged: contentsChanged }) - protected viewerConfig?: ViewerConfig; - - @property({ attribute: false }) - protected browseMediaQueryParameters?: BrowseMediaQueryParameters; - - @property({ attribute: false }) - protected resolvedMediaCache?: ResolvedMediaCache; - - protected _viewerCarouselRef: Ref = createRef(); - protected _thumbnailCarouselRef: Ref = createRef(); - - protected _syncThumbnailCarousel(): void { - const mediaSelected = this._viewerCarouselRef.value?.carouselSelected(); - if (mediaSelected !== undefined && this._thumbnailCarouselRef.value) { - this._thumbnailCarouselRef.value.selected = mediaSelected; - } - } - - protected _renderThumbnails(): TemplateResult { - if (!this.view || !this.viewerConfig) { - return html``; - } - - return html` ) => { - this._viewerCarouselRef.value?.carouselScrollTo(ev.detail.slideIndex); - }} - @frigate-card:carousel:init=${this._syncThumbnailCarousel.bind(this)} - > - `; - } - - protected render(): TemplateResult | void { - if (!this.view || !this.viewerConfig) { - return html``; - } - return html` ${this.viewerConfig && - this.viewerConfig.controls.thumbnails.mode === 'above' - ? this._renderThumbnails() - : ''} - - - ${this.viewerConfig && this.viewerConfig.controls.thumbnails.mode === 'below' - ? this._renderThumbnails() - : ''}`; - } - - /** - * Get element styles. - */ - static get styles(): CSSResultGroup { - return unsafeCSS(viewerCoreStyle); - } -} - @customElement('frigate-card-viewer-carousel') export class FrigateCardViewerCarousel extends FrigateCardMediaCarousel { @property({ attribute: false }) diff --git a/src/scss/viewer-core.scss b/src/scss/viewer-core.scss deleted file mode 100644 index f8822b5a..00000000 --- a/src/scss/viewer-core.scss +++ /dev/null @@ -1,17 +0,0 @@ -:host { - display: flex; - flex-direction: column; - gap: 5px; - - height: 100%; - width: 100%; -} - -frigate-card-viewer-carousel { - flex: 1; - min-height: 0; -} - -frigate-card-thumbnail-carousel { - flex: 0 0 var(--frigate-card-carousel-thumbnail-size); -} \ No newline at end of file diff --git a/src/scss/viewer.scss b/src/scss/viewer.scss index e792d174..19bc1a0b 100644 --- a/src/scss/viewer.scss +++ b/src/scss/viewer.scss @@ -1,5 +1,12 @@ :host { - height: 100%; width: 100%; - display: block; + height: 100%; + display: flex; + flex-direction: column; + gap: 5px; } + +frigate-card-viewer-carousel { + flex: 1; + min-height: 0; +} \ No newline at end of file