You've already forked joplin
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user