From 4ae810be2fff2e2f89f5049875df5b6e0cbc1c9d Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Sun, 13 Nov 2016 22:22:52 -0700 Subject: [PATCH] about:newtab - Update the unpinned site list to only show one result per domain. Fixes https://github.com/brave/browser-laptop/issues/5565 Auditors: @bbondy UPDATE: - Updated unique check from array => set Auditors: @bbondy --- app/common/state/aboutNewTabState.js | 20 ++++++++++++++++---- js/about/newtab.js | 3 --- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/common/state/aboutNewTabState.js b/app/common/state/aboutNewTabState.js index a3fe3ac6d37..2495f1b5bcb 100644 --- a/app/common/state/aboutNewTabState.js +++ b/app/common/state/aboutNewTabState.js @@ -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 @@ -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 diff --git a/js/about/newtab.js b/js/about/newtab.js index 97cb2a82c25..17a502d2e86 100644 --- a/js/about/newtab.js +++ b/js/about/newtab.js @@ -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)