diff --git a/app/sessionStore.js b/app/sessionStore.js index c4d12030cba..ef854bf6fd0 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -36,20 +36,6 @@ const getSetting = require('../js/settings').getSetting const promisify = require('../js/lib/promisify') const sessionStorageName = `session-store-${sessionStorageVersion}` -const getTopSiteMap = () => { - if (Array.isArray(topSites) && topSites.length) { - let siteMap = {} - let order = 0 - topSites.forEach((site) => { - let key = siteUtil.getSiteKey(Immutable.fromJS(site)) - site.order = order++ - siteMap[key] = site - }) - return siteMap - } - return {} -} - const getStoragePath = () => { return path.join(app.getPath('userData'), sessionStorageName) } @@ -524,7 +510,7 @@ module.exports.defaultAppState = () => { sync: { lastFetchTimestamp: 0 }, - sites: getTopSiteMap(), + sites: {}, tabs: [], windows: [], extensions: {}, diff --git a/js/data/newTabData.js b/js/data/newTabData.js index 38fe8cfc7fc..a2f5234dfc1 100644 --- a/js/data/newTabData.js +++ b/js/data/newTabData.js @@ -80,3 +80,5 @@ module.exports.topSites = [ "title": "Brave Browser: Fast AdBlock – Apps para Android no Google Play" } ] + +module.exports.topSiteLocations = module.exports.topSites.map((site) => site.location) diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 4a51697c477..8767a6d9435 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -34,6 +34,7 @@ const Filtering = require('../../app/filtering') const basicAuth = require('../../app/browser/basicAuth') const webtorrent = require('../../app/browser/webtorrent') const windows = require('../../app/browser/windows') +const { topSiteLocations } = require('../data/newTabData') const assert = require('assert') // state helpers @@ -421,9 +422,20 @@ const handleAppAction = (action) => { appState = appState.set('passwords', new Immutable.List()) break case appConstants.APP_CHANGE_NEW_TAB_DETAIL: + // If a site is pinned, add it to the sites if it isn't already there. + if (action.newTabPageDetail) { + let pinnedTopSites = action.newTabPageDetail.get('pinnedTopSites') + if (pinnedTopSites) { + pinnedTopSites.forEach((site) => { + if (site && topSiteLocations.includes(site.get('location'))) { + appState = appState.set('sites', siteUtil.addSite(appState.get('sites'), site)) + } + }) + } + } appState = aboutNewTabState.mergeDetails(appState, action) if (action.refresh) { - appState = aboutNewTabState.setSites(appState, action) + appState = aboutNewTabState.setSites(appState) } break case appConstants.APP_POPULATE_HISTORY: