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

Commit

Permalink
convert urlbar to ReduxComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Apr 12, 2017
1 parent 3ab1c68 commit 867edba
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
50 changes: 1 addition & 49 deletions app/renderer/components/navigation/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const siteTags = require('../../../../js/constants/siteTags')
const messages = require('../../../../js/constants/messages')
const settings = require('../../../../js/constants/settings')
const ipc = require('electron').ipcRenderer
const {isSourceAboutUrl, getBaseUrl} = require('../../../../js/lib/appUrlUtil')
const {isSourceAboutUrl} = require('../../../../js/lib/appUrlUtil')
const AddEditBookmarkHanger = require('../addEditBookmarkHanger')
const siteUtil = require('../../../../js/state/siteUtil')
const eventUtil = require('../../../../js/lib/eventUtil')
Expand Down Expand Up @@ -126,29 +126,6 @@ class NavigationBar extends React.Component {
)
}

get locationId () {
return getBaseUrl(this.props.location)
}

get publisherId () {
return this.props.locationInfo && this.props.locationInfo.getIn([this.locationId, 'publisher'])
}

get visiblePublisher () {
const hostPattern = UrlUtil.getHostPattern(this.publisherId)
const hostSettings = this.props.siteSettings.get(hostPattern)
const ledgerPaymentsShown = hostSettings && hostSettings.get('ledgerPaymentsShown')
return typeof ledgerPaymentsShown === 'boolean'
? ledgerPaymentsShown
: true
}

get isPublisherButtonEnabled () {
return getSetting(settings.PAYMENTS_ENABLED) &&
UrlUtil.isHttpOrHttps(this.props.location) &&
this.visiblePublisher
}

