From 2d649990b7185cadb6f76db06202a3ab58d51b5e Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Thu, 20 Jul 2017 00:51:46 +0900 Subject: [PATCH] Add navigationBarButtonContainer etc Closes #9846 Addresses #9283 Full changelog: https://github.com/brave/browser-laptop/commit/0d5d4fd84a8456ddf5029da433b929e90abfaca1 https://github.com/brave/browser-laptop/commit/ab59b147810ad98a13744bc11817d83e5310ac5b --- .../navigation/buttons/bookmarkButton.js | 131 ++++++++++++ .../navigation/buttons/homeButton.js | 95 +++++++++ .../buttons/navigationBarButtonContainer.js | 70 +++++++ .../navigation/buttons/reloadButton.js | 98 +++++++++ .../navigation/buttons/stopButton.js | 56 +++++ .../components/navigation/homeButton.js | 82 -------- .../components/navigation/navigationBar.js | 191 +++++------------- .../components/styles/commonStyles.js | 35 ---- 8 files changed, 495 insertions(+), 263 deletions(-) create mode 100644 app/renderer/components/navigation/buttons/bookmarkButton.js create mode 100644 app/renderer/components/navigation/buttons/homeButton.js create mode 100644 app/renderer/components/navigation/buttons/navigationBarButtonContainer.js create mode 100644 app/renderer/components/navigation/buttons/reloadButton.js create mode 100644 app/renderer/components/navigation/buttons/stopButton.js delete mode 100644 app/renderer/components/navigation/homeButton.js diff --git a/app/renderer/components/navigation/buttons/bookmarkButton.js b/app/renderer/components/navigation/buttons/bookmarkButton.js new file mode 100644 index 00000000000..93ab551c29b --- /dev/null +++ b/app/renderer/components/navigation/buttons/bookmarkButton.js @@ -0,0 +1,131 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +const React = require('react') +const Immutable = require('immutable') +const ipc = require('electron').ipcRenderer + +// Components +const ReduxComponent = require('../../reduxComponent') + +// Actions +const windowActions = require('../../../../../js/actions/windowActions') + +// Constants +const siteTags = require('../../../../../js/constants/siteTags') +const messages = require('../../../../../js/constants/messages') +const settings = require('../../../../../js/constants/settings') + +// State +const tabState = require('../../../../common/state/tabState') +const frameStateUtil = require('../../../../../js/state/frameStateUtil') + +// Store +const windowStore = require('../../../../../js/stores/windowStore') + +// Utils +const cx = require('../../../../../js/lib/classSet') +const siteUtil = require('../../../../../js/state/siteUtil') +const UrlUtil = require('../../../../../js/lib/urlutil') +const {getSetting} = require('../../../../../js/settings') + +const {StyleSheet, css} = require('aphrodite/no-important') + +const bookmarkButtonIcon = require('../../../../../img/toolbar/bookmark_btn.svg') +const bookmarkedButtonIcon = require('../../../../../img/toolbar/bookmark_marked.svg') + +class BookmarkButton extends React.Component { + constructor (props) { + super(props) + this.onToggleBookmark = this.onToggleBookmark.bind(this) + } + + get bookmarked () { + return this.props.activeFrameKey !== undefined && this.props.bookmarked + } + + get activeFrame () { + return windowStore.getFrame(this.props.activeFrameKey) + } + + onToggleBookmark () { + const editing = this.bookmarked + // 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) + } + + mergeProps (state, dispatchProps, ownProps) { + const currentWindow = state.get('currentWindow') + const activeFrame = frameStateUtil.getActiveFrame(currentWindow) || Immutable.Map() + const activeFrameKey = activeFrame.get('key') + const activeTabId = activeFrame.get('tabId', tabState.TAB_ID_NONE) + const activeTab = tabState.getByTabId(state, activeTabId) + + const props = {} + props.activeFrameKey = activeFrameKey + props.bookmarked = activeTab && activeTab.get('bookmarked') + props.sites = state.get('sites') + + return props + } + + componentDidMount () { + ipc.on(messages.SHORTCUT_ACTIVE_FRAME_BOOKMARK, () => this.onToggleBookmark()) + ipc.on(messages.SHORTCUT_ACTIVE_FRAME_REMOVE_BOOKMARK, () => this.onToggleBookmark()) + } + + render () { + return ( +