Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewards rebase #53

Merged
merged 79 commits into from May 10, 2018
Merged
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
72cb75f
Initial commit. Code works on staging with some temp workarounds
Apr 23, 2018
443f6c4
Removing temporary code.
Apr 23, 2018
64a945a
hot dog
trickpattyFH20 Mar 27, 2018
888c8b1
init circle
trickpattyFH20 Mar 29, 2018
7884800
react hot dog
trickpattyFH20 Mar 29, 2018
eac594c
rewards hot dog ui
trickpattyFH20 Mar 30, 2018
7358f88
close circle
trickpattyFH20 Mar 30, 2018
4c6004b
routing and offer card
trickpattyFH20 Apr 2, 2018
8b45dad
reward card layout
trickpattyFH20 Apr 2, 2018
06474ca
more offer card styles
trickpattyFH20 Apr 2, 2018
8feb2f6
card footer + copy feedback + styling
trickpattyFH20 Apr 3, 2018
c325bb9
more styles
trickpattyFH20 Apr 3, 2018
a6381f5
remove purple test style
trickpattyFH20 Apr 4, 2018
eeea57a
test rewards postmessage
trickpattyFH20 Apr 4, 2018
830aee8
one reward at a time for hot dog and offer card
trickpattyFH20 Apr 5, 2018
df4ea54
header + footer + styles
trickpattyFH20 Apr 9, 2018
d11ba1c
react shadow
trickpattyFH20 Apr 13, 2018
169fff4
define MainView first
trickpattyFH20 Apr 13, 2018
44ddfc6
lint
trickpattyFH20 Apr 16, 2018
4084715
add onmessage
trickpattyFH20 Apr 16, 2018
0521a73
fix selector and close button
trickpattyFH20 Apr 16, 2018
603e73f
iframe fallback
trickpattyFH20 Apr 17, 2018
2029ba2
fix ff beta logo
trickpattyFH20 Apr 17, 2018
2efba4c
data csp compatible images + class for index + text styles
trickpattyFH20 Apr 18, 2018
88b0621
disable rewards notification
trickpattyFH20 Apr 18, 2018
52ae822
fix shadow FOUC
trickpattyFH20 Apr 18, 2018
b55f20d
click outside settings
trickpattyFH20 Apr 18, 2018
ef81951
settings styles
trickpattyFH20 Apr 20, 2018
8049a56
settings actions
trickpattyFH20 Apr 23, 2018
27b8d4f
show ghostery pizza offer
trickpattyFH20 Apr 24, 2018
0613ab9
fix event listener reward reference
trickpattyFH20 Apr 26, 2018
52de54f
setConfiguration - for DEBUG only
Apr 27, 2018
632744e
Changing the way browser-core is loaded.
Apr 27, 2018
dff2831
handle signal
trickpattyFH20 Apr 30, 2018
99537a1
mark offer read + delete offer
trickpattyFH20 Apr 30, 2018
c23fe6f
new signals
trickpattyFH20 Apr 30, 2018
85002e5
refactor to sendSignal
trickpattyFH20 May 1, 2018
7ef9f23
Create ToggleSlider component. Use it in Setup flow.
IAmThePan Apr 11, 2018
c9c69ac
GH-409 Update Rewards view: rewards list, toggle on/off, reducers, fa…
IAmThePan Apr 16, 2018
2083be0
GH-409 Update Rewards view: reward details.
IAmThePan Apr 18, 2018
e2351b6
hot dog
trickpattyFH20 Mar 27, 2018
7301085
Integrate panel rewards with background I
IAmThePan Apr 26, 2018
dfb6317
Integrate panel rewards with background II. Fix linting errors
IAmThePan Apr 30, 2018
74b6611
Integrate panel rewards with Background III. Messages for read, remov…
IAmThePan Apr 30, 2018
574f679
Fix signal bug for content-script rewards
IAmThePan May 1, 2018
45094be
panel reward signals
trickpattyFH20 May 1, 2018
b771879
reward prompt flow
trickpattyFH20 May 1, 2018
456e54d
Finalize design for Rewards Panel
IAmThePan May 2, 2018
7d923da
clean rewards
trickpattyFH20 May 2, 2018
b4f87fe
rewards conf handling
trickpattyFH20 May 3, 2018
8272b01
update browser-core package and lock
trickpattyFH20 May 3, 2018
4bf063e
Add translations to Rewards Panel
IAmThePan May 3, 2018
f0aa355
Fix for Ghostery side enabling of offers
May 3, 2018
332f79f
styles. expiration. terms tt
trickpattyFH20 May 3, 2018
7dbd42f
enable offers by default
trickpattyFH20 May 3, 2018
455bc0e
start button styles
trickpattyFH20 May 3, 2018
3ed2459
Begin tests for the rewards panel
IAmThePan May 3, 2018
a3f202c
More and updated tests for Rewards Panel
IAmThePan May 3, 2018
a6f1441
Fix linting errors
IAmThePan May 3, 2018
a904612
signals
trickpattyFH20 May 4, 2018
9640606
Add more signals, fix linting errors, fix bug
IAmThePan May 4, 2018
417f461
Removing offers from ABTest
May 7, 2018
2815dca
style adjustments
trickpattyFH20 May 7, 2018
d87c7c9
GH-1051 fix null reward check
trickpattyFH20 May 8, 2018
48b38fd
GH-1055 fix - define onload evt first
trickpattyFH20 May 8, 2018
e294c78
button singleton + seen reward on offer card shown
trickpattyFH20 May 9, 2018
afb2dc4
typo
trickpattyFH20 May 9, 2018
7fb6652
Removing enable_offers_abtest.
May 9, 2018
83e7b78
Extra blanks
May 9, 2018
3976965
Removing checkbox for EDGE and CLIQZ unconditionally.
May 9, 2018
07983d0
Restore default manifest state.
May 9, 2018
bb2ee65
Update Rewards copy and add styling to non-happy-path Rewards panel
IAmThePan May 10, 2018
771c910
Update test snapshots
IAmThePan May 10, 2018
86111a3
Update package-lock file
IAmThePan May 10, 2018
86cc883
Minor copy change
IAmThePan May 10, 2018
63afa92
GH-1066 Fix text overflow on rewards panel
IAmThePan May 10, 2018
c25119b
Update snapshots for Reward Detail unit tests
IAmThePan May 10, 2018
afc04fc
documentation and svg cleanup
christophertino May 10, 2018
88229ed
Merge branch 'develop' into rewards-rebase
christophertino May 10, 2018
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

