Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit f672622

Browse files
committed
replace legacy logic with brand new PrivateIcon state logic
- transitory state: tabs are responsible but still looks ugly. Auditors: @NejcZdovc, @luixxiul Test plan: npm run test -- --grep="Tabs content - PrivateIcon"
1 parent 8a2e388 commit f672622

File tree

5 files changed

+110
-202
lines changed

5 files changed

+110
-202
lines changed

app/common/state/tabContentState/privateState.js

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
// State helpers
6+
const tabUIState = require('../tabUIState')
67
const frameStateUtil = require('../../../../js/state/frameStateUtil')
78

89
module.exports.isPrivateTab = (state, frameKey) => {
@@ -17,3 +18,19 @@ module.exports.isPrivateTab = (state, frameKey) => {
1718

1819
return !!frame.get('isPrivate')
1920
}
21+
22+
module.exports.showPrivateIcon = (state, frameKey) => {
23+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
24+
25+
if (frame == null) {
26+
if (process.env.NODE_ENV !== 'test') {
27+
console.error('Unable to find frame for showPrivateIcon method')
28+
}
29+
return false
30+
}
31+
32+
return (
33+
module.exports.isPrivateTab(state, frameKey) &&
34+
tabUIState.showTabEndIcon(state, frameKey)
35+
)
36+
}

app/renderer/components/styles/global.js

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ const globalStyles = {
176176
defaultTabPadding: '0 4px',
177177
defaultIconPadding: '2px',
178178
iconSize: '16px',
179+
sessionIconSize: '15px',
179180
closeIconSize: '13px',
180181
narrowIconSize: '12px',
181182
dialogWidth: '422px',
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
2-
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3-
* You can obtain one at http://mozilla.org/MPL/2.0/. */
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
const React = require('react')
66
const {StyleSheet, css} = require('aphrodite/no-important')
@@ -9,68 +9,61 @@ const {StyleSheet, css} = require('aphrodite/no-important')
99
const ReduxComponent = require('../../reduxComponent')
1010
const TabIcon = require('./tabIcon')
1111

12-
// State
13-
const tabUIState = require('../../../../common/state/tabUIState')
14-
15-
// Utils
12+
// State helpers
13+
const privateState = require('../../../../common/state/tabContentState/privateState')
1614
const frameStateUtil = require('../../../../../js/state/frameStateUtil')
15+
const tabState = require('../../../../common/state/tabState')
1716

1817
// Styles
18+
const {theme} = require('../../styles/theme')
1919
const globalStyles = require('../../styles/global')
2020
const privateSvg = require('../../../../extensions/brave/img/tabs/private.svg')
2121

2222
class PrivateIcon extends React.Component {
2323
mergeProps (state, ownProps) {
2424
const currentWindow = state.get('currentWindow')
25-
const frameKey = ownProps.frameKey
26-
const hasSeconardImage = tabUIState.hasVisibleSecondaryIcon(currentWindow, ownProps.frameKey)
25+
const tabId = ownProps.tabId
26+
const frameKey = frameStateUtil.getFrameKeyByTabId(currentWindow, tabId)
2727

2828
const props = {}
29-
// used in renderer
29+
props.isPinned = tabState.isTabPinned(state, tabId)
3030
props.isActive = frameStateUtil.isFrameKeyActive(currentWindow, frameKey)
31-
32-
// used in functions
33-
props.showPrivateIcon = ownProps.isPrivateTab && hasSeconardImage
34-
props.frameKey = frameKey
31+
props.showPrivateIcon = privateState.showPrivateIcon(currentWindow, frameKey)
32+
props.tabId = tabId
3533

3634
return props
3735
}
3836

3937
render () {
40-
if (!this.props.showPrivateIcon) {
38+
if (this.props.isPinned || !this.props.showPrivateIcon) {
4139
return null
4240
}
43-
const privateStyles = StyleSheet.create({
44-
icon: {
45-
backgroundColor: this.props.isActive ? globalStyles.color.white100 : globalStyles.color.black100
41+
42+
const privateProps = StyleSheet.create({
43+
private__icon_color: {
44+
backgroundColor: this.props.isActive
45+
? theme.tab.content.icon.private.background.active
46+
: theme.tab.content.icon.private.background.notActive
4647
}
4748
})
4849

4950
return <TabIcon
5051
data-test-id='privateIcon'
51-
className={css(styles.icon, styles.secondaryIcon, privateStyles.icon)}
52+
className={css(styles.private__icon, privateProps.private__icon_color)}
5253
/>
5354
}
5455
}
5556

5657
module.exports = ReduxComponent.connect(PrivateIcon)
5758

5859
const styles = StyleSheet.create({
59-
icon: {
60-
width: globalStyles.spacing.iconSize,
61-
minWidth: globalStyles.spacing.iconSize,
62-
height: globalStyles.spacing.iconSize,
63-
backgroundSize: globalStyles.spacing.iconSize,
64-
fontSize: globalStyles.fontSize.tabIcon,
65-
backgroundPosition: 'center',
66-
backgroundRepeat: 'no-repeat',
67-
paddingLeft: globalStyles.spacing.defaultIconPadding,
68-
paddingRight: globalStyles.spacing.defaultIconPadding
69-
},
70-
71-
secondaryIcon: {
60+
private__icon: {
61+
boxSizing: 'border-box',
7262
WebkitMaskRepeat: 'no-repeat',
7363
WebkitMaskPosition: 'center',
74-
WebkitMaskImage: `url(${privateSvg})`
64+
WebkitMaskImage: `url(${privateSvg})`,
65+
WebkitMaskSize: globalStyles.spacing.sessionIconSize,
66+
width: globalStyles.spacing.sessionIconSize,
67+
height: globalStyles.spacing.sessionIconSize
7568
}
7669
})

app/renderer/components/tabs/tab.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class Tab extends React.Component {
370370
<AudioTabIcon tabId={this.props.tabId} />
371371
<TabTitle tabId={this.props.tabId} />
372372
</div>
373-
<PrivateIcon isPrivateTab={this.props.isPrivateTab} frameKey={this.props.frameKey} />
373+
<PrivateIcon tabId={this.props.tabId} />
374374
<NewSessionIcon frameKey={this.props.frameKey} />
375375
<CloseTabIcon tabId={this.props.tabId} fixTabWidth={this.fixTabWidth} />
376376
</div>

0 commit comments

Comments
 (0)