forked from brave/browser-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splits sites object in the app state
Resolves brave#1856 Resolves brave#2771 Resolves brave#3646 Resolves brave#3694 Resolves brave#4224 Resolves brave#4260 Resolves brave#4833 Resolves brave#4868 Resolves brave#4929 Resolves brave#5699 Resolves brave#6104 Resolves brave#6108 Resolves brave#6585 Resolves brave#8022 Resolves brave#9301 Resolves brave#9326 Resolves brave#9978 Resolves brave#10026 Auditors: Test Plan:
- Loading branch information
Showing
88 changed files
with
3,201 additions
and
2,109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const Immutable = require('immutable') | ||
|
||
// State | ||
const bookmarkFoldersState = require('../../common/state/bookmarkFoldersState') | ||
|
||
// Constants | ||
const appConstants = require('../../../js/constants/appConstants') | ||
|
||
// Utils | ||
const {makeImmutable} = require('../../common/state/immutableUtil') | ||
const syncUtil = require('../../../js/state/syncUtil') | ||
|
||
const bookmarkFoldersReducer = (state, action, immutableAction) => { | ||
action = immutableAction || makeImmutable(action) | ||
switch (action.get('actionType')) { | ||
case appConstants.APP_ADD_BOOKMARK_FOLDER: | ||
{ | ||
const closestKey = action.get('closestKey') | ||
let folder = action.get('folderDetails') | ||
|
||
if (folder == null) { | ||
break | ||
} | ||
|
||
if (Immutable.List.isList(folder)) { | ||
action.get('folderDetails', Immutable.List()).forEach((folder) => { | ||
state = bookmarkFoldersState.addFolder(state, folder, closestKey) | ||
|
||
if (syncUtil.syncEnabled()) { | ||
state = syncUtil.updateSiteCache(state, folder) | ||
} | ||
}) | ||
} else { | ||
state = bookmarkFoldersState.addFolder(state, folder, closestKey) | ||
|
||
if (syncUtil.syncEnabled()) { | ||
state = syncUtil.updateSiteCache(state, folder) | ||
} | ||
} | ||
break | ||
} | ||
case appConstants.APP_EDIT_BOOKMARK_FOLDER: | ||
{ | ||
let folder = action.get('folderDetails') | ||
|
||
if (folder == null) { | ||
break | ||
} | ||
|
||
state = bookmarkFoldersState.editFolder(state, folder, action.get('editKey')) | ||
|
||
if (syncUtil.syncEnabled()) { | ||
state = syncUtil.updateSiteCache(state, folder) | ||
} | ||
|
||
break | ||
} | ||
case appConstants.APP_MOVE_BOOKMARK_FOLDER: | ||
{ | ||
state = bookmarkFoldersState.moveFolder( | ||
state, | ||
action.get('folderKey'), | ||
action.get('destinationKey'), | ||
action.get('append'), | ||
action.get('moveIntoParent') | ||
) | ||
|
||
if (syncUtil.syncEnabled()) { | ||
const destinationDetail = state.getIn(['sites', action.get('destinationKey')]) | ||
state = syncUtil.updateSiteCache(state, destinationDetail) | ||
} | ||
break | ||
} | ||
case appConstants.APP_REMOVE_BOOKMARK_FOLDER: | ||
{ | ||
state = bookmarkFoldersState.removeFolder(state, action.get('folderKey')) | ||
break | ||
} | ||
} | ||
|
||
return state | ||
} | ||
|
||
module.exports = bookmarkFoldersReducer |
Oops, something went wrong.