Move gallery to component.

This commit is contained in:
Dermot Duffy
2021-09-20 21:33:37 -07:00
parent 023c66b137
commit 9bbf46d4a5
7 changed files with 334 additions and 151 deletions
+46
View File
@@ -0,0 +1,46 @@
import type { BrowseMediaSource, FrigateCardView } from './types';
export interface ViewParameters {
view?: FrigateCardView;
target?: BrowseMediaSource;
childIndex?: number;
previous?: View;
}
export class View {
view: FrigateCardView;
target?: BrowseMediaSource;
childIndex?: number;
previous?: View;
constructor(params?: ViewParameters) {
this.view = params?.view || 'live';
this.target = params?.target;
this.childIndex = params?.childIndex;
this.previous = params?.previous;
}
public is(name: string): boolean {
return this.view == name;
}
get media(): BrowseMediaSource | undefined {
if (this.target) {
if (this.target.children && this.childIndex !== undefined) {
return this.target.children[this.childIndex];
}
return this.target;
}
return undefined;
}
public generateChangeEvent(node: HTMLElement): void {
node.dispatchEvent(
new CustomEvent<View>('frigate-card:change-view', {
bubbles: true,
composed: true,
detail: this,
}),
);
}
}