From 33e7f308ed1306627923b169fa9755469e3685e0 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Wed, 11 Jan 2023 19:58:51 -0800 Subject: [PATCH] Force the timeline window always. --- src/components/timeline-core.ts | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/components/timeline-core.ts b/src/components/timeline-core.ts index ffcd51c2..f9c8d05a 100644 --- a/src/components/timeline-core.ts +++ b/src/components/timeline-core.ts @@ -71,9 +71,6 @@ interface TimelineRangeChange extends TimelineWindow { } interface TimelineViewContext { - // Force a particular timeline window rather than taking the time from an - // event / recording. The timeline itself never sets this, but respects it if - // set elsewhere on first load. window?: TimelineWindow; } @@ -432,6 +429,7 @@ export class FrigateCardTimelineCore extends LitElement { }) // Whether or not to set the timeline window. .mergeInContext({ ...(canSeek && { mediaViewer: { seek: targetTime } }), + ...this._setWindowInContext(properties) }) .dispatchChangeEvent(this); } @@ -601,7 +599,9 @@ export class FrigateCardTimelineCore extends LitElement { await this._createViewWithEventMediaQuery( this._createEventMediaQuerys({ window: this._timeline.getWindow() }), ) - )?.dispatchChangeEvent(this); + ) + ?.mergeInContext(this._setWindowInContext()) + ?.dispatchChangeEvent(this); } } @@ -956,17 +956,7 @@ export class FrigateCardTimelineCore extends LitElement { !this._alreadyHasAcceptableMediaQuery(freshMediaQuery) ) { (await this._createViewWithEventMediaQuery(freshMediaQuery)) - ?.mergeInContext(this._removeWindowFromContext()) - .dispatchChangeEvent(this); - } else if (this.view.context?.timeline?.window) { - // No matter what, always remove the window context if it's set, otherwise - // the timeline can 'jump' (e.g. if window context is set, timeline window - // gets set to that, then the user subsequently manually moves the - // timeline but then a view is re-dispatched for some other reason -- it - // would cause the timeline to jump back to the original context window) . - this.view - .clone() - ?.mergeInContext(this._removeWindowFromContext()) + ?.mergeInContext(this._setWindowInContext(desiredWindow)) .dispatchChangeEvent(this); } } @@ -988,10 +978,14 @@ export class FrigateCardTimelineCore extends LitElement { * Generate the context for timeline views. * @returns The TimelineViewContext object. */ - protected _removeWindowFromContext(): ViewContext { - const newContext = {...this.view?.context?.timeline} - delete newContext.window; - return { timeline: newContext }; + protected _setWindowInContext(window?: TimelineWindow): ViewContext { + const newWindow = window ?? this._timeline?.getWindow(); + return { + timeline: { + ...this.view?.context?.timeline, + ...(newWindow && { window: newWindow }), + }, + }; } /**