Force the timeline window always.

This commit is contained in:
Dermot Duffy
2023-01-24 19:36:54 -08:00
parent 1feec926dd
commit 33e7f308ed
+13 -19
View File
@@ -71,9 +71,6 @@ interface TimelineRangeChange extends TimelineWindow {
} }
interface TimelineViewContext { 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; window?: TimelineWindow;
} }
@@ -432,6 +429,7 @@ export class FrigateCardTimelineCore extends LitElement {
}) // Whether or not to set the timeline window. }) // Whether or not to set the timeline window.
.mergeInContext({ .mergeInContext({
...(canSeek && { mediaViewer: { seek: targetTime } }), ...(canSeek && { mediaViewer: { seek: targetTime } }),
...this._setWindowInContext(properties)
}) })
.dispatchChangeEvent(this); .dispatchChangeEvent(this);
} }
@@ -601,7 +599,9 @@ export class FrigateCardTimelineCore extends LitElement {
await this._createViewWithEventMediaQuery( await this._createViewWithEventMediaQuery(
this._createEventMediaQuerys({ window: this._timeline.getWindow() }), 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) !this._alreadyHasAcceptableMediaQuery(freshMediaQuery)
) { ) {
(await this._createViewWithEventMediaQuery(freshMediaQuery)) (await this._createViewWithEventMediaQuery(freshMediaQuery))
?.mergeInContext(this._removeWindowFromContext()) ?.mergeInContext(this._setWindowInContext(desiredWindow))
.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())
.dispatchChangeEvent(this); .dispatchChangeEvent(this);
} }
} }
@@ -988,10 +978,14 @@ export class FrigateCardTimelineCore extends LitElement {
* Generate the context for timeline views. * Generate the context for timeline views.
* @returns The TimelineViewContext object. * @returns The TimelineViewContext object.
*/ */
protected _removeWindowFromContext(): ViewContext { protected _setWindowInContext(window?: TimelineWindow): ViewContext {
const newContext = {...this.view?.context?.timeline} const newWindow = window ?? this._timeline?.getWindow();
delete newContext.window; return {
return { timeline: newContext }; timeline: {
...this.view?.context?.timeline,
...(newWindow && { window: newWindow }),
},
};
} }
/** /**