1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +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:
Laurent Cozic 2018-11-08 00:58:06 +00:00
parent 5c1dd79435
commit 28b1d8a324
3 changed files with 46 additions and 24 deletions

View File

@ -619,16 +619,10 @@ class NoteTextComponent extends React.Component {
bridge().openItem(filePath); bridge().openItem(filePath);
} else if (item.type_ === BaseModel.TYPE_NOTE) { } else if (item.type_ === BaseModel.TYPE_NOTE) {
this.props.dispatch({ this.props.dispatch({
type: "FOLDER_SELECT", type: "FOLDER_AND_NOTE_SELECT",
id: item.parent_id, folderId: item.parent_id,
noteId: item.id,
}); });
setTimeout(() => {
this.props.dispatch({
type: 'NOTE_SELECT',
id: item.id,
});
}, 10);
} else { } else {
throw new Error('Unsupported item type: ' + item.type_); throw new Error('Unsupported item type: ' + item.type_);
} }

View File

@ -181,7 +181,7 @@ class BaseApplication {
process.exit(code); process.exit(code);
} }
async refreshNotes(state) { async refreshNotes(state, useSelectedNoteId = false) {
let parentType = state.notesParentType; let parentType = state.notesParentType;
let parentId = null; let parentId = null;
@ -233,10 +233,17 @@ class BaseApplication {
notesSource: source, notesSource: source,
}); });
this.store().dispatch({ if (useSelectedNoteId) {
type: 'NOTE_SELECT', this.store().dispatch({
id: notes.length ? notes[0].id : null, 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) { reducerActionToString(action) {
@ -273,13 +280,16 @@ class BaseApplication {
const result = next(action); const result = next(action);
const newState = store.getState(); const newState = store.getState();
let refreshNotes = false; let refreshNotes = false;
let refreshNotesUseSelectedNoteId = false;
reduxSharedMiddleware(store, next, action); 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); Setting.setValue('activeFolderId', newState.selectedFolderId);
this.currentFolder_ = newState.selectedFolderId ? await Folder.load(newState.selectedFolderId) : null; this.currentFolder_ = newState.selectedFolderId ? await Folder.load(newState.selectedFolderId) : null;
refreshNotes = true; 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')) { if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && action.key == 'uncompletedTodosOnTop') || action.type == 'SETTING_UPDATE_ALL')) {
@ -303,7 +313,7 @@ class BaseApplication {
} }
if (refreshNotes) { 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')) { if ((action.type == 'SETTING_UPDATE_ONE' && (action.key == 'dateFormat' || action.key == 'timeFormat')) || (action.type == 'SETTING_UPDATE_ALL')) {

View File

@ -169,8 +169,25 @@ function defaultNotesParentType(state, exclusion) {
return newNotesParentType; 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) { 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); let newState = Object.assign({}, state);
if (action.type === 'NOTE_SELECT') { if (action.type === 'NOTE_SELECT') {
@ -279,13 +296,14 @@ const reducer = (state = defaultState, action) => {
case 'FOLDER_SELECT': case 'FOLDER_SELECT':
newState = Object.assign({}, state); newState = changeSelectedFolder(state, action);
newState.selectedFolderId = action.id; break;
if (!action.id) {
newState.notesParentType = defaultNotesParentType(state, 'Folder'); case 'FOLDER_AND_NOTE_SELECT':
} else {
newState.notesParentType = 'Folder'; newState = changeSelectedFolder(state, action);
} const noteSelectAction = Object.assign({}, action, { type: 'NOTE_SELECT'});
newState = changeSelectedNotes(newState, noteSelectAction);
break; break;
case 'SETTING_UPDATE_ALL': case 'SETTING_UPDATE_ALL':