Sha256: 2d96c3696496bd9148f21bea19966d709169eb608b31b4dce73b3e76e84f49a0

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

import ApplicationController from "signum/controllers/application_controller"
import { post } from '@rails/request.js';

export default class extends ApplicationController {
  static values = { type: String, timeout: Number, sticky: Boolean, signalId: String, signalState: String }
  connect() {
    if (this.typeValue == "balloon" && !this.stickyValue) {
      this.timeoutId = setTimeout(() => {
        this.close()
      }, this.timeoutValue * 1000 + 500)
    }
  }

  close(event) {
    setTimeout(() => {
      this.element?.parentElement?.remove()
      if (event && this.typeValue != "balloon") {
        this.markClose()
      }
    }, 300)
  }

  async markClose() {
    try {
      const response = await post('/signal/close', {
        body: JSON.stringify({ id: this.signalIdValue }),
        contentType: 'application/json'
      });
      if (response.ok) {
        const niE = new CustomEvent("nd-item-activity", {
          bubbles: true,
          detail: "closed",
        });
        window.dispatchEvent(niE);
      } else {
        console.error('Error: ', response.statusText);
      }
    } catch (error) {
      console.error('Request failed', error);
    }
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signum-0.7.8 app/components/signum/notification_body/component_controller.js