Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
broaden null check, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Oct 9, 2018
1 parent 6e6803f commit aea4db0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 34 deletions.
7 changes: 1 addition & 6 deletions app/components/braveShields/braveShields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ export default class BraveShields extends React.Component<BraveShieldsProps, {}>
<ShieldsPanel
enabled={shieldsPanelTabData.braveShields !== 'block'}
data-test-id='brave-shields-panel'
style={{
/* Hack to make the extension content match the default
browser action popup top/bottom border */
borderRadius: '2px',
minHeight: 'auto'
}}
style={{ borderRadius: '2px', minHeight: 'auto' }}
>
<BraveShieldsHeader
tabData={shieldsPanelTabData}
Expand Down
42 changes: 21 additions & 21 deletions app/components/braveShields/braveShieldsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,27 @@ export interface BraveShieldsHeaderProps {
}

export default class BraveShieldsHeader extends React.PureComponent<BraveShieldsHeaderProps, {}> {
get enabledContent () {
return (
<EnabledText>
<Highlight enabled={true} size='large'>{getTotalResourcesBlocked(this.props.tabData)}</Highlight>
<Label size='medium'>{getMessage('totalBlocked')}</Label>
</EnabledText>
)
}

get disabledContent () {
return (
<DisabledText>
<ShieldIcon />
<Description enabled={false}>{getMessage('disabledMessage')}</Description>
</DisabledText>
)
}

onToggleShields = (event: React.ChangeEvent<HTMLInputElement>) => {
const { origin } = this.props.tabData
if (!isHttpOrHttps(origin)) {
if (!isHttpOrHttps(origin) || !event.target) {
return
}
const shieldsOption: BlockOptions = event.target.checked ? 'allow' : 'block'
Expand All @@ -55,30 +73,12 @@ export default class BraveShieldsHeader extends React.PureComponent<BraveShields
</Label>
<Toggle id='mainToggle' size='large' checked={enabled} onChange={this.onToggleShields} />
</HeaderToggle>
{
enabled
? <Description enabled={true}>{getMessage('enabledMessage')}</Description>
: null
}
{enabled ? <Description enabled={true}>{getMessage('enabledMessage')}</Description> : null}
<SiteCard>
<EnabledText>
<img src={getFavicon(url)} />
<Label size='large'>{hostname}</Label></EnabledText>
{
enabled
? (
<EnabledText>
<Highlight enabled={true} size='large'>{getTotalResourcesBlocked(this.props.tabData)}</Highlight>
<Label size='medium'>{getMessage('totalBlocked')}</Label>
</EnabledText>
)
: (
<DisabledText>
<ShieldIcon />
<Description enabled={false}>{getMessage('disabledMessage')}</Description>
</DisabledText>
)
}
{enabled ? this.enabledContent : this.disabledContent}
</SiteCard>
</Header>
)
Expand Down
4 changes: 2 additions & 2 deletions app/components/braveShields/interfaceControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export default class InterfaceControls extends React.PureComponent<Props, {}> {
}

onChangeBlockAds = (event: React.ChangeEvent<HTMLInputElement>) => {
if (typeof event.target === 'undefined') {
if (!event.target) {
return
}
const shoudEnableAdsTracks = event.target.checked ? 'allow' : 'block'
const shoudEnableAdsTracks: BlockOptions = event.target.checked ? 'allow' : 'block'
this.props.blockAdsTrackers(shoudEnableAdsTracks)
}

Expand Down
6 changes: 3 additions & 3 deletions app/components/braveShields/privacyControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ interface Props {

export default class PrivacyControls extends React.PureComponent<Props, {}> {
onChangeCookiesProtection = (event: React.ChangeEvent<any>) => {
if (typeof event.target === 'undefined') {
if (!event.target) {
return
}
this.props.blockCookies(event.target.value)
}

onChangeJavaScriptProtection = (event: React.ChangeEvent<any>) => {
if (typeof event.target === 'undefined') {
if (!event.target) {
return
}
this.props.blockJavaScript(event.target.value)
}

onChangeFingerprintingProtection = (event: React.ChangeEvent<any>) => {
if (typeof event.target === 'undefined') {
if (!event.target) {
return
}
this.props.blockFingerprinting(event.target.value)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/shieldsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Tab } from '../types/state/shieldsPannelState'

export const getTotalResourcesBlocked = (tabData: Partial<Tab>) => {
if (typeof tabData === 'undefined') {
if (!tabData) {
return 0
}
return (
Expand Down
2 changes: 1 addition & 1 deletion app/types/other/blockTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export type BlockTypes = 'ads' | 'trackers' | 'httpUpgradableResources' | 'javas
export type BlockOptions = 'allow' | 'block'
export type BlockFPOptions = 'allow' | 'block' | 'block_third_party'
export type BlockCookiesOptions = 'allow' | 'block' | 'block_third_party'
export type BlockJSOptions = 'allow' | 'block' | 'block_third_party'
export type BlockJSOptions = 'allow' | 'block' | 'block_third_party'

0 comments on commit aea4db0

Please sign in to comment.