Files
tubestation/browser/components/myfirefox/tabs-pickup.js
Sam Foster da60508fa5 Bug 1761787 - Add a shell for the signup flow / synced tabs area of My Firefox. r=Gijs,fluent-reviewers
* Sketch in a page layout and grid to house the tab-pickup region
* Add a tabs-pickup module with custom elements for the deck of cards that is the setup flow
* and a container with placeholder logic to manage the setup flow
* Make myfirefox.js a module, hook up the tabs-pickup element with its controller/manager where we can implement the fxa flow & business logic stuff

Differential Revision: https://phabricator.services.mozilla.com/D142661
2022-04-11 23:18:35 +00:00

132 lines
3.8 KiB
JavaScript

/* 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/frame-script */
const tabsSetupFlowManager = new (class {
initialize(elem) {
this.elem = elem;
// placeholder initial value
// Bug 1763138 - Get the actual initial state for the setup flow
this.setupState = 0;
this.elem.addEventListener("click", this);
this.elem.updateSetupState(this.setupState);
}
handleEvent(event) {
if (event.type == "click" && event.target.dataset.action) {
switch (event.target.dataset.action) {
case "view0-primary-action": {
this.advanceToAddDeviceStep(event.target);
break;
}
case "view1-primary-action": {
this.advanceToSyncTabsStep(event.target);
break;
}
case "view2-primary-action": {
this.advanceToSetupComplete(event.target);
break;
}
case "view3-primary-action": {
this.advanceToGetMyTabs(event.target);
break;
}
}
}
}
advanceToAddDeviceStep(containerElem) {
// Bug 1763138 - Implement the actual logic to advance to next step
this.setupState = 1;
this.elem.updateSetupState(this.setupState);
}
advanceToSyncTabsStep(containerElem) {
// Bug 1763138 - Implement the actual logic to advance to next step
this.setupState = 2;
this.elem.updateSetupState(this.setupState);
}
advanceToSetupComplete(containerElem) {
// Bug 1763138 - Implement the actual logic to advance to next step
this.setupState = 3;
this.elem.updateSetupState(this.setupState);
}
advanceToGetMyTabs(containerElem) {
// Bug 1763138 - Implement the actual logic to advance to next step
this.setupState = 4;
this.elem.updateSetupState(this.setupState);
}
})();
export class TabsPickupContainer extends HTMLElement {
constructor() {
super();
this.manager = null;
this._currentSetupState = -1;
}
get setupContainerElem() {
return this.querySelector("#tabpickup-setup-steps");
}
get tabsContainerElem() {
return this.querySelector("#tabpickup-tabs-container");
}
appendTemplatedElement(templateId, elementId) {
const template = document.getElementById(templateId);
const templateContent = template.content;
const cloned = templateContent.cloneNode(true);
if (elementId) {
cloned.firstElementChild.id = elementId;
}
this.appendChild(cloned);
}
updateSetupState(stateIndex) {
if (stateIndex === undefined) {
stateIndex = this._currentSetupState;
}
if (stateIndex == this._currentSetupState) {
return;
}
this._currentSetupState = stateIndex;
this.render();
}
render() {
if (!this.isConnected) {
return;
}
let setupElem = this.setupContainerElem;
let tabsElem = this.tabsContainerElem;
const stateIndex = this._currentSetupState;
// show/hide either the setup or tab list containers, creating each as necessary
if (stateIndex < 4) {
if (!setupElem) {
this.appendTemplatedElement(
"sync-setup-template",
"tabpickup-setup-steps"
);
setupElem = this.setupContainerElem;
}
if (tabsElem) {
tabsElem.hidden = true;
}
setupElem.hidden = false;
setupElem.selectedViewName = `sync-setup-view${stateIndex}`;
} else {
if (!tabsElem) {
this.appendTemplatedElement(
"synced-tabs-template",
"tabpickup-tabs-container"
);
tabsElem = this.tabsContainerElem;
}
if (setupElem) {
setupElem.hidden = true;
}
tabsElem.hidden = false;
}
}
}
customElements.define("tabs-pickup-container", TabsPickupContainer);
export { tabsSetupFlowManager };