From a8650d4bfd36136223e492f88d0ef874f3d70b1b Mon Sep 17 00:00:00 2001 From: yan Date: Tue, 8 Aug 2017 00:16:58 +0000 Subject: [PATCH] fix deleting history entry from History menu fix https://github.com/brave/browser-laptop/issues/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 --- app/browser/menu.js | 11 +++++++++-- app/browser/reducers/historyReducer.js | 19 +++++++++++++++++++ js/actions/windowActions.js | 6 ++++-- js/entry.js | 4 ++-- js/stores/windowStore.js | 7 ++++++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/app/browser/menu.js b/app/browser/menu.js index b83a907d51d..b3d8e62a8e2 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -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 } diff --git a/app/browser/reducers/historyReducer.js b/app/browser/reducers/historyReducer.js index 67579796d79..57ca841c711 100644 --- a/app/browser/reducers/historyReducer.js +++ b/app/browser/reducers/historyReducer.js @@ -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') @@ -11,6 +12,7 @@ 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') @@ -18,6 +20,20 @@ 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')) { @@ -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) } diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index db4c40e04e6..58b5d5f1139 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -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 }) }, diff --git a/js/entry.js b/js/entry.js index 12e060b627b..ec4b40a8768 100644 --- a/js/entry.js +++ b/js/entry.js @@ -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) { diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 79d79c9fa41..ab59c2bd9b9 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -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)