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

Android browser ui #96

Closed
Closed
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Prev
Fix all linter errors
  • Loading branch information
mai-cliqz committed Jun 11, 2018
commit 796a10c65abf29e6b4a179434f2ca1ae33ee6fa0
@@ -5,7 +5,7 @@ import { trustRestrictBlockSiteTracker, blockUnblockGlobalTracker, blockUnBlockA
export default function handleAllActions({ actionName, actionData, state }) {
let updated = {};

switch(actionName) {
switch (actionName) {
case 'handleTrustButtonClick':
updated = handleTrustButtonClick({ state });
break;
@@ -2,7 +2,9 @@ import { sendMessage } from '../utils/msg';
import { updateObject } from '../utils/utils';
import { resetTrustRestrictPause } from './summaryActions';

function trustRestrictTracker({ pageHost, blocking, app_ids, trust, restrict }) {
function trustRestrictTracker({
pageHost, blocking, app_ids, trust, restrict
}) {
const siteSpecificUnblocks = blocking.site_specific_unblocks;
const siteSpecificBlocks = blocking.site_specific_blocks;

@@ -55,9 +57,11 @@ function calculateDelta(oldState, newState) {

export function trustRestrictBlockSiteTracker({ actionData, state }) {
const { blocking, summary, settings } = state;
const pageHost = summary.pageHost;
const { pageHost } = summary;

const { app_id, cat_id, block, trust, restrict } = actionData;
const {
app_id, cat_id, block, trust, restrict
} = actionData;

const updated_app_ids = JSON.parse(JSON.stringify(blocking.selected_app_ids)) || {};

@@ -66,7 +70,7 @@ export function trustRestrictBlockSiteTracker({ actionData, state }) {

// update tracker category for site-specific blocking
const selectedBlockingTracker = updated_blocking_category.trackers
.find(tracker => tracker.shouldShow && tracker.id === app_id);
.find(tracker => tracker.shouldShow && tracker.id === app_id);
if (selectedBlockingTracker) {
const oldState = selectedBlockingTracker.blocked || selectedBlockingTracker.ss_blocked;
selectedBlockingTracker.ss_allowed = trust;
@@ -90,7 +94,7 @@ export function trustRestrictBlockSiteTracker({ actionData, state }) {
const updated_settings_category = updated_settings_categories.find(category => category.id === cat_id);

const selectedSettingsTracker = updated_settings_category.trackers
.find(tracker => tracker.shouldShow && +tracker.id === app_id);
.find(tracker => tracker.shouldShow && +tracker.id === app_id);
if (selectedSettingsTracker && !trust && !restrict) { // Only update global if this action is blocking
const oldState = selectedSettingsTracker.blocked;
selectedSettingsTracker.blocked = block;
@@ -100,8 +104,11 @@ export function trustRestrictBlockSiteTracker({ actionData, state }) {
updated_settings_category.num_blocked += delta;
}

const { updated_site_specific_unblocks, updated_site_specific_blocks }
= trustRestrictTracker({ pageHost, blocking, app_ids: [app_id], trust, restrict });
const {
updated_site_specific_unblocks, updated_site_specific_blocks
} = trustRestrictTracker({
pageHost, blocking, app_ids: [app_id], trust, restrict
});

// persist to background - note that categories are not included
sendMessage('setPanelData', {
@@ -129,7 +136,9 @@ export function trustRestrictBlockSiteTracker({ actionData, state }) {
}

export function blockUnblockGlobalTracker({ actionData, state }) {
const { block, cat_id, app_id, type } = actionData;
const {
block, cat_id, app_id, type
} = actionData;
const { blocking, settings } = state;

const updated_app_ids = JSON.parse(JSON.stringify(settings.selected_app_ids)) || {};
@@ -138,7 +147,7 @@ export function blockUnblockGlobalTracker({ actionData, state }) {
const updated_settings_category = updated_settings_categories.find(category => category.id === cat_id);

const selectedSettingsTracker = updated_settings_category.trackers
.find(tracker => tracker.shouldShow && tracker.id === app_id);
.find(tracker => tracker.shouldShow && tracker.id === app_id);

if (selectedSettingsTracker) {
const oldState = selectedSettingsTracker.blocked;
@@ -162,7 +171,7 @@ export function blockUnblockGlobalTracker({ actionData, state }) {
const updated_blocking_category = updated_blocking_categories.find(item => item.id === cat_id);

const selectedBlockingTracker = updated_blocking_category.trackers
.find(tracker => tracker.shouldShow && tracker.id === +app_id);
.find(tracker => tracker.shouldShow && tracker.id === +app_id);
// Only update if the site tracker is neither trusted nor restricted
if (selectedBlockingTracker) {
const oldState = selectedBlockingTracker.blocked || selectedBlockingTracker.ss_blocked;
@@ -4,8 +4,13 @@ import Accordions from './content/Accordions';
import DotsMenu from './content/DotsMenu';

export default class GlobalTrackers extends React.Component {
get categories() {
return this.props.categories;
}

actions = [
{
id: 'blockAllGlobal',
name: 'Block All',
callback: () => {
this.context.callGlobalAction({
@@ -18,6 +23,7 @@ export default class GlobalTrackers extends React.Component {
},
},
{
id: 'unblockAllGlobal',
name: 'Unblock All',
callback: () => {
this.context.callGlobalAction({
@@ -30,6 +36,7 @@ export default class GlobalTrackers extends React.Component {
},
},
{
id: 'resetSettings',
name: 'Reset Settings',
callback: () => {
this.context.callGlobalAction({
@@ -39,10 +46,6 @@ export default class GlobalTrackers extends React.Component {
}
]

get categories() {
return this.props.categories;
}

render() {
return (
<div className="global-trackers">
@@ -52,12 +55,16 @@ export default class GlobalTrackers extends React.Component {
</div>
<Accordions type="global-trackers" categories={this.categories} />
</div>
)
);
}
}

GlobalTrackers.propTypes = {
categories: PropTypes.array,
categories: PropTypes.arrayOf(PropTypes.object),
};

GlobalTrackers.defaultProps = {
categories: [],
};

GlobalTrackers.contextTypes = {
@@ -4,7 +4,6 @@ import TrackersChart from './content/TrackersChart';
import { fromTrackersToChartData } from '../utils/chart';

export default class Overview extends React.Component {

get isTrusted() {
return this.context.siteProps.isTrusted;
}
@@ -70,7 +69,7 @@ export default class Overview extends React.Component {
<p className="trackers-blocked-num"><span className="number">{this.nTrackersBlocked}</span> Trackers blocked</p>
</div>

<div className={`buttons-wrapper row`}>
<div className="buttons-wrapper row">
<div className="small-12">
<button
className={`button trust-site-btn ${this.isTrusted ? 'changed' : ''} ${this.isPaused ? 'paused' : ''}`}
@@ -98,13 +97,16 @@ export default class Overview extends React.Component {
</div>
</div>
</div>
)
);
}
}

Overview.propTypes = {
handleClick: PropTypes.func,
categories: PropTypes.array,
categories: PropTypes.arrayOf(PropTypes.object),
};

Overview.defaultProps = {
categories: [],
};

Overview.contextTypes = {
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import URLSearchParams from 'url-search-params';
import { Tabs, Tab } from './content/Tabs';
import Tabs from './content/Tabs';
import Tab from './content/Tab';
import Overview from './Overview';
import FixedMenu from './content/FixedMenu';
import SiteTrackers from './SiteTrackers';
@@ -21,9 +22,14 @@ export default class Panel extends React.Component {
settings: {},
blocking: {},
cliqzModuleData: {},
}
};
}

getChildContext = () => ({
siteProps: this.siteProps,
callGlobalAction: this.callGlobalAction,
});

componentDidMount() {
const tabId = new URLSearchParams(window.location.search).get('tabId');
this.setPanelState(tabId);
@@ -33,6 +39,43 @@ export default class Panel extends React.Component {
this.setCliqzDataState(tabId);
}

get siteCategories() {
return this.state.blocking.categories || [];
}

get globalCategories() {
return this.state.settings.categories || [];
}

get chartData() {
const trackers = this.siteCategories.map(category =>
({
id: category.id,
numTotal: category.num_total,
})
);

return fromTrackersToChartData(trackers);
}

get siteProps() {
const hostName = this.state.summary.pageHost || '';
const pageHost = hostName.toLowerCase().replace(/^(http[s]?:\/\/)?(www\.)?/, '');

const siteWhitelist = this.state.summary.site_whitelist || [];
const siteBlacklist = this.state.summary.site_blacklist || [];

const isTrusted = siteWhitelist.indexOf(pageHost) !== -1;
const isRestricted = siteBlacklist.indexOf(pageHost) !== -1;
const isPaused = this.state.summary.paused_blocking;

const nTrackersBlocked = (this.state.summary.trackerCounts || {}).blocked || 0;

return {
hostName, pageHost, isTrusted, isRestricted, isPaused, nTrackersBlocked
};
}

setPanelState = (tabId) => {
getPanelData(tabId).then((data) => {
this.setState({
@@ -89,48 +132,6 @@ export default class Panel extends React.Component {
}
}

get siteCategories() {
return this.state.blocking.categories || [];
}

get globalCategories() {
return this.state.settings.categories || [];
}

get chartData() {
const trackers = this.siteCategories.map(category =>
({
id: category.id,
numTotal: category.num_total,
})
);

return fromTrackersToChartData(trackers);
}

get siteProps() {
const hostName = this.state.summary.pageHost || '';
const pageHost = hostName.toLowerCase().replace(/^(http[s]?:\/\/)?(www\.)?/, '');

const siteWhitelist = this.state.summary.site_whitelist || [];
const siteBlacklist = this.state.summary.site_blacklist || [];

const isTrusted = siteWhitelist.indexOf(pageHost) !== -1;
const isRestricted = siteBlacklist.indexOf(pageHost) !== -1;
const isPaused = this.state.summary.paused_blocking;

const nTrackersBlocked = (this.state.summary.trackerCounts || {}).blocked || 0;

return { hostName, pageHost, isTrusted, isRestricted, isPaused, nTrackersBlocked };
}

getChildContext = () => {
return {
siteProps: this.siteProps,
callGlobalAction: this.callGlobalAction,
};
}

render() {
return (
<div>
@@ -143,21 +144,21 @@ export default class Panel extends React.Component {
<p className="trackers-blocked-num"><span className="number">{this.siteProps.nTrackersBlocked}</span> Trackers blocked</p>
</div>
<Tabs>
<Tab tabLabel={'Overview'} linkClassName={'custom-link'}>
<Tab tabLabel="Overview" linkClassName="custom-link">
<Overview categories={this.siteCategories} />
<FixedMenu panel={this.state.panel} cliqzModuleData={this.state.cliqzModuleData} />
</Tab>

<Tab tabLabel={'Site Trackers'} linkClassName={'custom-link'}>
<Tab tabLabel="Site Trackers" linkClassName="custom-link">
<SiteTrackers categories={this.siteCategories} />
</Tab>

<Tab tabLabel={'Global Trackers'} linkClassName={'custom-link'}>
<Tab tabLabel="Global Trackers" linkClassName="custom-link">
<GlobalTrackers categories={this.globalCategories} />
</Tab>
</Tabs>
</div>
)
);
}
}

@@ -6,6 +6,7 @@ import DotsMenu from './content/DotsMenu';
export default class SiteTrackers extends React.Component {
actions = [
{
id: 'blockAllSite',
name: 'Block All',
callback: () => {
this.context.callGlobalAction({
@@ -18,6 +19,7 @@ export default class SiteTrackers extends React.Component {
},
},
{
id: 'unblockAllSite',
name: 'Unblock All',
callback: () => {
this.context.callGlobalAction({
@@ -40,13 +42,17 @@ export default class SiteTrackers extends React.Component {
</div>
<Accordions type="site-trackers" categories={this.props.categories} />
</div>
)
);
}
}

SiteTrackers.propTypes = {
categories: PropTypes.array,
}
categories: PropTypes.arrayOf(PropTypes.object),
};

SiteTrackers.defaultProps = {
categories: [],
};

SiteTrackers.contextTypes = {
callGlobalAction: PropTypes.func,
ProTip! Use n and p to navigate between commits in a pull request.