Skip to content

Commit

Permalink
Fixes Other bookmarks not being usable
Browse files Browse the repository at this point in the history
Resolves brave#10157
Resolves brave#4202

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Aug 21, 2017
1 parent eced5c4 commit e021002
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/common/state/bookmarkFoldersState.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const bookmarkFoldersState = {
title: folderDetails.get('title'),
folderId: ~~key,
key: key.toString(),
parentFolderId: ~~folderDetails.get('parentFolderId', 0),
parentFolderId: Number(folderDetails.get('parentFolderId', 0)),
partitionNumber: ~~folderDetails.get('partitionNumber', 0),
objectId: folderDetails.get('objectId', null),
type: siteTags.BOOKMARK_FOLDER,
Expand All @@ -83,7 +83,7 @@ const bookmarkFoldersState = {

const newFolder = oldFolder.merge(makeImmutable({
title: folderDetails.get('title'),
parentFolderId: ~~folderDetails.get('parentFolderId', 0)
parentFolderId: Number(folderDetails.get('parentFolderId', 0))
}))

if (oldFolder.get('parentFolderId') !== newFolder.get('parentFolderId')) {
Expand All @@ -108,7 +108,7 @@ const bookmarkFoldersState = {
syncActions.removeSites([folder.toJS()])
}

folders.filter(folder => folder.get('parentFolderId') === ~~folderKey)
folders.filter(folder => folder.get('parentFolderId') === Number(folderKey))
.map(folder => {
state = bookmarksState.removeBookmarksByParentId(state, folder.get('folderId'))
state = bookmarkFoldersState.removeFolder(state, folder.get('folderId'))
Expand Down Expand Up @@ -168,7 +168,7 @@ const bookmarkFoldersState = {
: destinationItem.get('folderId')

state = bookmarkOrderCache.removeCacheKey(state, folder.get('parentFolderId'), folderKey)
folder = folder.set('parentFolderId', ~~parentFolderId)
folder = folder.set('parentFolderId', Number(parentFolderId))
const newKey = bookmarkFoldersUtil.getKey(folder)
state = state.deleteIn([STATE_SITES.BOOKMARK_FOLDERS, folderKey])
state = bookmarkOrderCache.addFolderToCache(state, folder.get('parentFolderId'), newKey)
Expand Down
12 changes: 8 additions & 4 deletions app/common/state/bookmarksState.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const bookmarksState = {
let bookmark = makeImmutable({
title: bookmarkDetail.get('title', ''),
location: bookmarkDetail.get('location'),
parentFolderId: ~~bookmarkDetail.get('parentFolderId', 0),
parentFolderId: Number(bookmarkDetail.get('parentFolderId', 0)),
partitionNumber: ~~dataItem.get('partitionNumber', 0),
objectId: bookmarkDetail.get('objectId', null),
favicon: dataItem.get('favicon'),
Expand Down Expand Up @@ -210,7 +210,7 @@ const bookmarksState = {
const removedBookmarks = []
const bookmarks = bookmarksState.getBookmarks(state)
.filter(bookmark => {
if (bookmark.get('parentFolderId') !== ~~parentFolderId) {
if (bookmark.get('parentFolderId') !== Number(parentFolderId)) {
return true
}
if (syncEnabled) {
Expand Down Expand Up @@ -265,12 +265,16 @@ const bookmarksState = {

// move bookmark into a new folder
if (moveIntoParent || destinationItem.get('parentFolderId') !== bookmark.get('parentFolderId')) {
const parentFolderId = destinationItem.get('type') === siteTags.BOOKMARK
let parentFolderId = destinationItem.get('type') === siteTags.BOOKMARK
? destinationItem.get('parentFolderId')
: destinationItem.get('folderId')

if (parentFolderId == null) {
parentFolderId = destinationKey
}

state = bookmarkOrderCache.removeCacheKey(state, bookmark.get('parentFolderId'), bookmarkKey)
bookmark = bookmark.set('parentFolderId', ~~parentFolderId)
bookmark = bookmark.set('parentFolderId', Number(parentFolderId))
const newKey = bookmarkUtil.getKey(bookmark)
state = state.deleteIn([STATE_SITES.BOOKMARKS, bookmarkKey])
state = bookmarkOrderCache.addBookmarkToCache(state, bookmark.get('parentFolderId'), newKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class AddEditBookmarkFolderForm extends React.Component {

onParentFolderChange (e) {
this.setState({
parentFolderId: ~~e.target.value
parentFolderId: Number(e.target.value)
})
}

Expand Down Expand Up @@ -185,6 +185,7 @@ class AddEditBookmarkFolderForm extends React.Component {
defaultValue={this.state.parentFolderId}
onChange={this.onParentFolderChange} >
<option value='0' data-l10n-id='bookmarksToolbar' />
<option value='-1' data-l10n-id='otherBookmarks' />
{
this.props.folders.map((folder) => <option value={folder.folderId}>{folder.label}</option>)
}
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/bookmarks/addEditBookmarkForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AddEditBookmarkForm extends React.Component {

onParentFolderChange (e) {
this.setState({
parentFolderId: ~~e.target.value
parentFolderId: Number(e.target.value)
})
}

Expand Down Expand Up @@ -221,6 +221,7 @@ class AddEditBookmarkForm extends React.Component {
defaultValue={this.state.parentFolderId}
onChange={this.onParentFolderChange} >
<option value='0' data-l10n-id='bookmarksToolbar' />
<option value='-1' data-l10n-id='otherBookmarks' />
{
this.props.folders.map((folder) => <option value={folder.folderId}>{folder.label}</option>)
}
Expand Down

0 comments on commit e021002

Please sign in to comment.