@@ -8,13 +8,15 @@ const Immutable = require('immutable')
8
8
9
9
// Actions
10
10
const syncActions = require ( '../../../js/actions/syncActions' )
11
+ const appActions = require ( '../../../js/actions/appActions' )
11
12
12
13
// State
13
14
const siteCache = require ( '../../common/state/siteCache' )
14
15
const tabState = require ( '../../common/state/tabState' )
15
16
const bookmarkFoldersState = require ( '../../common/state/bookmarkFoldersState' )
16
17
const pinnedSitesState = require ( '../../common/state/pinnedSitesState' )
17
18
const bookmarksState = require ( '../../common/state/bookmarksState' )
19
+ const historyState = require ( '../../common/state/historyState' )
18
20
19
21
// Constants
20
22
const appConstants = require ( '../../../js/constants/appConstants' )
@@ -61,30 +63,17 @@ const sitesReducer = (state, action, immutableAction) => {
61
63
const temp = state . get ( 'tempClearBrowsingData' , Immutable . Map ( ) )
62
64
const clearData = defaults ? defaults . merge ( temp ) : temp
63
65
if ( clearData . get ( 'browserHistory' ) ) {
64
- state = state . set ( 'sites' , siteUtil . clearHistory ( state . get ( 'sites' ) ) )
66
+ state = historyState . clearSites ( )
65
67
filtering . clearHistory ( )
66
68
}
67
69
break
68
70
}
69
- case appConstants . APP_ADD_SITE :
71
+ case appConstants . APP_ADD_HISTORY_SITE :
70
72
{
71
73
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 )
88
77
}
89
78
break
90
79
}
@@ -113,6 +102,12 @@ const sitesReducer = (state, action, immutableAction) => {
113
102
state = updateActiveTabBookmarked ( state )
114
103
break
115
104
}
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
+ }
116
111
case appConstants . APP_EDIT_BOOKMARK :
117
112
{
118
113
const isSyncEnabled = syncEnabled ( )
@@ -160,6 +155,12 @@ const sitesReducer = (state, action, immutableAction) => {
160
155
}
161
156
break
162
157
}
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
+ }
163
164
case appConstants . APP_EDIT_BOOKMARK_FOLDER :
164
165
{
165
166
const isSyncEnabled = syncEnabled ( )
@@ -182,7 +183,7 @@ const sitesReducer = (state, action, immutableAction) => {
182
183
state = bookmarkFoldersState . removeFolder ( state , action . folderKey )
183
184
break
184
185
}
185
- case appConstants . APP_REMOVE_SITE :
186
+ case appConstants . APP_REMOVE_HISTORY_SITE :
186
187
const removeSiteSyncCallback = action . skipSync ? undefined : syncActions . removeSite
187
188
state = siteUtil . removeSite ( state , action . siteDetail , action . tag , true , removeSiteSyncCallback )
188
189
if ( syncEnabled ( ) ) {
@@ -241,7 +242,7 @@ const sitesReducer = (state, action, immutableAction) => {
241
242
console . warn ( 'Trying to pin a tabId which does not exist:' , tabId , 'tabs: ' , state . get ( 'tabs' ) . toJS ( ) )
242
243
break
243
244
}
244
- const sites = state . get ( 'sites' )
245
+ const sites = pinnedSitesState . getSites ( state )
245
246
const siteDetail = pinnedSitesUtil . getDetailsFromTab ( sites , tab )
246
247
if ( pinned ) {
247
248
state = pinnedSitesState . addPinnedSite ( state , siteDetail )
0 commit comments