Fix clicking on timeline recordings.

This commit is contained in:
Dermot Duffy
2023-04-15 12:19:23 -07:00
parent 24f92fd78c
commit 69b34d7ea1
3 changed files with 55 additions and 30 deletions
+1 -1
View File
@@ -857,7 +857,7 @@ class FrigateCard extends LitElement {
this._resetMainScroll(); this._resetMainScroll();
} }
View.adoptQueryIfAppropriate(view, this._view); View.adoptFromViewIfAppropriate(view, this._view);
this._view = view; this._view = view;
this._generateConditionState(); this._generateConditionState();
+10 -5
View File
@@ -545,11 +545,16 @@ export class FrigateCardTimelineCore extends LitElement {
this.timelineConfig?.show_recordings && this.timelineConfig?.show_recordings &&
['background', 'group-label'].includes(properties.what) ['background', 'group-label'].includes(properties.what)
) { ) {
const query = createQueriesForRecordingsView( const cameraIDs = properties.group
this.cameraManager, ? new Set([String(properties.group)])
this.cardWideConfig, : this._getTimelineCameraIDs();
new Set([String(properties.group)]), const query = cameraIDs
); ? createQueriesForRecordingsView(
this.cameraManager,
this.cardWideConfig,
cameraIDs,
)
: null;
if (query) { if (query) {
view = await executeMediaQueryForView( view = await executeMediaQueryForView(
this, this,
+44 -24
View File
@@ -61,40 +61,60 @@ export class View {
); );
} }
public static adoptQueryIfAppropriate(next: View, curr?: View): void { public static adoptFromViewIfAppropriate(next: View, curr?: View): void {
// Special case: If the user is currently using the viewer, and then if (!curr) {
// switches to the gallery we make an attempt to keep the query/queryResults return;
// the same so the gallery can be used to click back and forth to the }
// viewer, and the selected media can be centered in the gallery. See the
// matching code in `updated()` in `gallery.ts`. We specifically must ensure // In certain cases it may make sense to adopt parameters from a prior view.
// that the new target media of the gallery (e.g. clips, snapshots or //
// recordings) is equal to the queries that are currently used in the // * Case #1: If the user is currently using the viewer, and then switches
// viewer. // to the gallery we make an attempt to keep the query/queryResults the
// See: https://github.com/dermotduffy/frigate-hass-card/issues/885 // same so the gallery can be used to click back and forth to the viewer,
// and the selected media can be centered in the gallery. See the matching
// code in `updated()` in `gallery.ts`. We specifically must ensure that
// the new target media of the gallery (e.g. clips, snapshots or
// recordings) is equal to the queries that are currently used in the
// viewer. See:
// https://github.com/dermotduffy/frigate-hass-card/issues/885
//
// * Case #2: If the user is looking at media in the `media` view and then
// changes camera to the *current* camera (via the menu) it will cause a
// new view to issue without a query and just the 'media' view, which
// means the viewer cannot know what kind of media to fetch.
let currentQueriesView: ClipsOrSnapshots | 'recordings' | null = null; let currentQueriesView: ClipsOrSnapshots | 'recordings' | null = null;
if (MediaQueriesClassifier.areEventQueries(curr?.query)) { if (MediaQueriesClassifier.areEventQueries(curr.query)) {
const queries = curr?.query.getQueries(); const queries = curr.query.getQueries();
if (queries?.every((query) => query.hasClip)) { if (queries?.every((query) => query.hasClip)) {
currentQueriesView = 'clips'; currentQueriesView = 'clips';
} else if (queries?.every((query) => query.hasSnapshot)) { } else if (queries?.every((query) => query.hasSnapshot)) {
currentQueriesView = 'snapshots'; currentQueriesView = 'snapshots';
} }
} else if (MediaQueriesClassifier.areRecordingQueries(curr?.query)) { } else if (MediaQueriesClassifier.areRecordingQueries(curr.query)) {
currentQueriesView = 'recordings'; currentQueriesView = 'recordings';
} }
if ( const hasNoQueryOrResults = !next.query || !next.queryResults;
curr?.isViewerView() && const switchingToGalleryFromViewer =
next.isGalleryView() && curr.isViewerView() && next.isGalleryView() && next.view === currentQueriesView;
(!next.query || !next.queryResults) && const switchingToMediaFromMedia = curr?.is('media') && next.is('media');
next.view === currentQueriesView
) { if (hasNoQueryOrResults) {
if (curr.query) { if (switchingToGalleryFromViewer) {
next.query = curr.query; if (curr.query) {
} next.query = curr.query;
if (curr.queryResults) { }
next.queryResults = curr.queryResults; if (curr.queryResults) {
next.queryResults = curr.queryResults;
}
} else if (switchingToMediaFromMedia && currentQueriesView) {
next.view =
currentQueriesView === 'clips'
? 'clip'
: currentQueriesView === 'snapshots'
? 'snapshot'
: 'recording';
} }
} }
} }