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

Commit

Permalink
fix deleting history entry from History menu
Browse files Browse the repository at this point in the history
fix #10328

Test Plan:
open a tab, go to any site
close the tab. notice that the site appears in the History menu.
go to about:history and delete the visited site.
it should disappear from the History menu
  • Loading branch information
diracdeltas committed Aug 8, 2017
1 parent 3b83297 commit a8650d4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
11 changes: 9 additions & 2 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,15 @@ const doAction = (state, action) => {
}
case windowConstants.WINDOW_CLEAR_CLOSED_FRAMES:
{
closedFrames = new Immutable.OrderedMap()
lastClosedUrl = null
if (!action.location) {
closedFrames = new Immutable.OrderedMap()
lastClosedUrl = null
} else {
closedFrames = closedFrames.delete(action.location)
if (lastClosedUrl === action.location) {
lastClosedUrl = null
}
}
updateRecentlyClosedMenuItems(state)
break
}
Expand Down
19 changes: 19 additions & 0 deletions app/browser/reducers/historyReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const Immutable = require('immutable')
const BrowserWindow = require('electron').BrowserWindow

// State
const historyState = require('../../common/state/historyState')
Expand All @@ -11,13 +12,28 @@ const aboutHistoryState = require('../../common/state/aboutHistoryState')
// Constants
const appConstants = require('../../../js/constants/appConstants')
const {STATE_SITES} = require('../../../js/constants/stateConstants')
const messages = require('../../../js/constants/messages')

// Utils
const {makeImmutable} = require('../../common/state/immutableUtil')
const syncUtil = require('../../../js/state/syncUtil')
const filtering = require('../../filtering')
const {calculateTopSites} = require('../api/topSites')

/**
* Helper to pass message to windows to clear closed frames
* @param {Array.BrowserWindow} windows
* @param {string} historyKey
*/
const clearClosedFrames = (windows, historyKey) => {
windows.forEach((wnd) => {
if (!wnd.webContents) {
return
}
wnd.webContents.send(messages.CLEAR_CLOSED_FRAMES, historyKey.split('|')[0])
})
}

const historyReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
switch (action.get('actionType')) {
Expand Down Expand Up @@ -62,15 +78,18 @@ const historyReducer = (state, action, immutableAction) => {
if (historyKey == null) {
break
}
const windows = BrowserWindow.getAllWindows()

if (Immutable.List.isList(historyKey)) {
action.get('historyKey', Immutable.List()).forEach((key) => {
state = historyState.removeSite(state, key)
clearClosedFrames(windows, key)
// TODO: Implement Sync history site removal
// state = syncUtil.updateObjectCache(state, action.get('siteDetail'), STATE_SITES.HISTORY_SITES)
})
} else {
state = historyState.removeSite(state, historyKey)
clearClosedFrames(windows, historyKey)
// TODO: Implement Sync history site removal
// state = syncUtil.updateObjectCache(state, action.get('siteDetail'), STATE_SITES.HISTORY_SITES)
}
Expand Down
6 changes: 4 additions & 2 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ const windowActions = {

/**
* Dispatches a message to the store to clear closed frames
* @param {string=} location - only clear frames with this location
*/
clearClosedFrames: function () {
clearClosedFrames: function (location) {
dispatch({
actionType: windowConstants.WINDOW_CLEAR_CLOSED_FRAMES
actionType: windowConstants.WINDOW_CLEAR_CLOSED_FRAMES,
location
})
},

Expand Down
4 changes: 2 additions & 2 deletions js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ ipc.on(messages.APP_STATE_CHANGE, (e, action) => {
: appStoreRenderer.state = Immutable.fromJS(action.state)
})

ipc.on(messages.CLEAR_CLOSED_FRAMES, () => {
windowActions.clearClosedFrames()
ipc.on(messages.CLEAR_CLOSED_FRAMES, (e, location) => {
windowActions.clearClosedFrames(location)
})

window.addEventListener('beforeunload', function (e) {
Expand Down
7 changes: 6 additions & 1 deletion js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,12 @@ const doAction = (action) => {
}
break
case windowConstants.WINDOW_CLEAR_CLOSED_FRAMES:
windowState = windowState.set('closedFrames', new Immutable.List())
if (!action.location) {
windowState = windowState.set('closedFrames', new Immutable.List())
} else {
windowState = windowState.set('closedFrames',
windowState.get('closedFrames').filterNot((frame) => frame.get('location') === action.location))
}
break
case windowConstants.WINDOW_SET_PREVIEW_FRAME:
windowState = frameStateUtil.setPreviewFrameKey(windowState, action.frameKey, true)
Expand Down

0 comments on commit a8650d4

Please sign in to comment.