Merge pull request #201 from dermotduffy/use-action-handler

Fix bug where touchevents were being ignored by elements within the card
This commit is contained in:
Dermot Duffy
2021-11-18 10:05:19 -08:00
committed by GitHub
3 changed files with 53 additions and 26 deletions
+10 -17
View File
@@ -677,22 +677,6 @@ export class FrigateCard extends LitElement {
return `${this.config.frigate.url}/events?camera=${this._frigateCameraName}`; return `${this.config.frigate.url}/events?camera=${this._frigateCameraName}`;
} }
/**
* Handle interaction with the card.
*/
protected _interactionHandler(): void {
if (!this.config.view.timeout) {
return;
}
if (this._interactionTimerID) {
window.clearTimeout(this._interactionTimerID);
}
this._interactionTimerID = window.setTimeout(() => {
this._interactionTimerID = null;
this._changeView();
}, this.config.view.timeout * 1000);
}
/** /**
* Handle an action called on an element. * Handle an action called on an element.
* @param ev The actionHandler event. * @param ev The actionHandler event.
@@ -718,6 +702,16 @@ export class FrigateCard extends LitElement {
) { ) {
handleAction(node, this._hass as HomeAssistant, config, ev.detail.action); handleAction(node, this._hass as HomeAssistant, config, ev.detail.action);
} }
if (this.config.view.timeout) {
if (this._interactionTimerID) {
window.clearTimeout(this._interactionTimerID);
}
this._interactionTimerID = window.setTimeout(() => {
this._interactionTimerID = null;
this._changeView();
}, this.config.view.timeout * 1000);
}
} }
/** /**
@@ -962,7 +956,6 @@ export class FrigateCard extends LitElement {
const actions = this._getMergedActions(); const actions = this._getMergedActions();
return html` <ha-card return html` <ha-card
@click=${this._interactionHandler}
.actionHandler=${actionHandler({ .actionHandler=${actionHandler({
hasHold: hasAction(actions.hold_action), hasHold: hasAction(actions.hold_action),
hasDoubleClick: hasAction(actions.double_tap_action), hasDoubleClick: hasAction(actions.double_tap_action),
+16 -3
View File
@@ -17,6 +17,7 @@ import { localize } from '../localize/localize.js';
import { renderProgressIndicator } from './message.js'; import { renderProgressIndicator } from './message.js';
import galleryStyle from '../scss/gallery.scss'; import galleryStyle from '../scss/gallery.scss';
import { actionHandler } from '../action-handler-directive.js';
const MAX_THUMBNAIL_WIDTH = 175; const MAX_THUMBNAIL_WIDTH = 175;
const DEFAULT_COLUMNS = 5; const DEFAULT_COLUMNS = 5;
@@ -155,7 +156,11 @@ export class FrigateCardGalleryCore extends LitElement {
<div class="mdc-image-list__image-aspect-container"> <div class="mdc-image-list__image-aspect-container">
<div class="mdc-image-list__image"> <div class="mdc-image-list__image">
<ha-card <ha-card
@click=${() => { .actionHandler=${actionHandler({
hasHold: false,
hasDoubleClick: false,
})}
@action=${() => {
if (this.view && this.view.previous) { if (this.view && this.view.previous) {
this.view.previous.dispatchChangeEvent(this); this.view.previous.dispatchChangeEvent(this);
} }
@@ -176,7 +181,11 @@ export class FrigateCardGalleryCore extends LitElement {
${child.can_expand ${child.can_expand
? html`<div class="mdc-image-list__image"> ? html`<div class="mdc-image-list__image">
<ha-card <ha-card
@click=${() => { .actionHandler=${actionHandler({
hasHold: false,
hasDoubleClick: false,
})}
@action=${() => {
if (this.view) { if (this.view) {
new View({ new View({
view: this.view.view, view: this.view.view,
@@ -196,7 +205,11 @@ export class FrigateCardGalleryCore extends LitElement {
title="${child.title}" title="${child.title}"
class="mdc-image-list__image" class="mdc-image-list__image"
src="${child.thumbnail}" src="${child.thumbnail}"
@click=${() => { .actionHandler=${actionHandler({
hasHold: false,
hasDoubleClick: false,
})}
@action=${() => {
if (this.view) { if (this.view) {
new View({ new View({
view: this.view.is('clips') view: this.view.is('clips')
+27 -6
View File
@@ -38,6 +38,7 @@ import { renderProgressIndicator } from '../components/message.js';
import './next-prev-control.js'; import './next-prev-control.js';
import viewerStyle from '../scss/viewer.scss'; import viewerStyle from '../scss/viewer.scss';
import { actionHandler } from '../action-handler-directive.js';
const getEmptyImageSrc = (width: number, height: number) => const getEmptyImageSrc = (width: number, height: number) =>
`data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}"%3E%3C/svg%3E`; `data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}"%3E%3C/svg%3E`;
@@ -485,7 +486,13 @@ export class FrigateCardViewerCore extends LitElement {
.controlConfig=${this.viewerConfig?.controls.next_previous} .controlConfig=${this.viewerConfig?.controls.next_previous}
.thumbnail=${neighbors.previous.thumbnail} .thumbnail=${neighbors.previous.thumbnail}
.title=${neighbors.previous.title} .title=${neighbors.previous.title}
@click=${() => this._nextPreviousHandler('previous')} .actionHandler=${actionHandler({
hasHold: false,
hasDoubleClick: false,
})}
@action=${() => {
this._nextPreviousHandler('previous');
}}
></frigate-card-next-previous-control>` ></frigate-card-next-previous-control>`
: ``} : ``}
<div class="embla"> <div class="embla">
@@ -499,7 +506,13 @@ export class FrigateCardViewerCore extends LitElement {
.controlConfig=${this.viewerConfig?.controls.next_previous} .controlConfig=${this.viewerConfig?.controls.next_previous}
.thumbnail=${neighbors.next.thumbnail} .thumbnail=${neighbors.next.thumbnail}
.title=${neighbors.next.title} .title=${neighbors.next.title}
@click=${() => this._nextPreviousHandler('next')} .actionHandler=${actionHandler({
hasHold: false,
hasDoubleClick: false,
})}
@action=${() => {
this._nextPreviousHandler('next');
}}
></frigate-card-next-previous-control>` ></frigate-card-next-previous-control>`
: ``} : ``}
</div>`; </div>`;
@@ -575,7 +588,7 @@ export class FrigateCardViewerCore extends LitElement {
this.renderRoot.querySelectorAll('.embla__container img').forEach((img) => { this.renderRoot.querySelectorAll('.embla__container img').forEach((img) => {
const imageElement: HTMLImageElement = img as HTMLImageElement; const imageElement: HTMLImageElement = img as HTMLImageElement;
if (imageElement.src === IMG_EMPTY) { if (imageElement.src === IMG_EMPTY) {
imageElement.src = replacementImageSrc imageElement.src = replacementImageSrc;
} }
}); });
} }
@@ -658,7 +671,11 @@ export class FrigateCardViewerCore extends LitElement {
src=${ifDefined(lazyLoad ? IMG_EMPTY : resolvedMedia.url)} src=${ifDefined(lazyLoad ? IMG_EMPTY : resolvedMedia.url)}
data-src=${ifDefined(lazyLoad ? resolvedMedia.url : undefined)} data-src=${ifDefined(lazyLoad ? resolvedMedia.url : undefined)}
title="${mediaToRender.title}" title="${mediaToRender.title}"
@click=${() => { .actionHandler=${actionHandler({
hasHold: false,
hasDoubleClick: false,
})}
@action=${() => {
if (this._carousel?.clickAllowed()) { if (this._carousel?.clickAllowed()) {
this._findRelatedClipView(mediaToRender).then((view) => { this._findRelatedClipView(mediaToRender).then((view) => {
if (view) { if (view) {
@@ -668,10 +685,14 @@ export class FrigateCardViewerCore extends LitElement {
} }
}} }}
@load="${(e: Event) => { @load="${(e: Event) => {
if (this.viewerConfig && (!this.viewerConfig.lazy_load || this._slideHasBeenLazyLoaded[slideIndex])) { if (
this.viewerConfig &&
(!this.viewerConfig.lazy_load ||
this._slideHasBeenLazyLoaded[slideIndex])
) {
this._mediaShowInfoHandler(slideIndex, createMediaShowInfo(e)); this._mediaShowInfoHandler(slideIndex, createMediaShowInfo(e));
} }
}}" }}"
/>`} />`}
</div> </div>
`; `;