Avoid resetting timeline when cameraIDs change.

This commit is contained in:
Dermot Duffy
2023-01-30 19:53:29 -08:00
parent ac295327ec
commit 93e8a8e71b
3 changed files with 27 additions and 13 deletions
+20 -3
View File
@@ -61,6 +61,8 @@ export class FrigateCardSurround extends LitElement {
@property({ attribute: false }) @property({ attribute: false })
public cameraManager?: CameraManager; public cameraManager?: CameraManager;
protected _cameraIDsForTimeline?: Set<string>;
/** /**
* Fetch thumbnail media when a target is not specified in the view (e.g. for * Fetch thumbnail media when a target is not specified in the view (e.g. for
* the live view). * the live view).
@@ -113,6 +115,16 @@ export class FrigateCardSurround extends LitElement {
import('./timeline.js'); import('./timeline.js');
} }
// Only reset the timeline cameraIDs when the media materially changes (and
// not on every view change, since the view will change frequently when the
// user is scrubbing video).
if (
changedProperties.has('view') &&
View.isMediaChange(changedProperties.get('view'), this.view)
) {
this._cameraIDsForTimeline = this._getCameraIDsForTimeline() ?? undefined;
}
// Once the component will certainly update, dispatch a media request. Only // Once the component will certainly update, dispatch a media request. Only
// do so if properties relevant to the request have changed (as per their // do so if properties relevant to the request have changed (as per their
// hasChanged). // hasChanged).
@@ -125,7 +137,7 @@ export class FrigateCardSurround extends LitElement {
} }
} }
protected _getCameraIDsForView(): Set<string> | null { protected _getCameraIDsForTimeline(): Set<string> | null {
if (!this.view || !this.cameras) { if (!this.view || !this.cameras) {
return null; return null;
} }
@@ -133,7 +145,12 @@ export class FrigateCardSurround extends LitElement {
return getAllDependentCameras(this.cameras, this.view.camera); return getAllDependentCameras(this.cameras, this.view.camera);
} }
if (this.view.isViewerView()) { if (this.view.isViewerView()) {
return new Set(this.view.queryResults?.getResults()?.map((media) => media.getCameraID())); return new Set(
this.view.query
?.getQueries()
?.map((query) => [...query.cameraIDs])
.flat(),
);
} }
return null; return null;
} }
@@ -205,7 +222,7 @@ export class FrigateCardSurround extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.view=${this.view} .view=${this.view}
.cameras=${this.cameras} .cameras=${this.cameras}
.cameraIDs=${this._getCameraIDsForView() ?? undefined} .cameraIDs=${this._cameraIDsForTimeline}
.mini=${true} .mini=${true}
.timelineConfig=${this.timelineConfig} .timelineConfig=${this.timelineConfig}
.thumbnailDetails=${this.thumbnailConfig?.show_details} .thumbnailDetails=${this.thumbnailConfig?.show_details}
+3 -4
View File
@@ -42,7 +42,6 @@ import {
dispatchFrigateCardEvent, dispatchFrigateCardEvent,
isHoverableDevice, isHoverableDevice,
} from '../utils/basic'; } from '../utils/basic';
import { getAllDependentCameras } from '../utils/camera.js';
import { import {
createViewForEvents, createViewForEvents,
@@ -186,7 +185,7 @@ export class FrigateCardTimelineCore extends LitElement {
// Which cameraIDs to include in the timeline. If not specified, all cameraIDs // Which cameraIDs to include in the timeline. If not specified, all cameraIDs
// are shown. // are shown.
@property({ attribute: false }) @property({ attribute: false, hasChanged: contentsChanged })
public cameraIDs?: Set<string>; public cameraIDs?: Set<string>;
@property({ attribute: false }) @property({ attribute: false })
@@ -343,8 +342,7 @@ export class FrigateCardTimelineCore extends LitElement {
const targetBarOn = const targetBarOn =
!this._locked || !this._locked ||
(!this.view?.is('timeline') && (this.mini && this._timeline.getSelection().some((id) => {
this._timeline.getSelection().some((id) => {
const item = this._timelineSource?.dataset?.get(id); const item = this._timelineSource?.dataset?.get(id);
return ( return (
item && item &&
@@ -1049,6 +1047,7 @@ export class FrigateCardTimelineCore extends LitElement {
protected _destroy(): void { protected _destroy(): void {
this._timeline?.destroy(); this._timeline?.destroy();
this._timeline = undefined; this._timeline = undefined;
this._targetBarVisible = false;
} }
/** /**
+4 -6
View File
@@ -1,7 +1,7 @@
// Minor / later: // Minor / later:
// - TODO: ts-prune https://camchenry.com/blog/deleting-dead-code-in-typescript // - TODO: ts-prune https://camchenry.com/blog/deleting-dead-code-in-typescript
// - TODO: View a media in the gallery from September, then notice timeline missing the item. // - TODO: Changing camera in live view, timeline stays the same.
// - TODO: Timeline initial load, then drag, appears to reset?
// Gallery: // Gallery:
// - TODO: Filter panel expands from right can occasionally 'stick' open. // - TODO: Filter panel expands from right can occasionally 'stick' open.
@@ -82,10 +82,8 @@ export class View {
// When in the live view, the queryResults contain the events that // When in the live view, the queryResults contain the events that
// happened in the past -- not reflective of the actual live media viewer // happened in the past -- not reflective of the actual live media viewer
// the user is seeing. // the user is seeing.
(curr.view !== 'live' && // TODO: Put stuff here that can be used in timeline reset code
(prev.queryResults !== curr.queryResults || (curr.view !== 'live' && (prev.queryResults !== curr.queryResults || prev.queryResults?.getSelectedResult() !== curr.queryResults?.getSelectedResult()))
prev.queryResults?.getSelectedResult() !==
curr.queryResults?.getSelectedResult()))
); );
} }