Allow views to have no selection.

This commit is contained in:
Dermot Duffy
2023-03-07 19:27:08 -08:00
parent 7f1fcf454e
commit 1851a563c0
5 changed files with 32 additions and 7 deletions
+10 -2
View File
@@ -120,6 +120,7 @@ export class FrigateCardViewer extends LitElement {
this.view,
{
targetView: 'recording',
select: 'latest',
},
);
} else {
@@ -132,6 +133,7 @@ export class FrigateCardViewer extends LitElement {
{
targetView: 'media',
mediaType: mediaType,
select: 'latest',
},
);
}
@@ -543,13 +545,19 @@ export class FrigateCardViewerCarousel extends LitElement {
* @returns A template to display to the user.
*/
protected _render(): TemplateResult | void {
if ((this.view?.queryResults?.getResultsCount() ?? 0) === 0) {
const resultCount = this.view?.queryResults?.getResultsCount() ?? 0;
if (!resultCount) {
return dispatchMessageEvent(this, localize('common.no_media'), 'info', {
icon: 'mdi:multimedia',
});
}
const media = this.view?.queryResults?.getSelectedResult();
// If there's no selected media, just choose the last (most recent one) to
// avoid rendering a blank. This situation should not occur in practice, as
// this view should not be called without a selected media.
const media =
this.view?.queryResults?.getSelectedResult() ??
this.view?.queryResults?.getResult(resultCount - 1);
if (!media || !this.view || !this.view.queryResults) {
return;
}