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

Commit

Permalink
removing pinned sites
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jul 13, 2017
1 parent e87c9e7 commit 1aa22fb
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 43 deletions.
3 changes: 1 addition & 2 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
18 changes: 18 additions & 0 deletions app/common/state/pinnedSitesState.js
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions app/common/state/tabState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
5 changes: 3 additions & 2 deletions app/renderer/components/tabs/content/closeTabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/renderer/components/tabs/content/favIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ module.exports.runPreMigrations = (data) => {
}
}

// TODO add sites migration into new types

return data
}

Expand Down Expand Up @@ -626,7 +628,8 @@ module.exports.defaultAppState = () => {
pendingRecords: {}
},
locationSiteKeysCache: undefined,
sites: getTopSiteMap(),
sites: getTopSiteMap(), // TODO remove
pinnedSites: [],
tabs: [],
windows: [],
extensions: {},
Expand Down
6 changes: 3 additions & 3 deletions js/constants/siteTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 2 additions & 17 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions test/unit/state/siteUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})

0 comments on commit 1aa22fb

Please sign in to comment.