diff --git a/app/browser/windows.js b/app/browser/windows.js index 028aee44eed..4658c990753 100644 --- a/app/browser/windows.js +++ b/app/browser/windows.js @@ -69,8 +69,7 @@ const updatePinnedTabs = (win) => { const appStore = require('../../js/stores/appStore') const state = appStore.getState() const windowId = win.id - const pinnedSites = state.get('sites').toList().filter((site) => - site.get('tags').includes(siteTags.PINNED)).map(site => getPinnedSiteProps(site)) + const pinnedSites = pinnedSiteState.getSites(state).map(site => getPinnedSiteProps(site)) const pinnedTabs = getPinnedTabsByWindowId(state, windowId) pinnedSites.filter((site) => diff --git a/app/common/state/pinnedSitesState.js b/app/common/state/pinnedSitesState.js new file mode 100644 index 00000000000..4652e4ea642 --- /dev/null +++ b/app/common/state/pinnedSitesState.js @@ -0,0 +1,18 @@ +const assert = require('assert') +const {makeImmutable, isMap, isList} = require('./immutableUtil') + +const validateState = function (state) { + state = makeImmutable(state) + assert.ok(isMap(state), 'state must be an Immutable.Map') + assert.ok(isList(state.get('pinnedSites')), 'state must contain an Immutable.List of pinnedSites') + return state +} + +const pinnedSiteState = { + getSites: (state) => { + state = validateState(state) + return state.get('pinnedSites') + } +} + +module.exports = pinnedSiteState diff --git a/app/common/state/tabState.js b/app/common/state/tabState.js index bb54171b2d1..6866fd3f857 100644 --- a/app/common/state/tabState.js +++ b/app/common/state/tabState.js @@ -239,6 +239,12 @@ const tabState = { return state.get('tabs').filter((tab) => !!tab.get('pinned')) }, + isTabPinned: (state, tabId) => { + state = validateState(state) + tabId = validateId('tabId', tabId) + return !!state.getIn(['tabs', 'pinned']) + }, + getNonPinnedTabs: (state) => { state = validateState(state) return state.get('tabs').filter((tab) => !tab.get('pinned')) diff --git a/app/renderer/components/tabs/content/closeTabIcon.js b/app/renderer/components/tabs/content/closeTabIcon.js index 577350c99cc..34bc48fa5bb 100644 --- a/app/renderer/components/tabs/content/closeTabIcon.js +++ b/app/renderer/components/tabs/content/closeTabIcon.js @@ -50,8 +50,9 @@ class CloseTabIcon extends React.Component { mergeProps (state, ownProps) { const currentWindow = state.get('currentWindow') const frameKey = ownProps.frameKey - const isPinnedTab = frameStateUtil.isPinned(currentWindow, frameKey) const frame = frameStateUtil.getFrameByKey(currentWindow, frameKey) || Immutable.Map() + const tabId = frame.get('tabId', tabState.TAB_ID_NONE) + const isPinnedTab = tabState.isTabPinned(state, tabId) const props = {} // used in renderer @@ -64,7 +65,7 @@ class CloseTabIcon extends React.Component { // used in functions props.frameKey = frameKey props.fixTabWidth = ownProps.fixTabWidth - props.tabId = frame.get('tabId', tabState.TAB_ID_NONE) + props.tabId = tabId props.hasFrame = !frame.isEmpty() return props diff --git a/app/renderer/components/tabs/content/favIcon.js b/app/renderer/components/tabs/content/favIcon.js index 354088de059..181300b4fb7 100644 --- a/app/renderer/components/tabs/content/favIcon.js +++ b/app/renderer/components/tabs/content/favIcon.js @@ -12,6 +12,7 @@ const TabIcon = require('./tabIcon') // State const tabContentState = require('../../../../common/state/tabContentState') +const tabState = require('../../../../common/state/tabState') // Utils const frameStateUtil = require('../../../../../js/state/frameStateUtil') @@ -34,12 +35,13 @@ class Favicon extends React.Component { const frameKey = ownProps.frameKey const frame = frameStateUtil.getFrameByKey(currentWindow, frameKey) || Immutable.Map() const isTabLoading = tabContentState.isTabLoading(currentWindow, frameKey) + const tabId = frame.get('tabId', tabState.TAB_ID_NONE) const props = {} // used in renderer props.isTabLoading = isTabLoading props.favicon = !isTabLoading && frame.get('icon') - props.isPinnedTab = frameStateUtil.isPinned(currentWindow, frameKey) + props.isPinnedTab = tabState.isTabPinned(state, tabId) props.tabIconColor = tabContentState.getTabIconColor(currentWindow, frameKey) props.isNarrowestView = tabContentState.isNarrowestView(currentWindow, frameKey) diff --git a/app/renderer/components/tabs/tab.js b/app/renderer/components/tabs/tab.js index 324f9e084d1..f6aaad24667 100644 --- a/app/renderer/components/tabs/tab.js +++ b/app/renderer/components/tabs/tab.js @@ -234,7 +234,7 @@ class Tab extends React.Component { props.notificationBarActive = notificationBarActive props.isActive = frameStateUtil.isFrameKeyActive(currentWindow, props.frameKey) props.tabWidth = currentWindow.getIn(['ui', 'tabs', 'fixTabWidth']) - props.isPinnedTab = frameStateUtil.isPinned(currentWindow, props.frameKey) + props.isPinnedTab = frameStateUtil.isPinned(currentWindow, props.frameKey) // TODO change to app state lookup props.canPlayAudio = tabContentState.canPlayAudio(currentWindow, props.frameKey) props.themeColor = tabContentState.getThemeColor(currentWindow, props.frameKey) props.isNarrowView = tabContentState.isNarrowView(currentWindow, props.frameKey) diff --git a/app/sessionStore.js b/app/sessionStore.js index c66b0b1687c..d047b870a01 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -491,6 +491,8 @@ module.exports.runPreMigrations = (data) => { } } + // TODO add sites migration into new types + return data } @@ -626,7 +628,8 @@ module.exports.defaultAppState = () => { pendingRecords: {} }, locationSiteKeysCache: undefined, - sites: getTopSiteMap(), + sites: getTopSiteMap(), // TODO remove + pinnedSites: [], tabs: [], windows: [], extensions: {}, diff --git a/js/constants/siteTags.js b/js/constants/siteTags.js index 4a86ba2fa59..b6af31c8184 100644 --- a/js/constants/siteTags.js +++ b/js/constants/siteTags.js @@ -4,13 +4,13 @@ const mapValuesByKeys = require('../lib/functional').mapValuesByKeys +// TODO remove + const _ = null const siteTags = { DEFAULT: _, BOOKMARK: _, - BOOKMARK_FOLDER: _, - PINNED: _, - READING_LIST: _ + BOOKMARK_FOLDER: _ } module.exports = mapValuesByKeys(siteTags) diff --git a/js/state/siteUtil.js b/js/state/siteUtil.js index 5320b15a9c7..6e3d382c0f9 100644 --- a/js/state/siteUtil.js +++ b/js/state/siteUtil.js @@ -13,6 +13,8 @@ const {makeImmutable} = require('../../app/common/state/immutableUtil') const defaultTags = new Immutable.List([siteTags.DEFAULT]) +// TODO depricate!! + const isBookmark = (tags) => { if (!tags) { return false @@ -28,14 +30,6 @@ const isBookmarkFolder = (tags) => { (tags && typeof tags !== 'string' && tags.includes(siteTags.BOOKMARK_FOLDER)) } -const isPinnedTab = (tags) => { - if (!tags) { - return false - } - return tags.includes(siteTags.PINNED) -} -module.exports.isPinnedTab = isPinnedTab - const reorderSite = (sites, order) => { sites = sites.map((site) => { const siteOrder = site.get('order') @@ -402,20 +396,11 @@ module.exports.removeSite = function (state, siteDetail, tag, reorder = true, sy return state } if (isBookmark(tag)) { - if (isPinnedTab(tags)) { - const tags = site.get('tags').filterNot((tag) => tag === siteTags.BOOKMARK) - site = site.set('tags', tags) - return state.setIn(stateKey, site) - } if (state.get('sites').size && reorder) { const order = state.getIn(stateKey.concat(['order'])) state = state.set('sites', reorderSite(state.get('sites'), order)) } return state.deleteIn(['sites', key]) - } else if (isPinnedTab(tag)) { - const tags = site.get('tags').filterNot((tag) => tag === siteTags.PINNED) - site = site.set('tags', tags) - return state.setIn(stateKey, site) } else { site = site.set('lastAccessedTime', undefined) return state.setIn(stateKey, site) diff --git a/test/unit/state/siteUtilTest.js b/test/unit/state/siteUtilTest.js index f45653f3ca0..ddff893b0a5 100644 --- a/test/unit/state/siteUtilTest.js +++ b/test/unit/state/siteUtilTest.js @@ -1683,20 +1683,4 @@ describe('siteUtil', function () { assert.strictEqual(siteUtil.getOrigin('http://http/test'), 'http://http') }) }) - describe('isPinnedTab', function () { - it('detects pinned tab site', function () { - assert.strictEqual(siteUtil.isPinnedTab(siteTags.PINNED), true) - assert.strictEqual(siteUtil.isPinnedTab([siteTags.PINNED]), true) - }) - it('detects not pinned for no site tags', function () { - assert.strictEqual(siteUtil.isPinnedTab([]), false) - }) - it('detects not pinned for site tags which are not PINNED', function () { - assert.strictEqual(siteUtil.isPinnedTab(siteTags.BOOKMARK), false) - assert.strictEqual(siteUtil.isPinnedTab([siteTags.BOOKMARK]), false) - }) - it('detects pinned when bookmarked and pinned', function () { - assert.strictEqual(siteUtil.isPinnedTab([siteTags.PINNED, siteTags.BOOKMARK]), true) - }) - }) })