Don't collect infinite previous views.
This commit is contained in:
@@ -30,6 +30,17 @@ import { renderProgressIndicator } from './message.js';
|
|||||||
import './thumbnail.js';
|
import './thumbnail.js';
|
||||||
import { THUMBNAIL_DETAILS_WIDTH_MIN } from './thumbnail.js';
|
import { THUMBNAIL_DETAILS_WIDTH_MIN } from './thumbnail.js';
|
||||||
|
|
||||||
|
interface GalleryViewContext {
|
||||||
|
// Keep track of the previous view to allow returning to a higher-level folder.
|
||||||
|
previous?: View;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'view' {
|
||||||
|
interface ViewContext {
|
||||||
|
gallery?: GalleryViewContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@customElement('frigate-card-gallery')
|
@customElement('frigate-card-gallery')
|
||||||
export class FrigateCardGallery extends LitElement {
|
export class FrigateCardGallery extends LitElement {
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
@@ -100,7 +111,7 @@ export class FrigateCardGallery extends LitElement {
|
|||||||
browseMediaQueryParameters,
|
browseMediaQueryParameters,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return renderProgressIndicator({cardWideConfig: this.cardWideConfig});
|
return renderProgressIndicator({ cardWideConfig: this.cardWideConfig });
|
||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
@@ -196,9 +207,9 @@ export class FrigateCardGalleryCore extends LitElement {
|
|||||||
*/
|
*/
|
||||||
protected _showBackArrow(): boolean {
|
protected _showBackArrow(): boolean {
|
||||||
return (
|
return (
|
||||||
!!this.view?.previous &&
|
!!this.view?.context?.gallery?.previous &&
|
||||||
!!this.view.previous.target &&
|
!!this.view.context.gallery.previous.target &&
|
||||||
this.view.previous.view === this.view.view
|
this.view.context.gallery.previous.view === this.view.view
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,8 +254,8 @@ export class FrigateCardGalleryCore extends LitElement {
|
|||||||
${this._showBackArrow()
|
${this._showBackArrow()
|
||||||
? html` <ha-card
|
? html` <ha-card
|
||||||
@click=${(ev) => {
|
@click=${(ev) => {
|
||||||
if (this.view && this.view.previous) {
|
if (this.view && this.view.context?.gallery?.previous) {
|
||||||
this.view.previous.dispatchChangeEvent(this);
|
this.view.context.gallery.previous.dispatchChangeEvent(this);
|
||||||
}
|
}
|
||||||
stopEventFromActivatingCardWideActions(ev);
|
stopEventFromActivatingCardWideActions(ev);
|
||||||
}}
|
}}
|
||||||
@@ -266,6 +277,11 @@ export class FrigateCardGalleryCore extends LitElement {
|
|||||||
this.hass,
|
this.hass,
|
||||||
this.view,
|
this.view,
|
||||||
child,
|
child,
|
||||||
|
{
|
||||||
|
gallery: {
|
||||||
|
previous: this.view,
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
stopEventFromActivatingCardWideActions(ev);
|
stopEventFromActivatingCardWideActions(ev);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { HomeAssistant } from 'custom-card-helpers';
|
import { HomeAssistant } from 'custom-card-helpers';
|
||||||
|
import { ViewContext } from 'view';
|
||||||
import { homeAssistantWSRequest } from '.';
|
import { homeAssistantWSRequest } from '.';
|
||||||
import {
|
import {
|
||||||
dispatchErrorMessageEvent,
|
dispatchErrorMessageEvent,
|
||||||
@@ -346,6 +347,7 @@ export const fetchChildMediaAndDispatchViewChange = async (
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
view: Readonly<View>,
|
view: Readonly<View>,
|
||||||
child: Readonly<FrigateBrowseMediaSource>,
|
child: Readonly<FrigateBrowseMediaSource>,
|
||||||
|
context?: ViewContext,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
let parent: FrigateBrowseMediaSource;
|
let parent: FrigateBrowseMediaSource;
|
||||||
try {
|
try {
|
||||||
@@ -358,6 +360,7 @@ export const fetchChildMediaAndDispatchViewChange = async (
|
|||||||
.evolve({
|
.evolve({
|
||||||
target: parent,
|
target: parent,
|
||||||
})
|
})
|
||||||
|
.mergeInContext(context)
|
||||||
.dispatchChangeEvent(element);
|
.dispatchChangeEvent(element);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-9
@@ -13,7 +13,6 @@ export interface ViewEvolveParameters {
|
|||||||
camera?: string;
|
camera?: string;
|
||||||
target?: FrigateBrowseMediaSource | null;
|
target?: FrigateBrowseMediaSource | null;
|
||||||
childIndex?: number | null;
|
childIndex?: number | null;
|
||||||
previous?: View | null;
|
|
||||||
context?: ViewContext | null;
|
context?: ViewContext | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +26,6 @@ export class View {
|
|||||||
public camera: string;
|
public camera: string;
|
||||||
public target: FrigateBrowseMediaSource | null;
|
public target: FrigateBrowseMediaSource | null;
|
||||||
public childIndex: number | null;
|
public childIndex: number | null;
|
||||||
public previous: View | null;
|
|
||||||
public context: ViewContext | null;
|
public context: ViewContext | null;
|
||||||
|
|
||||||
constructor(params: ViewParameters) {
|
constructor(params: ViewParameters) {
|
||||||
@@ -35,7 +33,6 @@ export class View {
|
|||||||
this.camera = params.camera;
|
this.camera = params.camera;
|
||||||
this.target = params.target ?? null;
|
this.target = params.target ?? null;
|
||||||
this.childIndex = params.childIndex ?? null;
|
this.childIndex = params.childIndex ?? null;
|
||||||
this.previous = params.previous ?? null;
|
|
||||||
this.context = params.context ?? null;
|
this.context = params.context ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +87,6 @@ export class View {
|
|||||||
camera: this.camera,
|
camera: this.camera,
|
||||||
target: this.target,
|
target: this.target,
|
||||||
childIndex: this.childIndex,
|
childIndex: this.childIndex,
|
||||||
previous: this.previous,
|
|
||||||
context: this.context,
|
context: this.context,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -107,10 +103,6 @@ export class View {
|
|||||||
target: params.target !== undefined ? params.target : this.target,
|
target: params.target !== undefined ? params.target : this.target,
|
||||||
childIndex: params.childIndex !== undefined ? params.childIndex : this.childIndex,
|
childIndex: params.childIndex !== undefined ? params.childIndex : this.childIndex,
|
||||||
context: params.context !== undefined ? params.context : this.context,
|
context: params.context !== undefined ? params.context : this.context,
|
||||||
|
|
||||||
// Special case: Set the previous to this of the evolved view (rather than
|
|
||||||
// the previous of this).
|
|
||||||
previous: params.previous !== undefined ? params.previous : this,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +111,7 @@ export class View {
|
|||||||
* @param context The context to merge in.
|
* @param context The context to merge in.
|
||||||
* @returns This view.
|
* @returns This view.
|
||||||
*/
|
*/
|
||||||
public mergeInContext(context: ViewContext): View {
|
public mergeInContext(context?: ViewContext): View {
|
||||||
this.context = { ...this.context, ...context };
|
this.context = { ...this.context, ...context };
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user