Skip to content

Commit

Permalink
introduce itemDialog for stores and segregate cart from checkoutdialog
Browse files Browse the repository at this point in the history
  • Loading branch information
JessNah committed May 22, 2021
1 parent 9498727 commit 08443d7
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 205 deletions.
41 changes: 26 additions & 15 deletions Extension/src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,32 @@ chrome.runtime.onInstalled.addListener(() => {
})

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(tab.url && tab.url.includes(SupportedSitesUrls[SupportedSites.INSTACART])){
setCurrentStore(SupportedSites.INSTACART);
} else if(tab.url && tab.url.includes(SupportedSitesUrls[SupportedSites.APPLESTORE])){
setCurrentStore(SupportedSites.APPLESTORE);
if(tab.url && tab.url.includes("apple.com/ca/shop/bag")){
chrome.tabs.sendMessage(tab.id, Messages.ENABLE_CHECKOUT_STATE);
} else {
chrome.tabs.sendMessage(tab.id, Messages.DISABLE_CHECKOUT_STATE);
}
} else if(tab.url && tab.url.includes(SupportedSitesUrls[SupportedSites.AMAZON])){
setCurrentStore(SupportedSites.AMAZON);
if(tab.url && tab.url.includes("/cart/view")){
chrome.tabs.sendMessage(tab.id, Messages.ENABLE_CHECKOUT_STATE);
} else {
chrome.tabs.sendMessage(tab.id, Messages.DISABLE_CHECKOUT_STATE);
if(tab && tab.url){
if(tab.url.includes(SupportedSitesUrls[SupportedSites.INSTACART])){
setCurrentStore(SupportedSites.INSTACART);
//cart open state does not happen on route level, see contentScript for logic
//inspecting dom to determine open cart
//view chrome.webNavigation code below to see item state logic
} else if(tab.url.includes(SupportedSitesUrls[SupportedSites.APPLESTORE])){
setCurrentStore(SupportedSites.APPLESTORE);
if(tab.url.includes("apple.com/ca/shop/bag")){
chrome.tabs.sendMessage(tab.id, Messages.ENABLE_CHECKOUT_STATE);
} else if(tab.url.includes("/shop/buy-")){
chrome.tabs.sendMessage(tab.id, Messages.ENABLE_ITEM_STATE);
} else {
chrome.tabs.sendMessage(tab.id, Messages.DISABLE_CHECKOUT_STATE);
chrome.tabs.sendMessage(tab.id, Messages.DISABLE_ITEM_STATE);
}
} else if(tab.url.includes(SupportedSitesUrls[SupportedSites.AMAZON])){
setCurrentStore(SupportedSites.AMAZON);
if(tab.url.includes("/cart/view")){
chrome.tabs.sendMessage(tab.id, Messages.ENABLE_CHECKOUT_STATE);
} else if(tab.url.includes("/product/")){
chrome.tabs.sendMessage(tab.id, Messages.ENABLE_ITEM_STATE);
} else {
chrome.tabs.sendMessage(tab.id, Messages.DISABLE_CHECKOUT_STATE);
chrome.tabs.sendMessage(tab.id, Messages.DISABLE_ITEM_STATE);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.take2--checkout-cart-item {
display: inline-flex;
justify-content: space-between;
width: 100%;
}

.take2--checkout-cart-item-text {
max-width: 160px;
word-wrap: break-word;
overflow: hidden;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
padding-left: 16px;
text-align: left;
display: -webkit-box;
vertical-align: middle;
line-height: normal;
}

.take2--checkout-cart-item-text-wrapper {
display: inline-block;
}

.take2--checkout-cart-item-score {
display: inline;
padding-left: 8px;
padding-right: 16px;
}

.take2--checkout-cart-item-text-container {
// max-width: 160px;
height: 40px;
// line-height: 40px;
text-align: center;
line-height: 40px;
}

.take2--checkout-cart-item-img {
max-height: 40px;
}

.take2--checkout-cart-heading {
padding-left: 20px;
padding-right: 16px;
font-size: var(--cds-productive-heading-04-font-size, 1.45rem);
font-weight: var(--cds-productive-heading-04-font-weight, 400);
line-height: var(--cds-productive-heading-04-line-height, 1.29);
letter-spacing: var(--cds-productive-heading-04-letter-spacing, 0);
}

.take2--checkout-cart-heading-wrapper {
display: inline-flex;
padding: 16px;
}
106 changes: 106 additions & 0 deletions Extension/src/components/CheckoutDialog/CheckoutCart/CheckoutCart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React, { Component } from 'react'
import "./CheckoutCart.scss"
import { Accordion, AccordionItem, Tag, TagTypeName } from "carbon-components-react"
import { productItem } from "../../../utils/types"
import { ShoppingCart32 } from "@carbon/icons-react"

interface CheckoutCartProps {
cart: productItem[],
cartRank: string,
selectItem: (item: productItem) => void;
}

class CheckoutCart extends Component<CheckoutCartProps> {
getStyledTagScore = (score) => {
let style = "red";
if(score >= 8){
style = "green";
} else if (score >= 6){
style = "teal";
} else if (score >= 4) {
style = "purple";
} else if (score >= 2) {
style = "magenta";
} else {
style = "red";
}
return style as TagTypeName;
}

getScoreText = (score) => {
let text = "Excellent";
if(score >= 8){
text = "Excellent";
} else if (score >= 6){
text = "Very good";
} else if (score >= 4) {
text = "Good";
} else if (score >= 2) {
text = "Fair";
} else {
text = "Low";
}
return text;
}

render() {
return (
<>
<div className={"take2--checkout-cart-heading-wrapper"}>
<ShoppingCart32 />
<div className={"take2--checkout-cart-heading"}>
Shopping cart
</div>
{this.props.cartRank &&
<Tag
type={this.getStyledTagScore(this.props.cartRank)}>
{this.getScoreText(this.props.cartRank)}
</Tag>}
</div>
<Accordion>
{this.props.cart.map((item: productItem, index) => {
return (
<AccordionItem
title={
<div key={index + "_cart_item"} className={"take2--checkout-cart-item"}>
<div
style={{display:"inline-flex", cursor:"pointer"}}
onClick={() => {this.props.selectItem(item)}}>
<div>
<img className={"take2--checkout-cart-item-img"} src={item.image}/>
</div>
<div className={"take2--checkout-cart-item-text-container"}>
<div className={"take2--checkout-cart-item-text-wrapper"}>
<span className={"take2--checkout-cart-item-text"}>{item.name}</span>
</div>
</div>
</div>
<div className={"take2--checkout-cart-item-text-container"}>
<div className={"take2--checkout-cart-item-text-wrapper"}>
<span className={"take2--checkout-cart-item-score"}>
<Tag
type={this.getStyledTagScore(item.score)} >
{this.getScoreText(item.score)}
</Tag>
</span>
</div>
</div>
</div>
}>
<div>{"This item scored " + item.score + "/10" }</div>
<div></div>
<div>{"185 kg carbon emissions3"}</div>
<div>{"73% Production"}</div>
<div>{"7% Transport"}</div>
<div>{"19% Use"}</div>
<div>{"<1% End-of-life processing"}</div>
</AccordionItem>
)})
}
</Accordion>
</>
)
}
}

export default CheckoutCart
54 changes: 0 additions & 54 deletions Extension/src/components/CheckoutDialog/CheckoutDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,4 @@
.exp--tearsheet__container {
max-width: 60% !important;
}
}

.take2--checkout-dialog-cart-item {
display: inline-flex;
justify-content: space-between;
width: 100%;
}

.take2--checkout-dialog-cart-item-text {
max-width: 160px;
word-wrap: break-word;
overflow: hidden;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
padding-left: 16px;
text-align: left;
display: -webkit-box;
vertical-align: middle;
line-height: normal;
}

.take2--checkout-dialog-cart-item-text-wrapper {
display: inline-block;
}

.take2--checkout-dialog-cart-item-score {
display: inline;
padding-left: 8px;
padding-right: 16px;
}

.take2--checkout-dialog-cart-item-text-container {
// max-width: 160px;
height: 40px;
// line-height: 40px;
text-align: center;
line-height: 40px;
}

.take2--checkout-dialog-cart-item-img {
max-height: 40px;
}

.take2--checkout-dialog-cart-heading {
padding-right: 16px;
font-size: var(--cds-productive-heading-04-font-size, 1.45rem);
font-weight: var(--cds-productive-heading-04-font-weight, 400);
line-height: var(--cds-productive-heading-04-line-height, 1.29);
letter-spacing: var(--cds-productive-heading-04-letter-spacing, 0);
}

.take2--checkout-dialog-card-heading-wrapper {
display: inline-flex;
padding: 16px;
}
Loading

0 comments on commit 08443d7

Please sign in to comment.