Sha256: cde1f0ca8350d8631dc13fbdb1a6fc634e5d507339ff83c9ef49ed287c9eef29

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

import ApplicationController from "signum/controllers/application_controller"

export default class extends ApplicationController {
  static targets = ["alertBellIcon", "bellIcon", "submenu", "item", "crossIcon"]

  connect() {
    this.bounditemActivity = this.itemActivity.bind(this)
    window.addEventListener("nd-item-activity", this.bounditemActivity)

    setTimeout(() => {
      this.manageBellIcon()
    }, 300)
  }

  disconnect() {
    window.removeEventListener("nd-item-activity", this.bounditemActivity)
  }

  show(event) {
    if (this.submenuTarget.children.length > 0) {
      this.submenuTarget.classList.remove("hidden")
      this.crossIconTarget.classList.remove("hidden")
    } else {
      this.submenuTarget.classList.add("hidden")
    }
  }

  hide(event) {
    this.submenuTarget.classList.add("hidden")
    this.crossIconTarget.classList.add("hidden")
    if (this.submenuTarget.children.length < 0) {
      this.alertBellIconTarget.classList.add("hidden")
    }
  }

  closeNotifications(event) {
    fetch("/signal/close_all", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({}),
    })
      .then((res) => {
        setTimeout(() => {
          this.manageBellIcon()
        }, 300)
      })
      .catch((err) => {
        console.log(err)
      })
  }

  itemActivity(event) {
    this.manageBellIcon()

    if (this.submenuTarget.children.length == 0) {
      this.hide(event)
    }
  }

  manageBellIcon() {
    if (this.submenuTarget.children.length > 0) {
      this.alertBellIconTarget.classList.remove("hidden")
      this.bellIconTarget.classList.add("hidden")
    } else {
      this.alertBellIconTarget.classList.add("hidden")
      this.bellIconTarget.classList.remove("hidden")
      this.crossIconTarget.classList.add("hidden")
    }
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signum-0.7.4 app/components/signum/notification_drawer/component_controller.js