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

Commit

Permalink
keep pinned topsite position after new site visit
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Jan 3, 2018
1 parent fdd7e38 commit ae0a1a4
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions app/browser/api/topSites.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const getTopSiteData = () => {

if (sites.size < 18) {
const preDefined = staticData
// TODO: this doesn't work properly
.filter((site) => {
return !isIgnored(state, site.get('key'))
})
Expand All @@ -131,24 +132,24 @@ const getTopSiteData = () => {
sites = sites.concat(preDefined)
}

sites = removeDuplicateDomains(sites)

// TODO: newer sites should skip pinned position
let gridSites = aboutNewTabState.getPinnedTopSites(state)

sites.forEach((site) => {
const siteExists = gridSites.some(pinnedSite => {
if (!pinnedSite) {
return false
}
return site.get('key') === pinnedSite.get('key')
})

if (!siteExists) {
gridSites.unshift(site)
const pinnedTopSites = aboutNewTabState.getPinnedTopSites(state)
let gridSites = pinnedTopSites.map(pinned => {
// topsites are populated once user visit a new site.
// pinning a site to a given index is a user decision
// and should be taken as priority. If there's an empty
// space we just fill it with visited sites. Otherwise
// fallback to the pinned item.
if (!pinned) {
const firstSite = sites.first()
sites = sites.shift()
return firstSite
}
return pinned
})

gridSites = gridSites.filter(site => site != null)
gridSites = removeDuplicateDomains(gridSites)

appActions.topSiteDataAvailable(gridSites)
}

Expand Down

0 comments on commit ae0a1a4

Please sign in to comment.