From def92d1b8e9d373e2f6f27c366d578d97d8960c6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:50 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- browser/components/sidebar/sidebar-syncedtabs.mjs | 191 ++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 browser/components/sidebar/sidebar-syncedtabs.mjs (limited to 'browser/components/sidebar/sidebar-syncedtabs.mjs') diff --git a/browser/components/sidebar/sidebar-syncedtabs.mjs b/browser/components/sidebar/sidebar-syncedtabs.mjs new file mode 100644 index 0000000000..4c3bd9dc46 --- /dev/null +++ b/browser/components/sidebar/sidebar-syncedtabs.mjs @@ -0,0 +1,191 @@ +/* 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/. */ + +const lazy = {}; +ChromeUtils.defineESModuleGetters(lazy, { + SyncedTabsController: "resource:///modules/SyncedTabsController.sys.mjs", +}); + +import { html, ifDefined } from "chrome://global/content/vendor/lit.all.mjs"; +import { + escapeHtmlEntities, + navigateToLink, +} from "chrome://browser/content/firefoxview/helpers.mjs"; + +import { SidebarPage } from "./sidebar-page.mjs"; + +class SyncedTabsInSidebar extends SidebarPage { + controller = new lazy.SyncedTabsController(this); + + constructor() { + super(); + this.onSearchQuery = this.onSearchQuery.bind(this); + } + + connectedCallback() { + super.connectedCallback(); + this.controller.addSyncObservers(); + this.controller.updateStates(); + } + + disconnectedCallback() { + super.disconnectedCallback(); + this.controller.removeSyncObservers(); + } + + /** + * The template shown when the list of synced devices is currently + * unavailable. + * + * @param {object} options + * @param {string} options.action + * @param {string} options.buttonLabel + * @param {string[]} options.descriptionArray + * @param {string} options.descriptionLink + * @param {boolean} options.error + * @param {string} options.header + * @param {string} options.headerIconUrl + * @param {string} options.mainImageUrl + * @returns {TemplateResult} + */ + messageCardTemplate({ + action, + buttonLabel, + descriptionArray, + descriptionLink, + error, + header, + headerIconUrl, + mainImageUrl, + }) { + return html` + + + + `; + } + + /** + * The template shown for a device that has tabs. + * + * @param {string} deviceName + * @param {string} deviceType + * @param {Array} tabItems + * @returns {TemplateResult} + */ + deviceTemplate(deviceName, deviceType, tabItems) { + return html` + + `; + } + + /** + * The template shown for a device that has no tabs. + * + * @param {string} deviceName + * @param {string} deviceType + * @returns {TemplateResult} + */ + noDeviceTabsTemplate(deviceName, deviceType) { + return html` + `; + } + + /** + * The template shown for a device that has tabs, but no tabs that match the + * current search query. + * + * @param {string} deviceName + * @param {string} deviceType + * @returns {TemplateResult} + */ + noSearchResultsTemplate(deviceName, deviceType) { + return html` + `; + } + + /** + * The template shown for the list of synced devices. + * + * @returns {TemplateResult[]} + */ + deviceListTemplate() { + return Object.values(this.controller.getRenderInfo()).map( + ({ name: deviceName, deviceType, tabItems, tabs }) => { + if (tabItems.length) { + return this.deviceTemplate(deviceName, deviceType, tabItems); + } else if (tabs.length) { + return this.noSearchResultsTemplate(deviceName, deviceType); + } + return this.noDeviceTabsTemplate(deviceName, deviceType); + } + ); + } + + render() { + const messageCard = this.controller.getMessageCard(); + if (messageCard) { + return [this.stylesheet(), this.messageCardTemplate(messageCard)]; + } + return html` + ${this.stylesheet()} + + ${this.deviceListTemplate()} + `; + } + + onSearchQuery(e) { + this.controller.searchQuery = e.detail.query; + this.requestUpdate(); + } +} + +customElements.define("sidebar-syncedtabs", SyncedTabsInSidebar); -- cgit v1.2.3