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

Commit 28b71b9

Browse files
committed
Removes history from sites object
1 parent 9279388 commit 28b71b9

26 files changed

+235
-140
lines changed

app/browser/bookmarksExporter.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,31 @@ const electron = require('electron')
1111
const dialog = electron.dialog
1212
const app = electron.app
1313
const BrowserWindow = electron.BrowserWindow
14-
const getSetting = require('../../js/settings').getSetting
14+
15+
// State
16+
const bookmarkFoldersState = require('../common/state/bookmarkFoldersState')
17+
const bookmarsState = require('../common/state/bookmarksState')
18+
19+
// Constants
1520
const settings = require('../../js/constants/settings')
1621
const siteTags = require('../../js/constants/siteTags')
22+
23+
// Utils
24+
const {getSetting} = require('../../js/settings')
1725
const siteUtil = require('../../js/state/siteUtil')
18-
const isWindows = process.platform === 'win32'
26+
const platformUtil = require('../common/lib/platformUtil')
27+
1928
const indentLength = 2
2029
const indentType = ' '
2130

22-
function showDialog (sites) {
31+
function showDialog (state) {
2332
const focusedWindow = BrowserWindow.getFocusedWindow()
2433
const fileName = moment().format('DD_MM_YYYY') + '.html'
2534
const defaultPath = path.join(getSetting(settings.DEFAULT_DOWNLOAD_SAVE_PATH) || app.getPath('downloads'), fileName)
2635
let personal = []
2736
let other = []
37+
const bookmarks = bookmarsState.getBookmarks(state)
38+
const bookmarkFolders = bookmarkFoldersState.getFolders(state)
2839

2940
dialog.showSaveDialog(focusedWindow, {
3041
defaultPath: defaultPath,
@@ -34,14 +45,14 @@ function showDialog (sites) {
3445
}]
3546
}, (fileName) => {
3647
if (fileName) {
37-
personal = createBookmarkArray(sites)
38-
other = createBookmarkArray(sites, -1, false)
48+
personal = createBookmarkArray(bookmarks, bookmarkFolders)
49+
other = createBookmarkArray(bookmarks, bookmarkFolders, -1, false)
3950
fs.writeFileSync(fileName, createBookmarkHTML(personal, other))
4051
}
4152
})
4253
}
4354

