diff --git a/app/renderer/components/navigation/navigationBar.js b/app/renderer/components/navigation/navigationBar.js index be11a8c01ef..21486a1e43c 100644 --- a/app/renderer/components/navigation/navigationBar.js +++ b/app/renderer/components/navigation/navigationBar.js @@ -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') @@ -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') @@ -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) { @@ -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) diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 1a50eeb4ee7..93a1b37d48e 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -1142,6 +1142,13 @@ const windowActions = { url, error }) + }, + + onToggleBookmark: function (isBookmarked) { + dispatch({ + actionType: windowConstants.WINDOW_ON_TOGGLE_BOOKMARK, + isBookmarked + }) } } diff --git a/js/constants/windowConstants.js b/js/constants/windowConstants.js index 6a653a956d2..b8690cc6b4c 100644 --- a/js/constants/windowConstants.js +++ b/js/constants/windowConstants.js @@ -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) diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 088396799e2..e01cc5201c8 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -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') @@ -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, @@ -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 }