componentDidMount () {
ipc.on(messages.SHORTCUT_ACTIVE_FRAME_BOOKMARK, () => this.onToggleBookmark())
ipc.on(messages.SHORTCUT_ACTIVE_FRAME_REMOVE_BOOKMARK, () => this.onToggleBookmark())
Expand All @@ -157,31 +134,21 @@ class NavigationBar extends React.Component {
mergeProps (state, dispatchProps, ownProps) {
const windowState = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(windowState) || Immutable.Map()
const activeTab = tabState.getActiveTabValue(state, getCurrentWindowId()) || Immutable.Map()
const activeTabId = tabState.getActiveTabId(state, getCurrentWindowId())
const props = {}

props.navbar = activeFrame.get('navbar')
props.sites = state.get('sites')
props.canGoForward = activeTab.get('canGoForward') || false
props.activeFrameKey = activeFrame.get('key')
props.location = activeFrame.get('location') || ''
props.title = activeFrame.get('title') || ''
props.scriptsBlocked = activeFrame.getIn(['noScript', 'blocked'])
props.partitionNumber = activeFrame.get('partitionNumber') || 0
props.history = activeFrame.get('history') || new Immutable.List()
props.suggestionIndex = activeFrame.getIn(['navbar', 'urlbar', 'suggestions', 'selectedIndex']) || 0
props.isSecure = activeFrame.getIn(['security', 'isSecure'])
props.hasLocationValueSuffix = activeFrame.getIn(['navbar', 'urlbar', 'suggestions', 'urlSuffix'])
props.startLoadTime = activeFrame.get('startLoadTime')
props.endLoadTime = activeFrame.get('endLoadTime')
props.loading = activeFrame.get('loading')
props.bookmarkDetail = windowState.get('bookmarkDetail')
props.mouseInTitlebar = windowState.getIn(['ui', 'mouseInTitlebar'])
props.searchDetail = windowState.get('searchDetail')
props.enableNoScript = ownProps.enableNoScript
props.settings = state.get('settings')
props.noScriptIsVisible = windowState.getIn(['ui', 'noScriptInfo', 'isVisible']) || false
props.menubarVisible = ownProps.menubarVisible
props.siteSettings = state.get('siteSettings')
props.synopsis = state.getIn(['publisherInfo', 'synopsis']) || new Immutable.Map()
Expand Down Expand Up @@ -257,25 +224,10 @@ class NavigationBar extends React.Component {
}
</div>
<UrlBar ref='urlBar'
activeFrameKey={this.props.activeFrameKey}
canGoForward={this.props.canGoForward}
searchDetail={this.props.searchDetail}
loading={this.loading}
location={this.props.location}
title={this.props.title}
history={this.props.history}
isSecure={this.props.isSecure}
hasLocationValueSuffix={this.props.hasLocationValueSuffix}
startLoadTime={this.props.startLoadTime}
endLoadTime={this.props.endLoadTime}
titleMode={this.titleMode}
urlbar={this.props.navbar.get('urlbar')}
onStop={this.onStop}
menubarVisible={this.props.menubarVisible}
noBorderRadius={this.isPublisherButtonEnabled}
activeTabShowingMessageBox={this.props.activeTabShowingMessageBox}
enableNoScript={this.props.enableNoScript}
scriptsBlocked={this.props.scriptsBlocked}
/>
{
isSourceAboutUrl(this.props.location)
Expand Down
60 changes: 54 additions & 6 deletions app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

const React = require('react')

const ImmutableComponent = require('../../../../js/components/immutableComponent')
const ReduxComponent = require('../reduxComponent')
const {StyleSheet, css} = require('aphrodite')
const Immutable = require('immutable')

const windowActions = require('../../../../js/actions/windowActions')
const appActions = require('../../../../js/actions/appActions')
Expand All @@ -18,20 +19,26 @@ const ipc = require('electron').ipcRenderer
const UrlBarSuggestions = require('./urlBarSuggestions')
const UrlBarIcon = require('./urlBarIcon')
const messages = require('../../../../js/constants/messages')
const siteSettings = require('../../../../js/state/siteSettings')
const {getSetting} = require('../../../../js/settings')
const settings = require('../../../../js/constants/settings')
const contextMenus = require('../../../../js/contextMenus')
const windowStore = require('../../../../js/stores/windowStore')
const UrlUtil = require('../../../../js/lib/urlutil')
const {eventElHasAncestorWithClasses, isForSecondaryAction} = require('../../../../js/lib/eventUtil')
const {isUrl, isIntermediateAboutPage} = require('../../../../js/lib/appUrlUtil')
const {getBaseUrl, isUrl, isIntermediateAboutPage} = require('../../../../js/lib/appUrlUtil')
const {getCurrentWindowId} = require('../../currentWindow')

// Icons
const iconNoScript = require('../../../../img/url-bar-no-script.svg')

class UrlBar extends ImmutableComponent {
constructor () {
super()
// State
const frameStateUtil = require('../../../../js/state/frameStateUtil')
const tabState = require('../../../common/state/tabState')

class UrlBar extends React.Component {
constructor (props) {
super(props)
this.onFocus = this.onFocus.bind(this)
this.onBlur = this.onBlur.bind(this)
this.onKeyDown = this.onKeyDown.bind(this)
Expand Down Expand Up @@ -505,6 +512,47 @@ class UrlBar extends ImmutableComponent {
contextMenus.onUrlBarContextMenu(this.props.searchDetail, this.activeFrame, e)
}

mergeProps (state, dispatchProps, ownProps) {
const windowState = state.get('currentWindow')
const activeFrame = frameStateUtil.getActiveFrame(windowState) || Immutable.Map()
const activeTabId = tabState.getActiveTabId(state, getCurrentWindowId())

const location = activeFrame.get('location') || ''
const baseUrl = getBaseUrl(location)

// TODO(bridiver) - this definitely needs a helper
const publisherId = state.getIn(['locationInfo', baseUrl, 'publisher'])
const hostPattern = UrlUtil.getHostPattern(publisherId)
const hostSettings = siteSettings.getSiteSettingsForHostPattern(state.get('settings'), hostPattern)
const ledgerPaymentsShown = hostSettings && hostSettings.get('ledgerPaymentsShown')
const visiblePublisher = typeof ledgerPaymentsShown === 'boolean' ? ledgerPaymentsShown : true
const isPublisherButtonEnabled = getSetting(settings.PAYMENTS_ENABLED) &&
UrlUtil.isHttpOrHttps(location) && visiblePublisher

const props = {}

props.activeFrameKey = activeFrame.get('key')
props.location = location
props.title = activeFrame.get('title') || ''
props.scriptsBlocked = activeFrame.getIn(['noScript', 'blocked'])
props.history = activeFrame.get('history') || new Immutable.List()
props.isSecure = activeFrame.getIn(['security', 'isSecure'])
props.hasLocationValueSuffix = activeFrame.getIn(['navbar', 'urlbar', 'suggestions', 'urlSuffix'])
props.startLoadTime = activeFrame.get('startLoadTime')
props.endLoadTime = activeFrame.get('endLoadTime')
props.loading = activeFrame.get('loading')
props.searchDetail = windowState.get('searchDetail')
props.enableNoScript = ownProps.enableNoScript
props.noScriptIsVisible = windowState.getIn(['ui', 'noScriptInfo', 'isVisible']) || false
props.menubarVisible = ownProps.menubarVisible
props.activeTabShowingMessageBox = tabState.isShowingMessageBox(state, activeTabId)
props.noBorderRadius = isPublisherButtonEnabled
props.urlbar = activeFrame.getIn(['navbar', 'urlbar'])
props.onStop = ownProps.onStop
props.titleMode = ownProps.titleMode
return props
}

render () {
return <form
className={cx({
Expand Down Expand Up @@ -605,4 +653,4 @@ const styles = StyleSheet.create({
}
})

module.exports = UrlBar
module.exports = ReduxComponent.connect(UrlBar)

0 comments on commit 867edba

Please sign in to comment.