1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

All: Handle saving collapsed states of sub-notebook

This commit is contained in:
Laurent Cozic
2018-05-09 10:49:31 +01:00
parent 567596643c
commit da6fdad2de
8 changed files with 95 additions and 9 deletions

View File

@@ -26,6 +26,7 @@ const defaultState = {
appState: 'starting',
hasDisabledSyncItems: false,
newNote: null,
collapsedFolderIds: [],
};
const stateUtils = {};
@@ -51,6 +52,23 @@ function stateHasEncryptedItems(state) {
return false;
}
function folderSetCollapsed(state, action) {
const collapsedFolderIds = state.collapsedFolderIds.slice();
const idx = collapsedFolderIds.indexOf(action.id);
if (action.collapsed) {
if (idx >= 0) return state;
collapsedFolderIds.push(action.id);
} else {
if (idx < 0) return state;
collapsedFolderIds.splice(idx, 1);
}
newState = Object.assign({}, state);
newState.collapsedFolderIds = collapsedFolderIds;
return newState;
}
// When deleting a note, tag or folder
function handleItemDelete(state, action) {
let newState = Object.assign({}, state);
@@ -339,6 +357,26 @@ const reducer = (state = defaultState, action) => {
newState.folders = action.items;
break;
case 'FOLDER_SET_COLLAPSED':
newState = folderSetCollapsed(state, action);
break;
case 'FOLDER_TOGGLE':
if (state.collapsedFolderIds.indexOf(action.id) >= 0) {
newState = folderSetCollapsed(state, Object.assign({ collapsed: false }, action));
} else {
newState = folderSetCollapsed(state, Object.assign({ collapsed: true }, action));
}
break;
case 'FOLDER_SET_COLLAPSED_ALL':
newState = Object.assign({}, state);
newState.collapsedFolderIds = action.ids.slice();
break;
case 'TAG_UPDATE_ALL':
newState = Object.assign({}, state);