From be72eb4aa71063dd265432f35405bd904511c419 Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Fri, 5 Jan 2018 18:13:44 -0200 Subject: [PATCH] Merge pull request #12515 from NejcZdovc/hotfix/#12476-drop Fixes dnd for url bar icon --- .../components/bookmarks/bookmarksToolbar.js | 23 +++++++++++++++---- .../components/navigation/urlBarIcon.js | 4 ++-- app/renderer/reducers/frameReducer.js | 11 --------- js/actions/windowActions.js | 7 ------ js/constants/windowConstants.js | 1 - js/dnd.js | 8 ++++++- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/renderer/components/bookmarks/bookmarksToolbar.js b/app/renderer/components/bookmarks/bookmarksToolbar.js index ada8e933170..792fe307298 100644 --- a/app/renderer/components/bookmarks/bookmarksToolbar.js +++ b/app/renderer/components/bookmarks/bookmarksToolbar.js @@ -58,19 +58,32 @@ class BookmarksToolbar extends React.Component { } return bookmarkRef.props.bookmarkKey !== sourceKey }), e.clientX) - const bookmark = dnd.prepareBookmarkDataFromCompatible(e.dataTransfer) + let bookmark = dnd.prepareBookmarkDataFromCompatible(e.dataTransfer) if (bookmark) { // Figure out the droppedOn element filtering out the source drag item - const bookmarkKey = bookmark.get('key') + let bookmarkKey = bookmark.get('key') + let tabDrop = false + + // When we have key null is only when we are getting data from TAB transfer type + if (bookmarkKey == null) { + tabDrop = true + } + const droppedOn = getClosestFromPos(e.clientX, bookmarkKey) if (droppedOn.selectedRef) { const isRightSide = !dnd.isLeftSide(ReactDOM.findDOMNode(droppedOn.selectedRef), e.clientX) const droppedOnKey = droppedOn.selectedRef.props.bookmarkKey const isDestinationParent = droppedOn.selectedRef.state.isFolder && droppedOn && droppedOn.isDroppedOn - if (bookmark.get('type') === siteTags.BOOKMARK_FOLDER) { - appActions.moveBookmarkFolder(bookmark.get('key'), droppedOnKey, isRightSide, isDestinationParent) + if (tabDrop) { + const parentKey = isDestinationParent ? droppedOnKey : null + bookmark = bookmark.set('parentFolderId', parentKey) + appActions.addBookmark(bookmark) } else { - appActions.moveBookmark(bookmark.get('key'), droppedOnKey, isRightSide, isDestinationParent) + if (bookmark.get('type') === siteTags.BOOKMARK_FOLDER) { + appActions.moveBookmarkFolder(bookmarkKey, droppedOnKey, isRightSide, isDestinationParent) + } else { + appActions.moveBookmark(bookmarkKey, droppedOnKey, isRightSide, isDestinationParent) + } } dnd.onDragEnd() } diff --git a/app/renderer/components/navigation/urlBarIcon.js b/app/renderer/components/navigation/urlBarIcon.js index 1fd6fcaaaca..e0f12053dc7 100644 --- a/app/renderer/components/navigation/urlBarIcon.js +++ b/app/renderer/components/navigation/urlBarIcon.js @@ -112,7 +112,8 @@ class UrlBarIcon extends React.Component { onDragStart (e) { dndData.setupDataTransferURL(e.dataTransfer, this.props.location, this.props.title) dndData.setupDataTransferBraveData(e.dataTransfer, dragTypes.TAB, { - tabId: this.props.tabId + location: this.props.location, + title: this.props.title }) } @@ -140,7 +141,6 @@ class UrlBarIcon extends React.Component { // used in other functions props.title = activeFrame.get('title', '') - props.tabId = activeFrame.get('tabId', tabState.TAB_ID_NONE) return props } diff --git a/app/renderer/reducers/frameReducer.js b/app/renderer/reducers/frameReducer.js index d25e1dd9f06..1460bfc54f7 100644 --- a/app/renderer/reducers/frameReducer.js +++ b/app/renderer/reducers/frameReducer.js @@ -18,7 +18,6 @@ const appActions = require('../../../js/actions/appActions') const frameStateUtil = require('../../../js/state/frameStateUtil') const {getSourceAboutUrl, getSourceMagnetUrl} = require('../../../js/lib/appUrlUtil') const {isURL, isPotentialPhishingUrl, getUrlFromInput} = require('../../../js/lib/urlutil') -const bookmarkUtil = require('../../common/lib/bookmarkUtil') const setFullScreen = (state, action) => { const index = frameStateUtil.getIndexByTabId(state, action.tabId) @@ -257,16 +256,6 @@ const frameReducer = (state, action, immutableAction) => { case windowConstants.WINDOW_SET_FULL_SCREEN: state = setFullScreen(state, action) break - case windowConstants.WINDOW_ON_FRAME_BOOKMARK: - { - // TODO make this an appAction that gets the bookmark data from tabState - const frameProps = frameStateUtil.getFrameByTabId(state, action.tabId) - if (frameProps) { - const bookmark = bookmarkUtil.getDetailFromFrame(frameProps) - appActions.addBookmark(bookmark) - } - break - } // TODO(bbondy): We should remove this window action completely and just go directly to // the browser process with an app action. case windowConstants.WINDOW_TAB_MOVE: { diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 5b47d9a1a21..ca02820f052 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -1128,13 +1128,6 @@ const windowActions = { }) }, - onFrameBookmark: function (tabId) { - dispatch({ - actionType: windowConstants.WINDOW_ON_FRAME_BOOKMARK, - tabId - }) - }, - onStop: function (isFocused, shouldRender) { dispatch({ actionType: windowConstants.WINDOW_ON_STOP, diff --git a/js/constants/windowConstants.js b/js/constants/windowConstants.js index 7a961d2e4b9..9318e2bcb89 100644 --- a/js/constants/windowConstants.js +++ b/js/constants/windowConstants.js @@ -95,7 +95,6 @@ const windowConstants = { WINDOW_ON_GO_FORWARD_LONG: _, WINDOW_ON_CERT_ERROR: _, WINDOW_ON_TAB_PAGE_CONTEXT_MENU: _, - WINDOW_ON_FRAME_BOOKMARK: _, WINDOW_ON_STOP: _, WINDOW_ON_MORE_BOOKMARKS_MENU: _, WINDOW_ON_SHOW_BOOKMARK_FOLDER_MENU: _, diff --git a/js/dnd.js b/js/dnd.js index 6841f8cdcc9..42a97204f0d 100644 --- a/js/dnd.js +++ b/js/dnd.js @@ -6,7 +6,9 @@ const windowActions = require('./actions/windowActions') const appActions = require('./actions/appActions') const ReactDOM = require('react-dom') const dndData = require('./dndData') +const Immutable = require('immutable') const dragTypes = require('./constants/dragTypes') +const siteTags = require('./constants/siteTags') const appStoreRenderer = require('./stores/appStoreRenderer') const {getCurrentWindowId} = require('../app/renderer/currentWindow') const {ESC} = require('../app/common/constants/keyCodes.js') @@ -137,7 +139,11 @@ module.exports.prepareBookmarkDataFromCompatible = (dataTransfer) => { if (!bookmark) { const dragData = dndData.getDragData(dataTransfer, dragTypes.TAB) if (dragData) { - windowActions.onFrameBookmark(dragData.get('tabId')) + bookmark = Immutable.fromJS({ + location: dragData.get('location'), + title: dragData.get('title'), + type: siteTags.BOOKMARK + }) } } return bookmark