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

Commit

Permalink
siteUtils => getFolders; Use for() instead of forEach()
Browse files Browse the repository at this point in the history
Auditors: @NejcZdovc
  • Loading branch information
bsclifton authored and NejcZdovc committed Jul 11, 2017
1 parent 21e2b13 commit 40dbd62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/renderer/components/bookmarks/addEditBookmarkHanger.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AddEditBookmarkHanger extends React.Component {
props.withHomeButton = getSetting(settings.SHOW_HOME_BUTTON)
// Fake a folderId property so that the bookmark is considered a bookmark folder.
// This is ImmutableJS so it doesn't actually set a value, it just returns a new one.
props.isFolder = siteUtil.isFolder(siteDetail.set('folderId', 0))
props.isFolder = !siteDetail ? siteUtil.isFolder(siteDetail.set('folderId', 0)) : false
props.heading = bookmarkHangerHeading(editMode, props.isFolder, isAdded)
props.location = siteDetail.get('location')
props.parentFolderId = siteDetail.get('parentFolderId')
Expand Down
30 changes: 17 additions & 13 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,26 +752,30 @@ module.exports.getFolder = function (sites, folderId) {
module.exports.getFolders = function (sites, folderId, parentId, labelPrefix) {
parentId = parentId || 0
let folders = []
sites
const results = sites
.filter(site => {
return (site.get('parentFolderId', 0) === parentId && module.exports.isFolder(site))
})
.toList()
.sort(module.exports.siteSort)
.forEach((site) => {
if (site.get('folderId') === folderId) {
return
}

const label = (labelPrefix || '') + (site.get('customTitle') || site.get('title'))
folders.push({
folderId: site.get('folderId'),
parentFolderId: site.get('parentFolderId'),
label
})
const subsites = module.exports.getFolders(sites, folderId, site.get('folderId'), (label || '') + ' / ')
folders = folders.concat(subsites)
const resultSize = results.size
for (let i = 0; i < resultSize; i++) {
const site = results.get(i)
if (site.get('folderId') === folderId) {
continue
}

const label = (labelPrefix || '') + (site.get('customTitle') || site.get('title'))
folders.push({
folderId: site.get('folderId'),
parentFolderId: site.get('parentFolderId'),
label
})
const subsites = module.exports.getFolders(sites, folderId, site.get('folderId'), (label || '') + ' / ')
folders = folders.concat(subsites)
}

return folders
}

Expand Down

0 comments on commit 40dbd62

Please sign in to comment.