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

Commit

Permalink
Merge pull request #10008 from brave/tabpages--9922
Browse files Browse the repository at this point in the history
Update tabPage based on active tab state
  • Loading branch information
bsclifton authored Jul 18, 2017
2 parents 9fdd83e + 0333c59 commit 52a43e5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
12 changes: 11 additions & 1 deletion app/renderer/components/tabs/content/tabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,22 @@ class TabIcon extends ImmutableComponent {
}
})

let altProps
if (!this.props.symbol) {
altProps = {
'data-test-id': this.props['data-test-id'],
'data-test2-id': this.props['data-test2-id']
}
}

return <div
className={this.props.className}
data-test-favicon={this.props['data-test-favicon']}
onDragStart={this.props.onDragStart}
draggable={this.props.draggable}
onClick={this.props.onClick}>
onClick={this.props.onClick}
{...altProps}
>
{
this.props.symbol
? <span
Expand Down
27 changes: 16 additions & 11 deletions app/renderer/reducers/frameReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ const getLocation = (location) => {
const frameReducer = (state, action, immutableAction) => {
switch (action.actionType) {
case appConstants.APP_TAB_UPDATED:
// This case will be fired for both tab creation and tab update.
// being `tabValue` set for tab creation and `changeInfo` set for tab update
const tab = immutableAction.get('tabValue')
const changeInfo = immutableAction.get('changeInfo')
if (!tab) {
break
}
Expand Down Expand Up @@ -112,26 +115,28 @@ const frameReducer = (state, action, immutableAction) => {
}

// TODO fix race condition in Muon more info in #9000
const title = immutableAction.getIn(['tabValue', 'title'])
const title = tab.get('title')
if (title != null) {
state = state.setIn(['frames', index, 'title'], title)
}

// TODO fix race condition in Muon more info in #9000
const active = immutableAction.getIn(['tabValue', 'active'])
const hasTabInHoverState = state.getIn(['ui', 'tabs', 'hoverTabIndex'])
const active = tab.get('active')
if (active != null) {
if (active) {
state = state.set('activeFrameKey', frame.get('key'))
if (hasTabInHoverState != null) {
state = frameStateUtil.setActiveFrameKey(state, frame.get('key'))
state = frameStateUtil.setFrameLastAccessedTime(state, index)

// Handle tabPage updates and preview cancelation based on tab updated
// otherwise tabValue will fire those events each time a tab finish loading
// see bug #8429
const isNewTab = changeInfo.isEmpty()
const activeTabHasUpdated = changeInfo.get('active') != null

if (!isNewTab && activeTabHasUpdated) {
state = frameStateUtil.updateTabPageIndex(state, tabId)
state = state.set('previewFrameKey', null)
}
if (frame.getIn(['ui', 'tabs', 'hoverTabPageIndex']) == null) {
state = state.deleteIn(['ui', 'tabs', 'previewTabPageIndex'])
}
state = state.setIn(['frames', index, 'lastAccessedTime'], new Date().getTime())

state = frameStateUtil.updateTabPageIndex(state, tabId)
}
}
break
Expand Down
15 changes: 10 additions & 5 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ function getActiveFrameKey (state) {
return state.get('activeFrameKey')
}

const setActiveFrameKey = (state, frameKey) => {
return state.set('activeFrameKey', frameKey)
}

const setFrameLastAccessedTime = (state, index) => {
return state.setIn(['frames', index, 'lastAccessedTime'], new Date().getTime())
}

function getNextFrame (state) {
const activeFrameIndex = findDisplayIndexForFrameKey(state, getActiveFrameKey(state))
const index = (activeFrameIndex + 1) % state.get('frames').size
Expand Down Expand Up @@ -461,16 +469,11 @@ function isPinned (state, frameKey) {
*/
function updateTabPageIndex (state, tabId, tabsPerPage = getSetting(settings.TABS_PER_PAGE)) {
const index = getFrameTabPageIndex(state, tabId, tabsPerPage)
const isTabInHoverState = !!getHoverTabIndex(state)

if (index === -1) {
return state
}

// Do not update tabPageIndex if user is in hover mode
if (isTabInHoverState) {
return state
}
return state.setIn(['ui', 'tabs', 'tabPageIndex'], index)
}
const frameStatePath = (state, frameKey) => {
Expand Down Expand Up @@ -735,6 +738,8 @@ module.exports = {
getFrameByTabId,
getIndexByTabId,
getPartitionNumber,
setFrameLastAccessedTime,
setActiveFrameKey,
getActiveFrame,
getNextFrame,
getPreviousFrame,
Expand Down
8 changes: 4 additions & 4 deletions test/tab-components/tabPagesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const {
tabPage2,
activeWebview,
activeTab,
tabsTab
tabsTab,
closeTab
} = require('../lib/selectors')

describe('tab pages', function () {
Expand Down Expand Up @@ -59,11 +60,10 @@ describe('tab pages', function () {

it('shows the right number of tabs after closing with mouse', function * () {
const numTabsPerPage = appConfig.defaultSettings[settings.TABS_PER_PAGE]
const firstTabOfNewPageIndex = numTabsPerPage
yield this.app.client.click(newFrameButton)
.waitForElementCount(tabPage, 2)
.closeTabWithMouse()
.closeTabByIndex(firstTabOfNewPageIndex)
.moveToObject(activeTab)
.click(closeTab)
// No tab page indicator elements when 1 page
.waitForElementCount(tabPage, 0)
.waitForElementCount(tabsTabs, numTabsPerPage)
Expand Down

0 comments on commit 52a43e5

Please sign in to comment.