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

Commit

Permalink
do not render stats blocked if page isnt active yet
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jan 17, 2019
1 parent 038a43a commit 9f55545
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/background/reducers/shieldsPanelReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { reloadTab } from '../api/tabsAPI'
import * as shieldsPanelState from '../../state/shieldsPanelState'
import { State, Tab } from '../../types/state/shieldsPannelState'
import { Actions } from '../../types/actions/index'
import { getTotalResourcesBlocked } from '../../helpers/shieldsUtils'
import { getTotalResourcesBlocked, isShieldsActive } from '../../helpers/shieldsUtils'

const updateShieldsIconBadgeText = (state: State) => {
const tabId: number = shieldsPanelState.getActiveTabId(state)
Expand Down Expand Up @@ -199,7 +199,8 @@ export default function shieldsPanelReducer (state: State = { tabs: {}, windows:
const currentTabId: number = shieldsPanelState.getActiveTabId(state)
state = shieldsPanelState.updateResourceBlocked(
state, tabId, action.details.blockType, action.details.subresource)
if (tabId === currentTabId) {
const shieldsActive: boolean = isShieldsActive(state, tabId)
if (tabId === currentTabId && shieldsActive) {
updateShieldsIconBadgeText(state)
}
break
Expand Down
9 changes: 8 additions & 1 deletion app/helpers/shieldsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 { Tab } from '../types/state/shieldsPannelState'
import { Tab, State } from '../types/state/shieldsPannelState'

export const getTotalResourcesBlocked = (tabData: Partial<Tab>) => {
if (!tabData) {
Expand Down Expand Up @@ -31,3 +31,10 @@ export const blockedResourcesSize = (blockedResources: number) => {
}
return blockedResources.toString()
}

export const isShieldsActive = (state: State, tabId: number): boolean => {
if (!state.tabs[tabId]) {
return false
}
return state.tabs[tabId].braveShields !== 'block'
}

0 comments on commit 9f55545

Please sign in to comment.