/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* eslint-env mozilla/remote-page */ import { html, styleMap } from "chrome://global/content/vendor/lit.all.mjs"; import { MozLitElement } from "chrome://global/content/lit-utils.mjs"; // eslint-disable-next-line import/no-unassigned-import import "chrome://global/content/elements/moz-message-bar.mjs"; const SHOPPING_SIDEBAR_ACTIVE_PREF = "browser.shopping.experience2023.active"; const SHOW_KEEP_SIDEBAR_CLOSED_MESSAGE_PREF = "browser.shopping.experience2023.showKeepSidebarClosedMessage"; const SHOPPING_AUTO_OPEN_SIDEBAR_PREF = "browser.shopping.experience2023.autoOpen.userEnabled"; class ShoppingMessageBar extends MozLitElement { #MESSAGE_TYPES_RENDER_TEMPLATE_MAPPING = new Map([ ["stale", () => this.staleWarningTemplate()], ["generic-error", () => this.genericErrorTemplate()], ["not-enough-reviews", () => this.notEnoughReviewsTemplate()], ["product-not-available", () => this.productNotAvailableTemplate()], ["thanks-for-reporting", () => this.thanksForReportingTemplate()], [ "product-not-available-reported", () => this.productNotAvailableReportedTemplate(), ], ["analysis-in-progress", () => this.analysisInProgressTemplate()], ["reanalysis-in-progress", () => this.reanalysisInProgressTemplate()], ["page-not-supported", () => this.pageNotSupportedTemplate()], ["thank-you-for-feedback", () => this.thankYouForFeedbackTemplate()], ["keep-closed", () => this.keepClosedTemplate()], ]); static properties = { type: { type: String }, productUrl: { type: String, reflect: true }, progress: { type: Number, reflect: true }, }; static get queries() { return { reAnalysisButtonEl: "#message-bar-reanalysis-button", productAvailableBtnEl: "#message-bar-report-product-available-btn", yesKeepClosedButtonEl: "#yes-keep-closed-button", noThanksButtonEl: "#no-thanks-button", }; } onClickAnalysisButton() { this.dispatchEvent( new CustomEvent("ReanalysisRequested", { bubbles: true, composed: true, }) ); Glean.shopping.surfaceReanalyzeClicked.record(); } onClickProductAvailable() { this.dispatchEvent( new CustomEvent("ReportedProductAvailable", { bubbles: true, composed: true, }) ); } handleNoThanksClick() { RPMSetPref(SHOPPING_SIDEBAR_ACTIVE_PREF, false); RPMSetPref(SHOW_KEEP_SIDEBAR_CLOSED_MESSAGE_PREF, false); this.dispatchEvent( new CustomEvent("HideKeepClosedMessage", { bubbles: true, composed: true, }) ); Glean.shopping.surfaceNoThanksButtonClicked.record(); } handleKeepClosedClick() { RPMSetPref(SHOPPING_SIDEBAR_ACTIVE_PREF, false); RPMSetPref(SHOW_KEEP_SIDEBAR_CLOSED_MESSAGE_PREF, false); RPMSetPref(SHOPPING_AUTO_OPEN_SIDEBAR_PREF, false); this.dispatchEvent( new CustomEvent("HideKeepClosedMessage", { bubbles: true, composed: true, }) ); Glean.shopping.surfaceYesKeepClosedButtonClicked.record(); } staleWarningTemplate() { return html`
`; } genericErrorTemplate() { return html` `; } notEnoughReviewsTemplate() { return html` `; } productNotAvailableTemplate() { return html` `; } thanksForReportingTemplate() { return html` `; } productNotAvailableReportedTemplate() { return html` `; } analysisInProgressTemplate() { return html`
`; } reanalysisInProgressTemplate() { return html`
`; } pageNotSupportedTemplate() { return html` `; } thankYouForFeedbackTemplate() { return html` `; } keepClosedTemplate() { return html` `; } render() { let messageBarTemplate = this.#MESSAGE_TYPES_RENDER_TEMPLATE_MAPPING.get( this.type )(); if (messageBarTemplate) { if (this.type == "stale") { Glean.shopping.surfaceStaleAnalysisShown.record(); } return html` ${messageBarTemplate} `; } return null; } } customElements.define("shopping-message-bar", ShoppingMessageBar);