Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #37 from mozilla/remove-sidebar
Browse files Browse the repository at this point in the history
Fix #33: Remove prototype sidebar.
  • Loading branch information
Osmose authored Aug 1, 2018
2 parents 2473c13 + 71d0b54 commit 5ed5552
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 320 deletions.
46 changes: 1 addition & 45 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,13 @@
* 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/. */

import {hasKeys} from 'commerce/utils';

const PRODUCT_KEYS = ['title', 'image', 'price'];
const SIDEBAR_URL = browser.extension.getURL('/sidebar.html');

/**
* Open the sidebar when the page action is clicked.
*/
browser.pageAction.onClicked.addListener(() => {
browser.sidebarAction.open();
});

/**
* Prep initial sidebar on location change for a given tab.
*/
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.url && tab.status === 'loading') {
browser.sidebarAction.setPanel({
panel: SIDEBAR_URL,
tabId,
});
}
});

browser.runtime.onConnect.addListener((port) => {
port.onMessage.addListener((message) => {
if (message.type === 'product-data') {
// If this page contains a product, prep the sidebar and show the
// page action icon for opening the sidebar.
const isProductPage = hasKeys(message.data, PRODUCT_KEYS);
if (isProductPage) {
browser.sidebarAction.setPanel({
panel: getPanelURL(message.data),
tabId: port.sender.tab.id,
});
browser.pageAction.show(port.sender.tab.id);
}
console.log(message.data); // eslint-disable-line no-console
}
});
port.postMessage({
type: 'background-ready',
});
});

/**
* Generate the sidebar panel URL for a specific product.
*/
function getPanelURL(productData) {
const url = new URL(SIDEBAR_URL);
for (const key of PRODUCT_KEYS) {
url.searchParams.set(key, productData[key]);
}
return url.href;
}
9 changes: 0 additions & 9 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@
"background": {
"scripts": ["background.bundle.js"]
},
"page_action": {
"default_icon": "icon.svg",
"default_title": "Show Shopping Sidebar"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["product_info.bundle.js"]
}
],
"sidebar_action": {
"default_icon": "icon.svg",
"default_title": "Commerce",
"default_panel": "sidebar.html"
},
"permissions": [
"<all_urls>",
"tabs"
Expand Down
11 changes: 0 additions & 11 deletions src/sidebar.html

This file was deleted.

30 changes: 0 additions & 30 deletions src/sidebar/components/Accordion.css

This file was deleted.

119 changes: 0 additions & 119 deletions src/sidebar/components/Accordion.jsx

This file was deleted.

17 changes: 0 additions & 17 deletions src/sidebar/index.css

This file was deleted.

65 changes: 0 additions & 65 deletions src/sidebar/index.jsx

This file was deleted.

16 changes: 0 additions & 16 deletions src/tests/sidebar/components/test_Accordion.jsx

This file was deleted.

10 changes: 10 additions & 0 deletions src/tests/test_basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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/. */

import test from 'tape';

test('that the test suite runs', (t) => {
t.equal(1 + 1, 2, 'Addition works');
t.end();
});
7 changes: 0 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,3 @@ export async function retry(callback, maxRetries = 5, delayFactor = 2, initialDe
}
throw lastError;
}

/**
* Check if an object contains all the specified keys.
*/
export function hasKeys(object, keys) {
return keys.map(key => key in object).every(val => val);
}
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {
target: 'web',
entry: {
background: './src/background',
sidebar: './src/sidebar/index',
product_info: './src/product_info',
},
output: {
Expand Down

0 comments on commit 5ed5552

Please sign in to comment.