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

Commit

Permalink
Moves context menu into reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jun 26, 2017
1 parent d776d63 commit 147aba4
Show file tree
Hide file tree
Showing 7 changed files with 492 additions and 155 deletions.
29 changes: 17 additions & 12 deletions app/renderer/components/bookmarks/bookmarkToolbarButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const windowActions = require('../../../../js/actions/windowActions')
const appActions = require('../../../../js/actions/appActions')
const bookmarkActions = require('../../../../js/actions/bookmarkActions')

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

// Constants
const dragTypes = require('../../../../js/constants/dragTypes')
const {iconSize} = require('../../../../js/constants/config')
Expand All @@ -28,7 +25,6 @@ const {getCurrentWindowId} = require('../../currentWindow')
const dnd = require('../../../../js/dnd')
const cx = require('../../../../js/lib/classSet')
const frameStateUtil = require('../../../../js/state/frameStateUtil')
const contextMenus = require('../../../../js/contextMenus')
const bookmarkUtil = require('../../../common/lib/bookmarkUtil')

// Styles
Expand All @@ -55,10 +51,6 @@ class BookmarkToolbarButton extends React.Component {
this.bookmarkNode.addEventListener('auxclick', this.onAuxClick)
}

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

onAuxClick (e) {
if (e.button === 1) {
this.onClick(e)
Expand Down Expand Up @@ -143,16 +135,28 @@ class BookmarkToolbarButton extends React.Component {
}

openContextMenu (e) {
contextMenus.onSiteDetailContextMenu(this.props.bookmark, this.activeFrame, e)
if (e) {
e.stopPropagation()
}
windowActions.onSiteDetailMenu(this.props.bookmarkKey)
}

clickBookmarkItem (e) {
return bookmarkActions.clickBookmarkItem(this.props.bookmarks, this.props.bookmark, this.activeFrame, e)
return bookmarkActions.clickBookmarkItem(this.props.bookmarkKey, this.props.tabId, e)
}

showBookmarkFolderMenu (e) {
const rectLeft = e.target.getBoundingClientRect()
const rectBottom = e.target.parentNode.getBoundingClientRect()
const left = (rectLeft.left | 0) - 2
const top = (rectBottom.bottom | 0) - 1

if (e && e.stopPropagation) {
e.stopPropagation()
}

windowActions.onShowBookmarkFolderMenu(this.props.bookmarkKey, left, top)
windowActions.setBookmarksToolbarSelectedFolderId(this.props.folderId)
contextMenus.onShowBookmarkFolderMenu(this.props.bookmarks, this.props.bookmark, this.activeFrame, e)
}

mergeProps (state, ownProps) {
Expand All @@ -176,8 +180,9 @@ class BookmarkToolbarButton extends React.Component {

// used in other function
props.bookmarkKey = ownProps.bookmarkKey
props.bookmarks = siteUtil.getBookmarks(state.get('sites')) // TODO (nejc) only primitives
props.tabId = activeFrame.get('tabId')
props.contextMenuDetail = !!currentWindow.get('contextMenuDetail')
props.bookmark = bookmark // TODO (nejc) only primitives
props.draggingOverData = draggingOverData // TODO (nejc) only primitives
props.activeFrameKey = activeFrame.get('key')
props.selectedFolderId = currentWindow.getIn(['ui', 'bookmarksToolbar', 'selectedFolderId'])
Expand Down
12 changes: 3 additions & 9 deletions app/renderer/components/bookmarks/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const appActions = require('../../../../js/actions/appActions')
// State
const windowState = require('../../../common/state/windowState')

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

// Constants
const siteTags = require('../../../../js/constants/siteTags')
const dragTypes = require('../../../../js/constants/dragTypes')
Expand All @@ -38,6 +35,7 @@ const bookmarkUtil = require('../../../common/lib/bookmarkUtil')

// Styles
const globalStyles = require('../styles/global')
var windowActions = require('../../../../js/actions/windowActions.js')

class BookmarksToolbar extends React.Component {
constructor (props) {
Expand All @@ -49,10 +47,6 @@ class BookmarksToolbar extends React.Component {
this.onMoreBookmarksMenu = this.onMoreBookmarksMenu.bind(this)
}

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

onDrop (e) {
e.preventDefault()
const bookmark = dnd.prepareBookmarkDataFromCompatible(e.dataTransfer)
Expand Down Expand Up @@ -127,7 +121,8 @@ class BookmarksToolbar extends React.Component {
}

onMoreBookmarksMenu (e) {
contextMenus.onMoreBookmarksMenu(this.activeFrame, this.props.bookmarks, this.props.hiddenBookmarks, e)
const rect = e.target.getBoundingClientRect()
windowActions.onMoreBookmarksMenu(this.props.hiddenBookmarks, rect.top)
}

onContextMenu (e) {
Expand Down Expand Up @@ -159,7 +154,6 @@ class BookmarksToolbar extends React.Component {
props.activeFrameKey = activeFrame.get('key')
props.title = activeFrame.get('title')
props.location = activeFrame.get('location')
props.bookmarks = siteUtil.getBookmarks(state.get('sites', Immutable.List())) // TODO (nejc) only primitives

return props
}
Expand Down
Loading

0 comments on commit 147aba4

Please sign in to comment.