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

fix bad tab page preview while closing tabs #11768

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,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 @@ -21,7 +21,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 @@ -584,36 +583,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) => {
}
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