mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Fixes #953 (maybe): Improved the way internal links to notes are loaded to make it more reliable
This commit is contained in:
parent
5c1dd79435
commit
28b1d8a324
@ -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_);
|
||||
}
|
||||
|
@ -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')) {
|
||||
|
@ -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':
|
||||
|
Loading…
Reference in New Issue
Block a user