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 #11768 from brave/ca--11632
Browse files Browse the repository at this point in the history
fix bad tab page preview while closing tabs
  • Loading branch information
bbondy committed Nov 8, 2017
1 parent dc8c07f commit 3b9daa1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
12 changes: 0 additions & 12 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,6 @@ const windowActions = {
})
},

/**
* Dispatches a message to the store to set the tab page index being previewed.
*
* @param {number} previewTabPageIndex - The tab page index to preview
*/
setPreviewTabPageIndex: function (previewTabPageIndex) {
dispatch({
actionType: windowConstants.WINDOW_SET_PREVIEW_TAB_PAGE_INDEX,
previewTabPageIndex
})
},

/**
* Dispatches a message to the store to set the tab page index.
*
Expand Down
27 changes: 3 additions & 24 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const {getSetting} = require('../settings')
const {isIntermediateAboutPage} = require('../lib/appUrlUtil')
const urlParse = require('../../app/common/urlParse')

let tabPageHoverTimeout
let tabHoverTimeout = null

const comparatorByKeyAsc = (a, b) => a.get('key') > b.get('key')
Expand Down Expand Up @@ -560,36 +559,16 @@ const getPreviewFrameKey = (state) => {
return state.get('previewFrameKey')
}

const setPreviewTabPageIndex = (state, index, immediate = false) => {
clearTimeout(tabPageHoverTimeout)
const setPreviewTabPageIndex = (state, index) => {
const previewTabs = getSetting(settings.SHOW_TAB_PREVIEWS)
const isActive = state.getIn(['ui', 'tabs', 'tabPageIndex']) === index
const hoverTabPageIndex = state.getIn(['ui', 'tabs', 'hoverTabPageIndex'])
let newTabPageIndex = index

if (!previewTabs || state.getIn(['ui', 'tabs', 'hoverTabPageIndex']) !== index || isActive) {
if (!previewTabs || hoverTabPageIndex !== index || isActive) {
newTabPageIndex = null
}

if (!immediate) {
// if there is an existing preview tab page index then we're already in preview mode
// we use actions here because that is the only way to delay updating the state
const previewMode = state.getIn(['ui', 'tabs', 'previewTabPageIndex']) != null
if (previewMode && newTabPageIndex == null) {
// add a small delay when we are clearing the preview frame key so we don't lose
// previewMode if the user mouses over another tab - see below
tabPageHoverTimeout = setTimeout(windowActions.setPreviewTabPageIndex.bind(null, null), 200)
return state
}

if (!previewMode) {
// If user isn't in previewMode so we add a bit of delay to avoid tab from flashing out
// as reported here: https://github.com/brave/browser-laptop/issues/1434
// using an action here because that is the only way we can do a delayed state update
tabPageHoverTimeout = setTimeout(windowActions.setPreviewTabPageIndex.bind(null, newTabPageIndex), 200)
return state
}
}

return state.setIn(['ui', 'tabs', 'previewTabPageIndex'], newTabPageIndex)
}

Expand Down
2 changes: 1 addition & 1 deletion js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const doAction = (action) => {
windowState = frameStateUtil.setPreviewFrameKey(windowState, action.frameKey, true)
break
case windowConstants.WINDOW_SET_PREVIEW_TAB_PAGE_INDEX:
windowState = frameStateUtil.setPreviewTabPageIndex(windowState, action.previewTabPageIndex, true)
windowState = frameStateUtil.setPreviewTabPageIndex(windowState, action.previewTabPageIndex)
break
case windowConstants.WINDOW_SET_TAB_PAGE_INDEX:
if (action.index != null) {
Expand Down

0 comments on commit 3b9daa1

Please sign in to comment.