| 1 | import { Component, useState } from "@odoo/owl"; |
| 2 | import { browser } from "@web/core/browser/browser"; |
| 3 | import { isMobileOS } from "@web/core/browser/feature_detection"; |
| 4 | import { useService } from "@web/core/utils/hooks"; |
| 5 | |
| 6 | export class PttAdBanner extends Component { |
| 7 | static template = "discuss.pttAdBanner"; |
| 8 | static props = {}; |
| 9 | static LOCAL_STORAGE_KEY = "ptt_ad_banner_discarded"; |
| 10 | |
| 11 | setup() { |
| 12 | super.setup(); |
| 13 | this.pttExtService = useService("discuss.ptt_extension"); |
| 14 | this.store = useService("mail.store"); |
| 15 | this.state = useState({ |
| 16 | wasDiscarded: browser.localStorage.getItem(PttAdBanner.LOCAL_STORAGE_KEY), |
| 17 | }); |
| 18 | } |
| 19 | |
| 20 | onClickClose() { |
| 21 | browser.localStorage.setItem(PttAdBanner.LOCAL_STORAGE_KEY, true); |
| 22 | this.state.wasDiscarded = true; |
| 23 | } |
| 24 | |
| 25 | get isVisible() { |
| 26 | return ( |
| 27 | !this.pttExtService.isEnabled && |
| 28 | this.store.settings.use_push_to_talk && |
| 29 | !isMobileOS() && |
| 30 | !this.state.wasDiscarded |
| 31 | ); |
| 32 | } |
| 33 | } |