diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 932971d6c2..a145e553aa 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -619,16 +619,10 @@ class NoteTextComponent extends React.Component { bridge().openItem(filePath); } else if (item.type_ === BaseModel.TYPE_NOTE) { this.props.dispatch({ - type: "FOLDER_SELECT", - id: item.parent_id, + type: "FOLDER_AND_NOTE_SELECT", + folderId: item.parent_id, + noteId: item.id, }); - - setTimeout(() => { - this.props.dispatch({ - type: 'NOTE_SELECT', - id: item.id, - }); - }, 10); } else { throw new Error('Unsupported item type: ' + item.type_); } diff --git a/ReactNativeClient/lib/BaseApplication.js b/ReactNativeClient/lib/BaseApplication.js index 3115a3be49..53ea0cf7c8 100644 --- a/ReactNativeClient/lib/BaseApplication.js +++ b/ReactNativeClient/lib/BaseApplication.js @@ -181,7 +181,7 @@ class BaseApplication { process.exit(code); } - async refreshNotes(state) { + async refreshNotes(state, useSelectedNoteId = false) { let parentType = state.notesParentType; let parentId = null; @@ -233,10 +233,17 @@ class BaseApplication { notesSource: source, }); - this.store().dispatch({ - type: 'NOTE_SELECT', - id: notes.length ? notes[0].id : null, - }); + if (useSelectedNoteId) { + this.store().dispatch({ + type: 'NOTE_SELECT', + id: state.selectedNoteIds && state.selectedNoteIds.length ? state.selectedNoteIds[0] : null, + }); + } else { + this.store().dispatch({ + type: 'NOTE_SELECT', + id: notes.length ? notes[0].id : null, + }); + } } reducerActionToString(action) { @@ -273,13 +280,16 @@ class BaseApplication { const result = next(action); const newState = store.getState(); let refreshNotes = false; + let refreshNotesUseSelectedNoteId = false; reduxSharedMiddleware(store, next, action); - if (action.type == 'FOLDER_SELECT' || action.type === 'FOLDER_DELETE' || (action.type === 'SEARCH_UPDATE' && newState.notesParentType === 'Folder')) { + if (action.type == 'FOLDER_SELECT' || action.type === 'FOLDER_DELETE' || action.type === 'FOLDER_AND_NOTE_SELECT' || (action.type === 'SEARCH_UPDATE' && newState.notesParentType === 'Folder')) { Setting.setValue('activeFolderId', newState.selectedFolderId); this.currentFolder_ = newState.selectedFolderId ? await Folder.load(newState.selectedFolderId) : null; refreshNotes = true; + + if (action.type === 'FOLDER_AND_NOTE_SELECT') refreshNotesUseSelectedNoteId = true; } if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'uncompletedTodosOnTop') || action.type == 'SETTING_UPDATE_ALL')) { @@ -303,7 +313,7 @@ class BaseApplication { } if (refreshNotes) { - await this.refreshNotes(newState); + await this.refreshNotes(newState, refreshNotesUseSelectedNoteId); } if ((action.type == 'SETTING_UPDATE_ONE' && (action.key == 'dateFormat' || action.key == 'timeFormat')) || (action.type == 'SETTING_UPDATE_ALL')) { diff --git a/ReactNativeClient/lib/reducer.js b/ReactNativeClient/lib/reducer.js index ce90c05704..5e0c5b78e1 100644 --- a/ReactNativeClient/lib/reducer.js +++ b/ReactNativeClient/lib/reducer.js @@ -169,8 +169,25 @@ function defaultNotesParentType(state, exclusion) { return newNotesParentType; } +function changeSelectedFolder(state, action) { + newState = Object.assign({}, state); + newState.selectedFolderId = 'folderId' in action ? action.folderId : action.id; + if (!newState.selectedFolderId) { + newState.notesParentType = defaultNotesParentType(state, 'Folder'); + } else { + newState.notesParentType = 'Folder'; + } + return newState; +} + function changeSelectedNotes(state, action) { - const noteIds = 'id' in action ? (action.id ? [action.id] : []) : action.ids; + let noteIds = []; + if (action.id) noteIds = [action.id]; + if (action.ids) noteIds = action.ids; + if (action.noteId) noteIds = [action.noteId]; + + // const noteIds = 'id' in action ? (action.id ? [action.id] : []) : action.ids; + let newState = Object.assign({}, state); if (action.type === 'NOTE_SELECT') { @@ -279,13 +296,14 @@ const reducer = (state = defaultState, action) => { case 'FOLDER_SELECT': - newState = Object.assign({}, state); - newState.selectedFolderId = action.id; - if (!action.id) { - newState.notesParentType = defaultNotesParentType(state, 'Folder'); - } else { - newState.notesParentType = 'Folder'; - } + newState = changeSelectedFolder(state, action); + break; + + case 'FOLDER_AND_NOTE_SELECT': + + newState = changeSelectedFolder(state, action); + const noteSelectAction = Object.assign({}, action, { type: 'NOTE_SELECT'}); + newState = changeSelectedNotes(newState, noteSelectAction); break; case 'SETTING_UPDATE_ALL':