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

Commit

Permalink
fixes double delete
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Sep 11, 2017
1 parent b1d4a73 commit 5198210
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 22 additions & 4 deletions app/browser/reducers/urlBarSuggestionsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const {makeImmutable} = require('../../common/state/immutableUtil')
const tabState = require('../../common/state/tabState')
const historyState = require('../../common/state/historyState')
const bookmarksState = require('../../common/state/bookmarksState')
const historyUtil = require('../../common/lib/historyUtil')
const bookmarkLocationCache = require('../../common/cache/bookmarkLocationCache')

const urlBarSuggestionsReducer = (state, action) => {
switch (action.actionType) {
Expand All @@ -37,10 +39,18 @@ const urlBarSuggestionsReducer = (state, action) => {
if (Array.isArray(bookmarkKey)) {
data = Immutable.List()
bookmarkKey.forEach((key) => {
data = data.push(bookmarksState.getBookmark(state, key))
const bookmark = bookmarksState.getBookmark(state, key)
const historyKey = historyUtil.getKey(bookmark)
if (!historyState.hasSite(state, historyKey)) {
data = data.push(bookmark)
}
})
} else {
data = bookmarksState.getBookmark(state, bookmarkKey)
const bookmark = bookmarksState.getBookmark(state, bookmarkKey)
const historyKey = historyUtil.getKey(bookmark)
if (!historyState.hasSite(state, historyKey)) {
data = bookmark
}
}

if (data != null) {
Expand All @@ -60,10 +70,18 @@ const urlBarSuggestionsReducer = (state, action) => {
if (Array.isArray(historyKey)) {
data = Immutable.List()
historyKey.map((key) => {
data = data.push(historyState.getSite(state, key))
const site = historyState.getSite(state, key)
const bookmarkKey = bookmarkLocationCache.getCacheKey(state, site.get('location'))
if (bookmarkKey.size === 0) {
data = data.push(site)
}
})
} else {
data = historyState.getSite(state, historyKey)
const site = historyState.getSite(state, historyKey)
const bookmarkKey = bookmarkLocationCache.getCacheKey(state, site.get('location'))
if (bookmarkKey.size === 0) {
data = site
}
}

if (data != null) {
Expand Down
5 changes: 5 additions & 0 deletions app/common/state/historyState.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const historyState = {
return state.getIn([STATE_SITES.HISTORY_SITES, key], Immutable.Map())
},

hasSite: (state, key) => {
state = validateState(state)
return state.hasIn([STATE_SITES.HISTORY_SITES, key], Immutable.Map())
},

addSite: (state, siteDetail) => {
let sites = historyState.getSites(state)
let siteKey = historyUtil.getKey(siteDetail)
Expand Down

0 comments on commit 5198210

Please sign in to comment.