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

Fix bookmark toolbar not showing on first bookmark from context menu #3355

Merged
merged 1 commit into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions js/components/addEditBookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ const windowActions = require('../actions/windowActions')
const appActions = require('../actions/appActions')
const KeyCodes = require('../constants/keyCodes')
const siteTags = require('../constants/siteTags')
const messages = require('../constants/messages')
const settings = require('../constants/settings')
const siteUtil = require('../state/siteUtil')
const getSetting = require('../settings').getSetting
const ipc = global.require('electron').ipcRenderer

class AddEditBookmark extends ImmutableComponent {
constructor () {
Expand Down Expand Up @@ -85,18 +89,31 @@ class AddEditBookmark extends ImmutableComponent {
const currentDetail = this.props.currentDetail.set('parentFolderId', Number(e.target.value))
windowActions.setBookmarkDetail(currentDetail, this.props.originalDetail, this.props.destinationDetail)
}
showToolbarOnFirstBookmark () {
const showBookmarksToolbar = getSetting(settings.SHOW_BOOKMARKS_TOOLBAR)
const isFirstBookmark = this.props.sites.find(
(site) => siteUtil.isBookmark(site) || siteUtil.isFolder(site)
)
appActions.changeSetting(settings.SHOW_BOOKMARKS_TOOLBAR, !isFirstBookmark || showBookmarksToolbar)
}
updateMenuBookmarkedStatus (isBookmarked) {
ipc.send(messages.UPDATE_MENU_BOOKMARKED_STATUS, isBookmarked)
}
onSave () {
// First check if the title of the currentDetail is set
if (!this.bookmarkNameValid) {
return false
}

this.showToolbarOnFirstBookmark()
const tag = this.isFolder ? siteTags.BOOKMARK_FOLDER : siteTags.BOOKMARK
appActions.addSite(this.props.currentDetail, tag, this.props.originalDetail, this.props.destinationDetail)
this.updateMenuBookmarkedStatus(true)
this.onClose()
}
onRemoveBookmark () {
appActions.removeSite(this.props.currentDetail, siteTags.BOOKMARK)
this.updateMenuBookmarkedStatus(false)
this.onClose()
}
get displayBookmarkName () {
Expand Down
23 changes: 4 additions & 19 deletions js/components/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const ImmutableComponent = require('./immutableComponent')
const cx = require('../lib/classSet.js')
const Button = require('./button')
const UrlBar = require('./urlBar')
const appActions = require('../actions/appActions')
const windowActions = require('../actions/windowActions')
const siteTags = require('../constants/siteTags')
const messages = require('../constants/messages')
Expand Down Expand Up @@ -38,24 +37,10 @@ class NavigationBar extends ImmutableComponent {
return this.props.activeFrameKey !== undefined && this.props.loading
}

onToggleBookmark (isBookmarked) {
if (isBookmarked === undefined) {
isBookmarked = this.bookmarked
}
onToggleBookmark () {
// trigger the AddEditBookmark modal; saving/deleting takes place there
const siteDetail = siteUtil.getDetailFromFrame(this.activeFrame, siteTags.BOOKMARK)
const showBookmarksToolbar = getSetting(settings.SHOW_BOOKMARKS_TOOLBAR)
const hasBookmark = this.props.sites.find(
(site) => siteUtil.isBookmark(site) || siteUtil.isFolder(site)
)
if (!isBookmarked) {
appActions.addSite(siteDetail, siteTags.BOOKMARK)
}
// Show bookmarks toolbar after first bookmark is saved
appActions.changeSetting(settings.SHOW_BOOKMARKS_TOOLBAR, !hasBookmark || showBookmarksToolbar)
// trigger the AddEditBookmark modal
windowActions.setBookmarkDetail(siteDetail, siteDetail)
// Update checked/unchecked status in the Bookmarks menu
ipc.send(messages.UPDATE_MENU_BOOKMARKED_STATUS, this.bookmarked)
}

onReload (e) {
Expand Down Expand Up @@ -97,8 +82,8 @@ class NavigationBar extends ImmutableComponent {
}

componentDidMount () {
ipc.on(messages.SHORTCUT_ACTIVE_FRAME_BOOKMARK, () => this.onToggleBookmark(false))
ipc.on(messages.SHORTCUT_ACTIVE_FRAME_REMOVE_BOOKMARK, () => this.onToggleBookmark(true))
ipc.on(messages.SHORTCUT_ACTIVE_FRAME_BOOKMARK, () => this.onToggleBookmark())
ipc.on(messages.SHORTCUT_ACTIVE_FRAME_REMOVE_BOOKMARK, () => this.onToggleBookmark())
// Set initial checked/unchecked status in Bookmarks menu
ipc.send(messages.UPDATE_MENU_BOOKMARKED_STATUS, this.bookmarked)
}
Expand Down
2 changes: 1 addition & 1 deletion js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ipc.on(messages.REQUEST_MENU_DATA_FOR_WINDOW, () => {
const windowState = windowStore.getState()
const activeFrame = FrameStateUtil.getActiveFrame(Immutable.fromJS(windowState))
const windowData = {
location: activeFrame.get('location'),
location: activeFrame ? activeFrame.get('location') : null,
closedFrames: windowState.get('closedFrames').toJS()
}
ipc.send(messages.RESPONSE_MENU_DATA_FOR_WINDOW, windowData)
Expand Down