Fix bug that caused gallery to render wrong media type.
This commit is contained in:
+40
-1
@@ -1,7 +1,8 @@
|
||||
import { ViewContext } from 'view';
|
||||
import { FrigateCardView } from '../types.js';
|
||||
import { ClipsOrSnapshots, FrigateCardView } from '../types.js';
|
||||
import { dispatchFrigateCardEvent } from '../utils/basic.js';
|
||||
import { MediaQueries } from './media-queries';
|
||||
import { MediaQueriesClassifier } from './media-queries-classifier.js';
|
||||
import { MediaQueriesResults } from './media-queries-results';
|
||||
|
||||
interface ViewEvolveParameters {
|
||||
@@ -60,6 +61,44 @@ export class View {
|
||||
);
|
||||
}
|
||||
|
||||
public static adoptQueryIfAppropriate(next: View, curr?: View): void {
|
||||
// Special case: If the user is currently using the viewer, and then
|
||||
// switches to the gallery we make an attempt to keep the query/queryResults
|
||||
// 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
|
||||
// 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
|
||||
|
||||
let currentQueriesView: ClipsOrSnapshots | 'recordings' | null = null;
|
||||
if (MediaQueriesClassifier.areEventQueries(curr?.query)) {
|
||||
const queries = curr?.query.getQueries();
|
||||
if (queries?.every((query) => query.hasClip)) {
|
||||
currentQueriesView = 'clips';
|
||||
} else if (queries?.every((query) => query.hasSnapshot)) {
|
||||
currentQueriesView = 'snapshots';
|
||||
}
|
||||
} else if (MediaQueriesClassifier.areRecordingQueries(curr?.query)) {
|
||||
currentQueriesView = 'recordings';
|
||||
}
|
||||
|
||||
if (
|
||||
curr?.isViewerView() &&
|
||||
next.isGalleryView() &&
|
||||
(!next.query || !next.queryResults) &&
|
||||
next.view === currentQueriesView
|
||||
) {
|
||||
if (curr.query) {
|
||||
next.query = curr.query;
|
||||
}
|
||||
if (curr.queryResults) {
|
||||
next.queryResults = curr.queryResults;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone a view.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user