Skip to content

Commit

Permalink
Fix bookmark drag and drop after order cache changes
Browse files Browse the repository at this point in the history
Fix brave#11040

Auditors: @NejcZdovc
  • Loading branch information
bbondy authored and syuan100 committed Nov 9, 2017
1 parent 74e3ed8 commit a00fde7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/common/lib/bookmarkUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@ const getDNDBookmarkData = (state, bookmarkKey) => {
}

let oldBookmarks
let oldBookmarkOrderCache
let oldFolders
let lastValue
let lastWidth
const getToolbarBookmarks = (state) => {
const windowWidth = window.innerWidth
const allBookmarks = bookmarksState.getBookmarks(state)
const bookmarkOrderCache = bookmarksState.getBookmarkOrder(state)
const allFolders = bookmarkFoldersState.getFolders(state)
if (
allBookmarks === oldBookmarks &&
bookmarkOrderCache === oldBookmarkOrderCache &&
allFolders === oldFolders &&
lastWidth === windowWidth &&
lastValue
Expand All @@ -85,6 +88,7 @@ const getToolbarBookmarks = (state) => {
}

oldBookmarks = allBookmarks
oldBookmarkOrderCache = bookmarkOrderCache
oldFolders = allFolders
lastWidth = windowWidth

Expand Down
4 changes: 4 additions & 0 deletions app/common/state/bookmarksState.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const bookmarksState = {
return state.getIn([STATE_SITES.BOOKMARKS, key], Immutable.Map())
},

getBookmarkOrder: (state) => {
return state.getIn(STATE_SITES.BOOKMARK_ORDER_PATH)
},

/**
* Use this function if you only have a key and don't know if key is for folder or regular bookmark
* @param state
Expand Down
3 changes: 1 addition & 2 deletions app/renderer/components/bookmarks/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class BookmarksToolbar extends React.Component {
if (droppedOn.selectedRef) {
const isRightSide = !dnd.isLeftSide(ReactDOM.findDOMNode(droppedOn.selectedRef), e.clientX)
const droppedOnKey = droppedOn.selectedRef.props.bookmarkKey
const isDestinationParent = droppedOn.selectedRef.props.isFolder && droppedOn && droppedOn.isDroppedOn

const isDestinationParent = droppedOn.selectedRef.state.isFolder && droppedOn && droppedOn.isDroppedOn
if (bookmark.get('type') === siteTags.BOOKMARK_FOLDER) {
appActions.moveBookmarkFolder(bookmark.get('key'), droppedOnKey, isRightSide, isDestinationParent)
} else {
Expand Down
3 changes: 2 additions & 1 deletion js/constants/stateConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const STATE_SITES = {
BOOKMARKS: 'bookmarks',
BOOKMARK_FOLDERS: 'bookmarkFolders',
HISTORY_SITES: 'historySites',
PINNED_SITES: 'pinnedSites'
PINNED_SITES: 'pinnedSites',
BOOKMARK_ORDER_PATH: ['cache', 'bookmarkOrder']
}

module.exports = {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/app/common/state/bookmarksStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const stateWithData = Immutable.fromJS({
})

describe('bookmarkState unit test', function () {
describe('getBookmarkOrder', function () {
it('resturns order state', function () {
assert.deepEqual(bookmarksState.getBookmarkOrder(stateWithData), stateWithData.getIn(['cache', 'bookmarkOrder']))
})
})
describe('getBookmarksByParentId', function () {
it('null case', function () {
const result = bookmarksState.getBookmarksByParentId(stateWithData)
Expand Down

0 comments on commit a00fde7

Please sign in to comment.