Skip to content

Commit

Permalink
Removes non-primitive types from NavigationBar
Browse files Browse the repository at this point in the history
Resolves brave#9791

Auditors: @bridiver @bsclifton

Test Plan:
  • Loading branch information
NejcZdovc committed Jun 30, 2017
1 parent 5114cc3 commit d03851a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
23 changes: 1 addition & 22 deletions app/renderer/components/navigation/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const windowActions = require('../../../../js/actions/windowActions')
const appActions = require('../../../../js/actions/appActions')

// Constants
const siteTags = require('../../../../js/constants/siteTags')
const messages = require('../../../../js/constants/messages')
const settings = require('../../../../js/constants/settings')

Expand All @@ -28,15 +27,10 @@ const tabState = require('../../../common/state/tabState')
const publisherState = require('../../../common/lib/publisherUtil')
const frameStateUtil = require('../../../../js/state/frameStateUtil')

// Store
const windowStore = require('../../../../js/stores/windowStore')

// Utils
const cx = require('../../../../js/lib/classSet')
const {getBaseUrl} = require('../../../../js/lib/appUrlUtil')
const siteUtil = require('../../../../js/state/siteUtil')
const eventUtil = require('../../../../js/lib/eventUtil')
const UrlUtil = require('../../../../js/lib/urlutil')
const {getSetting} = require('../../../../js/settings')
const contextMenus = require('../../../../js/contextMenus')

Expand All @@ -51,22 +45,8 @@ class NavigationBar extends React.Component {
this.onReloadLongPress = this.onReloadLongPress.bind(this)
}

get activeFrame () {
return windowStore.getFrame(this.props.activeFrameKey)
}

onToggleBookmark () {
const editing = this.props.isBookmarked
// show the AddEditBookmarkHanger control; saving/deleting takes place there
let siteDetail = siteUtil.getDetailFromFrame(this.activeFrame, siteTags.BOOKMARK)
const key = siteUtil.getSiteKey(siteDetail)

if (key !== null) {
siteDetail = siteDetail.set('parentFolderId', this.props.sites.getIn([key, 'parentFolderId']))
siteDetail = siteDetail.set('customTitle', this.props.sites.getIn([key, 'customTitle']))
}
siteDetail = siteDetail.set('location', UrlUtil.getLocationIfPDF(siteDetail.get('location')))
windowActions.setBookmarkDetail(siteDetail, siteDetail, null, editing, true)
windowActions.onToggleBookmark(this.props.isBookmarked)
}

onReload (e) {
Expand Down Expand Up @@ -145,7 +125,6 @@ class NavigationBar extends React.Component {

// used in other functions
props.navbar = navbar // TODO(nejc) remove, primitives only
props.sites = state.get('sites') // TODO(nejc) remove, primitives only
props.activeTabId = activeTabId
props.showHomeButton = !props.titleMode && getSetting(settings.SHOW_HOME_BUTTON)

Expand Down
7 changes: 7 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,13 @@ const windowActions = {
url,
error
})
},

onToggleBookmark: function (isBookmarked) {
dispatch({
actionType: windowConstants.WINDOW_ON_TOGGLE_BOOKMARK,
isBookmarked
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ const windowConstants = {
WINDOW_ON_GO_BACK_LONG: _,
WINDOW_ON_GO_FORWARD_LONG: _,
WINDOW_CLOSE_OTHER_FRAMES: _,
WINDOW_ON_CERT_ERROR: _
WINDOW_ON_CERT_ERROR: _,
WINDOW_ON_TOGGLE_BOOKMARK: _
}

module.exports = mapValuesByKeys(windowConstants)
20 changes: 19 additions & 1 deletion js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const frameStateUtil = require('../state/frameStateUtil')
const ipc = require('electron').ipcRenderer
const messages = require('../constants/messages')
const debounce = require('../lib/debounce')
const getSetting = require('../settings').getSetting
const {getSetting} = require('../settings')
const UrlUtil = require('../lib/urlutil')
const {l10nErrorText} = require('../../app/common/lib/httpUtil')
const { makeImmutable } = require('../../app/common/state/immutableUtil')
Expand All @@ -23,6 +23,8 @@ const assert = require('assert')
const contextMenuState = require('../../app/common/state/contextMenuState')
const appStoreRenderer = require('./appStoreRenderer')
const windowActions = require('../actions/windowActions')
const siteUtil = require('../state/siteUtil')
const siteTags = require('../constants/siteTags')

let windowState = Immutable.fromJS({
activeFrameKey: null,
Expand Down Expand Up @@ -750,6 +752,22 @@ const doAction = (action) => {
}
break
}
case windowConstants.WINDOW_ON_TOGGLE_BOOKMARK:
{
// show the AddEditBookmarkHanger control; saving/deleting takes place there
const activeFrame = frameStateUtil.getActiveFrame(windowState)
let siteDetail = siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK)
const key = siteUtil.getSiteKey(siteDetail)

if (key !== null) {
const site = appStoreRenderer.state.getIn(['sites', key], Immutable.Map())
siteDetail = siteDetail.set('parentFolderId', site.get('parentFolderId'))
siteDetail = siteDetail.set('customTitle', site.get('customTitle'))
}
siteDetail = siteDetail.set('location', UrlUtil.getLocationIfPDF(siteDetail.get('location')))
windowActions.setBookmarkDetail(siteDetail, siteDetail, null, action.isBookmarked, true)
break
}
default:
break
}
Expand Down

0 comments on commit d03851a

Please sign in to comment.