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 5f3c4e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 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
2 changes: 1 addition & 1 deletion js/about/newtab.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class NewTabPage extends React.Component {
}

get pinnedTopSites () {
return this.state.newTabData.getIn(['newTabDetail', 'pinnedTopSites'], Immutable.List())
return this.state.newTabData.getIn(['newTabDetail', 'pinnedTopSites'], Immutable.List()).setSize(18)
}

get ignoredTopSites () {
Expand Down

0 comments on commit 5f3c4e4

Please sign in to comment.