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

Commit

Permalink
Merge pull request #5593 from bsclifton/topsites
Browse files Browse the repository at this point in the history
about:newtab - Update the unpinned site list to only show one result per domain
  • Loading branch information
bbondy committed Nov 14, 2016
2 parents e0601d8 + fb177d1 commit 8246d95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 16 additions & 4 deletions app/common/state/aboutNewTabState.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@ const sortCountDescending = (left, right) => {
if (left.get('count') > right.get('count')) return -1
return 0
}

const removeDuplicateDomains = (list) => {
const siteDomains = new Set()
return list.filter((site) => {
try {
const hostname = require('url').parse(site.get('location')).hostname
if (!siteDomains.has(hostname)) {
siteDomains.add(hostname)
return true
}
} catch (e) {
console.log('Error parsing hostname: ', e)
}
return false
})
}
/**
* topSites are defined by users. Pinned sites are attached to their positions
* in the grid, and the non pinned indexes are populated with newly accessed sites
Expand All @@ -43,9 +57,7 @@ const getTopSites = (state) => {

// Filter out pinned and ignored sites
let unpinnedSites = sites.filter((site) => !(isPinned(state, site) || isIgnored(state, site)))

// TODO(bsclifton): de-dupe here
// ..
unpinnedSites = removeDuplicateDomains(unpinnedSites)

// Merge the pinned and unpinned lists together
// Pinned items have priority because the position is important
Expand Down
3 changes: 0 additions & 3 deletions js/about/newtab.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ class NewTabPage extends React.Component {
const currentPositionIndex = gridSites.indexOf(currentPosition)
const pinnedTopSites = this.pinnedTopSites.splice(currentPositionIndex, 1, null)
newTabState.pinnedTopSites = pinnedTopSites

// TODO: ignoring an item sometimes was removing a pin for a different site
// I think the merge is not working properly.
}

newTabState.ignoredTopSites = this.ignoredTopSites.push(siteProps)
Expand Down

0 comments on commit 8246d95

Please sign in to comment.