This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Removed the sidebar panel, and added a pageAction panel, which opens/closes on pageAction click. Added a 'priceComparison' object that, similar to the 'product' object, is passed from 'background.js' to the pageAction panel ('./src/popup/index.jsx') via the panel's URL as a query string. This 'priceComparison' object is currently pulled from a stub method, 'getPriceComparisonData', which currently just returns a static object literal. Ultimately this method would call an external API and return the data we need to display in the panel. TODO: Add CSS and top left-most icon.
- Loading branch information
1 parent
00f8c5b
commit 5dc1289
Showing
11 changed files
with
166 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* 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 autobind from 'autobind-decorator'; | ||
import pt from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import 'commerce/popup/components/Button.css'; | ||
|
||
/** | ||
* An expandable section in an Accordion container. Must be used as a | ||
* direct child of an Accordion. | ||
*/ | ||
@autobind | ||
export default class Button extends React.Component { | ||
static propTypes = { | ||
/** Text displayed in on the button */ | ||
label: pt.string.isRequired, | ||
/** If there are multiple buttons, true if this is the primary button */ | ||
primary: pt.bool, | ||
onClick: pt.func, | ||
|
||
} | ||
|
||
static defaultProps = { | ||
primary: false, | ||
onClick() {}, | ||
} | ||
|
||
handleClick() { | ||
this.props.onClick(this.props.primary); | ||
} | ||
|
||
render() { | ||
const {label, primary} = this.props; | ||
return ( | ||
<button type="button" className={`button ${primary ? 'primary' : ''}`} onClick={this.handleClick}> | ||
<span className="button-label">{label}</span> | ||
</button> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,3 @@ body { | |
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
#sidebar, | ||
.sidebar-container { | ||
width: 100%; | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* 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 React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import pt from 'prop-types'; | ||
|
||
import Button from 'commerce/popup/components/Button'; | ||
import {hasKeys} from 'commerce/utils'; | ||
|
||
import 'commerce/popup/index.css'; | ||
|
||
const PRODUCT_KEYS = ['title', 'image', 'price']; | ||
const PRICE_COMPARISON_KEYS = ['altVendor', 'altPrice', 'faviconURL']; | ||
|
||
class Popup extends React.Component { | ||
static propTypes = { | ||
product: pt.shape({ | ||
title: pt.string, | ||
image: pt.string, | ||
price: pt.string, | ||
}), | ||
priceComparison: pt.shape({ | ||
altVendor: pt.string, | ||
altPrice: pt.string, | ||
faviconURL: pt.string, | ||
}), | ||
} | ||
|
||
static defaultProps = { | ||
product: undefined, | ||
priceComparison: undefined, | ||
} | ||
|
||
componentDidCatch() { | ||
// TODO: Show friendly message when errors happen. | ||
} | ||
|
||
render() { | ||
const {price} = this.props.product; | ||
const {altVendor, altPrice, faviconURL} = this.props.priceComparison; | ||
// remove '$', '-'' and starting/ending ' ' from the string and | ||
// split string if given a range of prices (e.g. Crate and Barrel), and | ||
// convert to a number with two decimal places | ||
const cleanPrice = parseInt(price | ||
.replace(/\$|-/g, '') | ||
.trim() | ||
.split(/\s/)[0], 10); | ||
const savings = (cleanPrice - altPrice) > 0 ? (cleanPrice - altPrice).toFixed(2) : 0; | ||
return ( | ||
<div> | ||
<h1>You could save <span>${savings}</span> buying this elsewhere.</h1> | ||
<h2>We found this same product available for less on another site:</h2> | ||
<div> | ||
<img alt={`${altVendor} favicon`} src={faviconURL} /> | ||
<span>{altVendor}</span> | ||
<span>${altPrice}</span> | ||
</div> | ||
<Button className="button" label="No Thanks" /> | ||
<Button className="button" primary label="Show Me" /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
// Pull in product data from query parameters | ||
const url = new URL(window.location); | ||
const product = { | ||
title: url.searchParams.get('title'), | ||
image: url.searchParams.get('image'), | ||
price: url.searchParams.get('price'), | ||
}; | ||
const isValidProduct = PRODUCT_KEYS.map(key => product[key]).every(val => val); | ||
|
||
// Pull in price comparison data from query parameters | ||
const priceComparison = { | ||
altVendor: url.searchParams.get('altVendor'), | ||
altPrice: url.searchParams.get('altPrice'), | ||
faviconURL: url.searchParams.get('faviconURL'), | ||
}; | ||
const isBetterPrice = hasKeys(priceComparison, PRICE_COMPARISON_KEYS); | ||
|
||
ReactDOM.render( | ||
<Popup | ||
product={isValidProduct ? product : undefined} | ||
priceComparison={isBetterPrice ? priceComparison : undefined} | ||
/>, | ||
document.getElementById('popup'), | ||
); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.