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

Commit

Permalink
Update tab page index based on active state
Browse files Browse the repository at this point in the history
Fix #9922
Fix #9911
  • Loading branch information
cezaraugusto committed Jul 18, 2017
1 parent 16ae489 commit 0333c59
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
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

0 comments on commit 0333c59

Please sign in to comment.