Update live to use the new surround.
This commit is contained in:
+17
-72
@@ -120,79 +120,12 @@ export class FrigateCardLive extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render thumbnails carousel.
|
||||
* @returns A rendered template or void.
|
||||
*/
|
||||
protected renderThumbnails(config: LiveConfig): TemplateResult | void {
|
||||
if (!this.liveConfig || !this.view) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchThumbnailsThenRender = async (): Promise<TemplateResult | void> => {
|
||||
if (!this.hass || !this.cameras || !this.view) {
|
||||
return;
|
||||
}
|
||||
const browseMediaParams = BrowseMediaUtil.getBrowseMediaQueryParameters(
|
||||
config.controls.thumbnails.media,
|
||||
this.cameras.get(this.view.camera),
|
||||
);
|
||||
if (!browseMediaParams) {
|
||||
return;
|
||||
}
|
||||
let parent: FrigateBrowseMediaSource | null;
|
||||
try {
|
||||
parent = await BrowseMediaUtil.browseMediaQuery(this.hass, browseMediaParams);
|
||||
} catch (e) {
|
||||
return dispatchErrorMessageEvent(this, (e as Error).message);
|
||||
}
|
||||
|
||||
if (BrowseMediaUtil.getFirstTrueMediaChildIndex(parent) != null) {
|
||||
return html`<frigate-card-thumbnail-carousel
|
||||
.target=${parent}
|
||||
.view=${this.view}
|
||||
.config=${config.controls.thumbnails}
|
||||
.highlight_selected=${false}
|
||||
@frigate-card:carousel:tap=${(ev: CustomEvent<ThumbnailCarouselTap>) => {
|
||||
const mediaType = browseMediaParams.mediaType;
|
||||
if (mediaType && this.view && ['snapshots', 'clips'].includes(mediaType)) {
|
||||
new View({
|
||||
view: mediaType === 'clips' ? 'clip' : 'snapshot',
|
||||
camera: this.view.camera,
|
||||
target: ev.detail.target,
|
||||
childIndex: ev.detail.childIndex,
|
||||
}).dispatchChangeEvent(this);
|
||||
}
|
||||
}}
|
||||
>
|
||||
</frigate-card-thumbnail-carousel>`;
|
||||
}
|
||||
};
|
||||
|
||||
const fillerStyle = {
|
||||
height: config.controls.thumbnails.size,
|
||||
};
|
||||
|
||||
// As the live carousel moves, thumbnails are re-fetched. This is an async
|
||||
// request, so it can jarring to the user to have the main camera view nudge
|
||||
// up/down as the thumbnails disappear and re-appear. Instead, if there was
|
||||
// previously a thumbnail carousel rendered, use a filler that is the same
|
||||
// size until it is replaced with a real carousel (or empty, if no carousel
|
||||
// is rendered for the next camera).
|
||||
return html`${until(
|
||||
fetchThumbnailsThenRender(),
|
||||
this._thumbnailCarousel
|
||||
? html` <div style="${styleMap(fillerStyle)}"></div>`
|
||||
: html``,
|
||||
)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Master render method.
|
||||
* @returns A rendered template.
|
||||
*/
|
||||
protected render(): TemplateResult | void {
|
||||
if (!this.hass || !this.liveConfig || !this.cameras) {
|
||||
if (!this.hass || !this.liveConfig || !this.cameras || !this.view) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,11 +135,24 @@ export class FrigateCardLive extends LitElement {
|
||||
this.conditionState,
|
||||
) as LiveConfig;
|
||||
|
||||
const browseMediaParams = BrowseMediaUtil.getBrowseMediaQueryParameters(
|
||||
config.controls.thumbnails.media,
|
||||
this.cameras.get(this.view.camera),
|
||||
);
|
||||
if (!browseMediaParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Note use of liveConfig and not config below -- the carousel will
|
||||
// independently override the liveconfig to reflect the camera in the
|
||||
// carousel (not necessarily the selected camera).
|
||||
return html`
|
||||
${config.controls.thumbnails.mode === 'above' ? this.renderThumbnails(config) : ''}
|
||||
return html` <frigate-card-surround-thumbnails
|
||||
.hass=${this.hass}
|
||||
.view=${this.view}
|
||||
.config=${config.controls.thumbnails}
|
||||
.targetView=${config.controls.thumbnails.media == 'clips' ? 'clip' : 'snapshot'}
|
||||
.browseMediaParams=${browseMediaParams}
|
||||
>
|
||||
<frigate-card-live-carousel
|
||||
.hass=${this.hass}
|
||||
.view=${this.view}
|
||||
@@ -228,8 +174,7 @@ export class FrigateCardLive extends LitElement {
|
||||
}}
|
||||
>
|
||||
</frigate-card-live-carousel>
|
||||
${config.controls.thumbnails.mode === 'below' ? this.renderThumbnails(config) : ''}
|
||||
`;
|
||||
</frigate-card-surround-thumbnails>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user