fix event listener reward reference
  • Loading branch information
trickpattyFH20 authored and IAmThePan committed May 10, 2018
commit 0613ab9c5ae95a6515855a1ae72b02236be752f5
@@ -14,14 +14,28 @@ const { onMessage } = chrome.runtime;
class OfferCard extends Component {
constructor(props) {
super(props);

console.log('constructor props:', props);
this.state = {
closed: false,
copyText: t('rewards_copy_code'),
showNotification: false,
showSettings: false
showSettings: false,
rewardUI: props.reward && props.reward.offer_data && props.reward.offer_data.ui_info.template_data || {},
// rewardUI: mockData,
imageLoads: {
logo: false,
content: false,
}
};

// @TODO sendMessage to add "seen" flag to reward object
if (this.props.port) {
this.props.port.postMessage({ name: 'rewardSeen', message: {data: 'test'} });
} else {
sendMessage('rewardSeen', {data: 'test'});
}

this.iframeEl = parent.document.getElementById('ghostery-iframe-container');
if (this.iframeEl) {
this.iframeEl.classList = '';
@@ -37,6 +51,25 @@ class OfferCard extends Component {
this.copyCode = this.copyCode.bind(this);
this.disableRewards = this.disableRewards.bind(this);
this.toggleSettings = this.toggleSettings.bind(this);
this.handleImageLoaded = this.handleImageLoaded.bind(this);

// Cliqz metrics
this.sendSignal('offer_shown');
}

sendSignal(type) {
// @param type = ['offer_shown', 'offer_ca_action', 'offer_closed']
if (this.props.port) {
this.props.port.postMessage({ name: 'rewardsSignal', message: {
id: this.props.reward.offer_id,
type
}});
} else {
sendMessage('rewardsSignal', {
id: this.props.reward.offer_id,
type
});
}
}

copyCode() {
@@ -79,9 +112,15 @@ class OfferCard extends Component {
});
}

handleImageLoaded(e) {
e.target.classList.remove('hide');
}

render() {
console.log('render props:', this.props);
console.log('render title:', this.state);
return (
// @TODO condition for hide class
<div className="ghostery-rewards-component">
{ this.state.closed !== true &&
<div className="ghostery-reward-card">
@@ -96,7 +135,7 @@ class OfferCard extends Component {
<div className="reward-content-header">
<div className="flex-grow" />
<div className="reward-company-logo">
<img src={this.props.reward.companyLogo} />
<img src={this.state.rewardUI.logo_url} className="hide" onLoad={this.handleImageLoaded} />
</div>
<div
onClick={this.toggleSettings}
@@ -114,33 +153,33 @@ class OfferCard extends Component {
</div>
<div className="reward-content-img">
<div className="flex-grow" />
<img src={this.props.reward.contentImg} />
<img src={this.state.rewardUI.picture_url} className="hide" onLoad={this.handleImageLoaded} />
<div className="flex-grow" />
</div>
<div className="reward-content-detail">
<span className="reward-benefit">
{ this.props.reward.benefit }
{ this.state.rewardUI.benefit }
</span>
<span className="reward-headline">
{this.props.reward.headline}
{ this.state.rewardUI.headline }
</span>
<span className="reward-description">
{ this.props.reward.description }
{ this.state.rewardUI.desc }
</span>
</div>
<div className="reward-code">
<div>
{this.props.reward.rewardCode}
<input readOnly className="reward-code-input" value={this.props.reward.rewardCode} type="text" />
{this.state.rewardUI.code}
<input readOnly className="reward-code-input" value={this.state.rewardUI.code} type="text" />
</div>
<a onClick={this.copyCode}>{this.state.copyText}</a>
</div>
<div className="reward-content-footer">
<span> {t('rewards_expire')} { this.props.reward.expireTime } </span>
<a target="_blank" href={this.props.reward.termsLink}> { t('rewards_terms_conditions') } </a>
{/* <span> {t('rewards_expire')} { this.props.reward.expireTime } </span> */}
{/* <a target="_blank" href={this.props.reward.termsLink}> { t('rewards_terms_conditions') } </a> */}
</div>
<a target="_blank" href={this.props.reward.redeemLink} className="reward-redeem">
{t('rewards_redeem_now')}
<a target="_blank" href={this.state.rewardUI.call_to_action && this.state.rewardUI.call_to_action.url} className="reward-redeem">
{this.state.rewardUI.call_to_action.text}
</a>
</div>
<div className="reward-footer">
@@ -32,25 +32,12 @@ const channelsSupported = (typeof chrome.runtime.connect === 'function');

class RewardsApp {
constructor() {
this.reward = {
rewardCode: 'SDF75DSUI90',
expireTime: '14 days',
termsLink: 'https://www.ghostery.com/about-ghostery/browser-extension-privacy-policy/',
redeemLink: 'https://www.ghostery.com/',
benefit: '2 Free',
headline: 'Audio Books',
description: 'Description of the offer. There is a lot of exciting stuff going on.',
companyLogo: 'https://cdn.cliqz.com/extension/offers/test/resources/flaconi20-week/flaconi20-week-logo-long-1523970905.png',
contentImg: 'https://cdn.cliqz.com/extension/offers/test/resources/flaconi20-week/flaconi20-week-logo-long-1523970905.png'
};

this.rewardsContainer = document.createElement('div');
this.rewardsApp = document.createElement('div');
this.rewardsIframe = null;;
this.iframeStyle = null;;
this.port = null;
this.mainView = null;
this.imgBlob = null;
this.rewardsApp.id = 'ghostery-rewards-app';
this.rewardsApp.className = 'show';
this.handleMessages = this.handleMessages.bind(this);
@@ -82,7 +69,7 @@ class RewardsApp {

renderReact() {
let MainView = this.mainView;
ReactDOM.render(<MainView reward={this.reward} imgBlob={this.imgBlob} />, this.rewardsApp);
ReactDOM.render(<MainView reward={this.reward} />, this.rewardsApp);
}

renderShadow() {
@@ -96,7 +83,7 @@ class RewardsApp {
<div id="ghostery-shadow-root">
<Route exact path="/" render={ ()=> <HotDog reward={props.reward} /> } />
<Route path="/hotdog" render={ ()=> <HotDog reward={props.reward} /> } />
<Route path="/offercard" render={ ()=> <OfferCard reward={props.reward} imgBlob={props.imgBlob} /> } />
<Route path="/offercard" render={ ()=> <OfferCard reward={props.reward} port={this.port} /> } />
</div>
</ShadowDOM>
</Router>
@@ -128,7 +115,7 @@ class RewardsApp {
<div>
<Route exact path="/" render={ ()=> <HotDog reward={props.reward} /> } />
<Route path="/hotdog" render={ ()=> <HotDog reward={props.reward} /> } />
<Route path="/offercard" render={ ()=> <OfferCard reward={props.reward} imgBlob={props.imgBlob} /> } />
<Route path="/offercard" render={ ()=> <OfferCard reward={props.reward} port={this.port} /> } />
</div>
</Router>
);
@@ -146,15 +133,17 @@ class RewardsApp {
this.port.postMessage({ name: 'rewardsLoaded' });
}
} else {
// TODO listen for this in background.js
sendMesage('rewardsLoaded');
onMessage.addListener(this.handleMessages);
}
}

handleMessages(request, sender, response) {
console.log('postMessage request', request);
if (request.name === 'showHotDog') {
console.log('showHotDog postMessage');
this.reward = request;
console.log('showHotDog event reward id ', request.reward.offer_id);
this.reward = request.reward;
}
console.log(document.readyState);
if (document.readyState === 'complete' || document.readyState === 'interactive') {
@@ -36,6 +36,7 @@ class Panel extends React.Component {
// try to get tabId from query string if available (FF for Android only)
const tabId = new URLSearchParams(window.location.search).get('tabId');
this.props.actions.getPanelData(tabId).then((data) => {
console.log('panelData', data)
if (data.is_expert) {
// load Detail component
this.props.history.push('/detail');
@@ -143,8 +143,9 @@
align-items: center;

img {
width: auto;
height: auto;
width: 100%;
height: 100%;
object-fit: contain;
}
}

@@ -177,7 +178,8 @@

img {
width: 100%;
height: auto;
height: 100%;
object-fit: contain;
}
}

@@ -413,6 +413,14 @@ function handleBlockedRedirect(name, message, tab_id, callback) {
return false;
}

function handleRewards(name, message, tab_id, callback) {
if (name === 'rewardsSignal') {
// @TODO send signal
// {"origin":"offers-cc","type":"action-signal","data":{"action_id":"hub_open"}}
// cliqz.modules['offers-v2'].background.actions.processRealEstateMessage(message);
}
}

/**
* Handle messages sent from dist/settings_redirect.js script.
* of the settings_redirect.html local page. Used on @EDGE and Chrome.
@@ -507,6 +515,7 @@ function onMessageHandler(request, sender, callback) {
const {
name, message, messageId, origin
} = request;
console.log('REQUESTORIGIN', origin);
const { tab } = sender;
const tab_id = tab && tab.id;
// Edge does not have url on tab object, as of Build 14342_rc1
@@ -549,6 +558,8 @@ function onMessageHandler(request, sender, callback) {
return handleClick2Play(name, message, tab_id, callback);
} else if (origin === 'blocked_redirect') {
return handleBlockedRedirect(name, message, tab_id, callback);
} else if (origin === 'rewards') {
return handleRewards(name, message, tab_id, callback);
}

// HANDLE UNIVERSAL EVENTS HERE (NO ORIGIN LISTED ABOVE)
@@ -1087,14 +1098,13 @@ messageCenter.on('enabled', () => {
msg.data.offer_data) {
if (!rewards.storedOffers.hasOwnProperty(msg.data.offer_id)) {
rewards.storedOffers[msg.data.offer_id] = msg.data;
rewards.currentOffer = msg.data;
}

log('RECEIVED OFFER', msg);
utils.getActiveTab((tab) => {
let tabId = 0;
if (tab) tabId = tab.id;
rewards.showHotDog(tabId);
rewards.showHotDog(tabId, msg.data);
});

// const { data } = msg;
@@ -184,7 +184,7 @@ class PanelData {
needsReload: this._trackerData.get('needsReload'),
smartBlock: this._trackerData.get('smartBlock'),
tab_id: this._trackerData.get('tab_id'),
rewards: rewards.offers
rewards: rewards.storedOffers
},
summary: this.summaryView,
blocking: this._confData.get('is_expert') ? this.blockingView : false,
@@ -35,7 +35,13 @@ class Rewards {
this.channelsSupported = (typeof chrome.runtime.onConnect === 'object');
}

showHotDog(tab_id) {
handleSignal(rewardId) {

}

showHotDog(tab_id, offer) {
console.log('CHECK NEW OFFER ID', offer.offer_id)
this.currentOffer = offer;
const tab = tabInfo.getTabInfo(tab_id);

// If the tab is prefetched, we can't add purplebox to it.
@@ -46,7 +52,7 @@ class Rewards {

// Inject script cannot handle errors properly, but we call createBox after verifying that the tab is OK
// So update hotdog status for this tab
tabInfo.setTabInfo(tab_id, 'rewards', true);
// tabInfo.setTabInfo(tab_id, 'rewards', true);
if (this.channelsSupported) {
if (this.ports.has(tab_id)) {
this.ports.get(tab_id).disconnect();
@@ -60,10 +66,10 @@ class Rewards {
if (!this.ports.has(tabId)) {
this.ports.set(tabId, port);
this.ports.get(tabId).onMessage.addListener((message) => {
// const reward =
if (message.name === 'rewardsLoaded') {
this.ports.get(tabId).postMessage({ name: 'showHotDog', reward: this.currentOffer });
this.currentOffer = null;
} else if (message.name === 'rewardSignal') {
this.handleSignal(message.rewardId);
}
});
}
ProTip! Use n and p to navigate between commits in a pull request.