44-
// TODO refactor this based on the structure
55+
// TODO refactor this based on the structure (now we send in bookmarks and folders)
4556
function createBookmarkArray (sites, parentFolderId, first = true, depth = 1) {
4657
const filteredBookmarks = parentFolderId
4758
? sites.filter((site) => site.get('parentFolderId') === parentFolderId)
@@ -71,7 +82,7 @@ function createBookmarkArray (sites, parentFolderId, first = true, depth = 1) {
7182
}
7283

7384
function createBookmarkHTML (personal, other) {
74-
const breakTag = (isWindows) ? '\r\n' : '\n'
85+
const breakTag = (platformUtil.isWindows()) ? '\r\n' : '\n'
7586
const title = 'Bookmarks'
7687

7788
return `<!DOCTYPE NETSCAPE-Bookmark-file-1>

app/browser/menu.js

+1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ const createBookmarksSubmenu = (state) => {
401401
CommonMenu.exportBookmarksMenuItem()
402402
]
403403

404+
// TODO we should send sites in, but first level bookmarks and folders
404405
const bookmarks = menuUtil.createBookmarkTemplateItems(state.get('sites'))
405406
if (bookmarks.length > 0) {
406407
submenu.push(CommonMenu.separatorMenuItem)

app/browser/reducers/sitesReducer.js

+21-20
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ const Immutable = require('immutable')
88

99
// Actions
1010
const syncActions = require('../../../js/actions/syncActions')
11+
const appActions = require('../../../js/actions/appActions')
1112

1213
// State
1314
const siteCache = require('../../common/state/siteCache')
1415
const tabState = require('../../common/state/tabState')
1516
const bookmarkFoldersState = require('../../common/state/bookmarkFoldersState')
1617
const pinnedSitesState = require('../../common/state/pinnedSitesState')
1718
const bookmarksState = require('../../common/state/bookmarksState')
19+
const historyState = require('../../common/state/historyState')
1820

1921
// Constants
2022
const appConstants = require('../../../js/constants/appConstants')
@@ -61,30 +63,17 @@ const sitesReducer = (state, action, immutableAction) => {
6163
const temp = state.get('tempClearBrowsingData', Immutable.Map())
6264
const clearData = defaults ? defaults.merge(temp) : temp
6365
if (clearData.get('browserHistory')) {
64-
state = state.set('sites', siteUtil.clearHistory(state.get('sites')))
66+
state = historyState.clearSites()
6567
filtering.clearHistory()
6668
}
6769
break
6870
}
69-
case appConstants.APP_ADD_SITE:
71+
case appConstants.APP_ADD_HISTORY_SITE:
7072
{
7173
const isSyncEnabled = syncEnabled()
72-
if (Immutable.List.isList(action.siteDetail)) {
73-
action.siteDetail.forEach((s) => {
74-
state = siteUtil.addSite(state, s, action.tag, action.skipSync)
75-
if (isSyncEnabled) {
76-
state = syncUtil.updateSiteCache(state, s)
77-
}
78-
})
79-
} else {
80-
let sites = state.get('sites')
81-
if (!action.siteDetail.get('folderId') && siteUtil.isFolder(action.siteDetail)) {
82-
action.siteDetail = action.siteDetail.set('folderId', siteUtil.getNextFolderId(sites))
83-
}
84-
state = siteUtil.addSite(state, action.siteDetail, action.tag, action.skipSync)
85-
if (isSyncEnabled) {
86-
state = syncUtil.updateSiteCache(state, action.siteDetail)
87-
}
74+
state = historyState.addSite(state, action.siteDetail)
75+
if (isSyncEnabled) {
76+
state = syncUtil.updateSiteCache(state, action.siteDetail)
8877
}
8978
break
9079
}
@@ -113,6 +102,12 @@ const sitesReducer = (state, action, immutableAction) => {
113102
state = updateActiveTabBookmarked(state)
114103
break
115104
}
105+
case appConstants.APP_ADD_BOOKMARKS:
106+
{
107+
// TODO we need to do it like this until we implement action inside actions
108+
action.bookmarkList.forEach(bookmark => appActions.addBookmark(bookmark))
109+
break
110+
}
116111
case appConstants.APP_EDIT_BOOKMARK:
117112
{
118113
const isSyncEnabled = syncEnabled()
@@ -160,6 +155,12 @@ const sitesReducer = (state, action, immutableAction) => {
160155
}
161156
break
162157
}
158+
case appConstants.APP_ADD_BOOKMARK_FOLDERS:
159+
{
160+
// TODO we need to do it like this until we implement action inside actions
161+
action.folderList.forEach(folder => appActions.addBookmarkFolder(folder))
162+
break
163+
}
163164
case appConstants.APP_EDIT_BOOKMARK_FOLDER:
164165
{
165166
const isSyncEnabled = syncEnabled()
@@ -182,7 +183,7 @@ const sitesReducer = (state, action, immutableAction) => {
182183
state = bookmarkFoldersState.removeFolder(state, action.folderKey)
183184
break
184185
}
185-
case appConstants.APP_REMOVE_SITE:
186+
case appConstants.APP_REMOVE_HISTORY_SITE:
186187
const removeSiteSyncCallback = action.skipSync ? undefined : syncActions.removeSite
187188
state = siteUtil.removeSite(state, action.siteDetail, action.tag, true, removeSiteSyncCallback)
188189
if (syncEnabled()) {
@@ -241,7 +242,7 @@ const sitesReducer = (state, action, immutableAction) => {
241242
console.warn('Trying to pin a tabId which does not exist:', tabId, 'tabs: ', state.get('tabs').toJS())
242243
break
243244
}
244-
const sites = state.get('sites')
245+
const sites = pinnedSitesState.getSites(state)
245246
const siteDetail = pinnedSitesUtil.getDetailsFromTab(sites, tab)
246247
if (pinned) {
247248
state = pinnedSitesState.addPinnedSite(state, siteDetail)

app/browser/reducers/urlBarSuggestionsReducer.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@
77
const appConstants = require('../../../js/constants/appConstants')
88
const {generateNewSuggestionsList, generateNewSearchXHRResults} = require('../../common/lib/suggestion')
99
const {init, add} = require('../../common/lib/siteSuggestions')
10-
const Immutable = require('immutable')
1110
const {makeImmutable} = require('../../common/state/immutableUtil')
1211
const tabState = require('../../common/state/tabState')
1312

1413
const urlBarSuggestionsReducer = (state, action) => {
1514
switch (action.actionType) {
16-
case appConstants.APP_ADD_SITE:
15+
case appConstants.APP_ADD_HISTORY_SITE:
1716
case appConstants.APP_ADD_BOOKMARK:
1817
case appConstants.APP_EDIT_BOOKMARK:
19-
if (Immutable.List.isList(action.siteDetail)) {
20-
action.siteDetail.forEach((s) => {
21-
add(s)
22-
})
23-
} else {
24-
add(action.siteDetail)
25-
}
18+
add(action.siteDetail)
2619
break
2720
case appConstants.APP_SET_STATE:
21+
// TODO do we need to merge bookmarks and history into one?
2822
init(Object.values(action.appState.get('sites').toJS()))
2923
break
3024
case appConstants.APP_URL_BAR_TEXT_CHANGED:

app/browser/tabs.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {isResourceEnabled} = require('../filtering')
2929
const autofill = require('../autofill')
3030
const bookmarksState = require('../common/state/bookmarksState')
3131
const bookmarkFoldersState = require('../common/state/bookmarkFoldersState')
32+
const historyState = require('../common/state/historyState')
3233

3334
let currentPartitionNumber = 0
3435
const incrementPartitionNumber = () => ++currentPartitionNumber
@@ -797,7 +798,7 @@ const api = {
797798

798799
getHistoryEntries: (state, action) => {
799800
const tab = getWebContents(action.get('tabId'))
800-
const sites = state ? state.get('sites') : null
801+
const sites = state ? historyState.getSites(state) : null
801802

802803
if (tab && !tab.isDestroyed()) {
803804
let history = {
@@ -821,7 +822,7 @@ const api = {
821822
// TODO: return brave lion (or better: get icon from extension if possible as data URI)
822823
} else {
823824
if (sites) {
824-
const site = sites.find(function (element) { return element.get('location') === url })
825+
const site = sites.find((element) => element.get('location') === url)
825826
if (site) {
826827
entry.icon = site.get('favicon')
827828
}

app/common/lib/bookmarkFoldersUtil.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const isFolderNameValid = (title) => {
55
return (title != null && title !== 0) && title.trim().length > 0
66
}
77

8-
const getNextFolderIdItem = (sites) =>
9-
sites.max((siteA, siteB) => {
10-
const folderIdA = siteA.get('folderId')
11-
const folderIdB = siteB.get('folderId')
8+
const getNextFolderIdItem = (folders) =>
9+
folders.max((folderA, folderB) => {
10+
const folderIdA = folderA.get('folderId')
11+
const folderIdB = folderB.get('folderId')
1212
if (folderIdA === folderIdB) {
1313
return 0
1414
}
@@ -21,12 +21,12 @@ const getNextFolderIdItem = (sites) =>
2121
return folderIdA > folderIdB
2222
})
2323

24-
const getNextFolderId = (sites) => {
24+
const getNextFolderId = (folders) => {
2525
const defaultFolderId = 0
26-
if (!sites) {
26+
if (!folders) {
2727
return defaultFolderId
2828
}
29-
const maxIdItem = getNextFolderIdItem(sites)
29+
const maxIdItem = getNextFolderIdItem(folders)
3030
return (maxIdItem ? (maxIdItem.get('folderId') || 0) : 0) + 1
3131
}
3232

app/common/lib/historyUtil.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const {makeImmutable} = require('../state/immutableUtil')
88
const siteUtil = require('../../../js/state/siteUtil')
99
const aboutHistoryMaxEntries = 500
1010

11-
module.exports.maxEntries = aboutHistoryMaxEntries
11+
const maxEntries = aboutHistoryMaxEntries
1212

1313
const sortTimeDescending = (left, right) => {
1414
if (left.get('lastAccessedTime') < right.get('lastAccessedTime')) return 1
1515
if (left.get('lastAccessedTime') > right.get('lastAccessedTime')) return -1
1616
return 0
1717
}
1818

19-
module.exports.getHistory = (sites) => {
19+
const getHistory = (sites) => {
2020
sites = makeImmutable(sites) ? makeImmutable(sites).toList() : new Immutable.List()
2121
return sites.filter((site) => siteUtil.isHistoryEntry(site))
2222
.sort(sortTimeDescending)
@@ -30,7 +30,7 @@ const getDayString = (entry, locale) => {
3030
: ''
3131
}
3232

33-
module.exports.groupEntriesByDay = (history, locale) => {
33+
const groupEntriesByDay = (history, locale) => {
3434
const reduced = history.reduce((previousValue, currentValue, currentIndex, array) => {
3535
const result = currentIndex === 1 ? [] : previousValue
3636
if (currentIndex === 1) {
@@ -60,7 +60,7 @@ module.exports.groupEntriesByDay = (history, locale) => {
6060
* Return an array with ALL entries.
6161
* Format is expected to be array containing one array per day.
6262
*/
63-
module.exports.totalEntries = (entriesByDay) => {
63+
const totalEntries = (entriesByDay) => {
6464
entriesByDay = makeImmutable(entriesByDay) || new Immutable.List()
6565

6666
let result = new Immutable.List()
@@ -69,3 +69,10 @@ module.exports.totalEntries = (entriesByDay) => {
6969
})
7070
return result
7171
}
72+
73+
module.exports = {
74+
maxEntries,
75+
getHistory,
76+
groupEntriesByDay,
77+
totalEntries
78+
}

app/common/lib/pinnedSitesUtil.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
15
const Immutable = require('immutable')
26
const siteUtil = require('../../../js/state/siteUtil')
37
const {makeImmutable} = require('../state/immutableUtil')

app/common/state/aboutHistoryState.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5+
const Immutable = require('immutable')
56
const {makeImmutable} = require('./immutableUtil')
6-
const historyUtil = require('../lib/historyUtil')
7+
const historyState = require('./historyState')
78

89
const aboutHistoryState = {
910
getHistory: (state) => {
1011
state = makeImmutable(state)
1112
return state.getIn(['about', 'history'])
1213
},
14+
1315
setHistory: (state) => {
1416
state = makeImmutable(state)
15-
state = state.setIn(['about', 'history', 'entries'],
16-
historyUtil.getHistory(state.get('sites')))
17+
// TODO make sure that they are sorted
18+
state = state.setIn(['about', 'history', 'entries'], historyState.getSites(state))
19+
return state.setIn(['about', 'history', 'updatedStamp'], new Date().getTime())
20+
},
21+
22+
clearHistory: (state) => {
23+
state = makeImmutable(state)
24+
state = state.setIn(['about', 'history', 'entries'], Immutable.Map())
1725
return state.setIn(['about', 'history', 'updatedStamp'], new Date().getTime())
1826
}
1927
}

app/common/state/aboutNewTabState.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const Immutable = require('immutable')
66
const {makeImmutable} = require('./immutableUtil')
77
const {isSourceAboutUrl} = require('../../../js/lib/appUrlUtil')
8+
const historyState = require('./historyState')
89
const aboutNewTabMaxEntries = 18
910

1011
const pinnedTopSites = (state) => {
@@ -50,8 +51,7 @@ const getTopSites = (state) => {
5051
return Immutable.Map()
5152
}
5253

53-
// TODO change to historySites
54-
return state.get('sites')
54+
return historyState.getSites(state)
5555
.filter((site, key) => !isSourceAboutUrl(site.get('location')) && !isPinned(state, key) && !isIgnored(state, key))
5656
.sort(sortCountDescending)
5757
.slice(0, aboutNewTabMaxEntries)
@@ -80,6 +80,13 @@ const aboutNewTabState = {
8080
// return a filtered version of the sites array
8181
state = state.setIn(['about', 'newtab', 'sites'], getTopSites(state))
8282
return state.setIn(['about', 'newtab', 'updatedStamp'], new Date().getTime())
83+
},
84+
85+
clearTopSites: (state) => {
86+
state = makeImmutable(state)
87+
88+
state = state.setIn(['about', 'newtab', 'sites'], Immutable.Map())
89+
return state.setIn(['about', 'newtab', 'updatedStamp'], new Date().getTime())
8390
}
8491
}
8592

0 commit comments

Comments
 (0)