Desktop, Mobile: Fixes #2652: Fixed auto-title feature

This commit is contained in:
Laurent Cozic 2020-03-04 01:13:10 +00:00
parent cb2df32d91
commit 6e47652566
2 changed files with 13 additions and 27 deletions

View File

@ -932,6 +932,7 @@ const NoteScreen = connect(state => {
ftsEnabled: state.settings['db.ftsEnabled'],
sharedData: state.sharedData,
showSideMenu: state.showSideMenu,
provisionalNoteIds: state.provisionalNoteIds,
};
})(NoteScreenComponent);

View File

@ -20,13 +20,9 @@ shared.noteExists = async function(noteId) {
};
shared.saveNoteButton_press = async function(comp, folderId = null, options = null) {
options = Object.assign(
{},
{
autoTitle: true,
},
options
);
options = Object.assign({}, {
autoTitle: true,
}, options);
const releaseMutex = await saveNoteMutex_.acquire();
@ -46,14 +42,14 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
note.parent_id = folder.id;
}
let isNew = !note.id;
const isProvisionalNote = comp.props.provisionalNoteIds.includes(note.id);
let saveOptions = { userSideValidation: true };
if (!isNew) {
saveOptions.fields = BaseModel.diffObjectsFields(comp.state.lastSavedNote, note);
}
const saveOptions = {
userSideValidation: true,
fields: BaseModel.diffObjectsFields(comp.state.lastSavedNote, note),
};
const hasAutoTitle = comp.state.newAndNoTitleChangeNoteId || (isNew && !note.title);
const hasAutoTitle = comp.state.newAndNoTitleChangeNoteId || (isProvisionalNote && !note.title);
if (hasAutoTitle && options.autoTitle) {
note.title = Note.defaultTitle(note);
if (saveOptions.fields && saveOptions.fields.indexOf('title') < 0) saveOptions.fields.push('title');
@ -64,7 +60,7 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
const stateNote = comp.state.note;
// Note was reloaded while being saved.
if (!isNew && (!stateNote || stateNote.id !== savedNote.id)) return releaseMutex();
if (!stateNote || stateNote.id !== savedNote.id) return releaseMutex();
// Re-assign any property that might have changed during saving (updated_time, etc.)
note = Object.assign(note, savedNote);
@ -86,15 +82,13 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
note: note,
};
if (isNew && hasAutoTitle) newState.newAndNoTitleChangeNoteId = note.id;
if (isProvisionalNote && hasAutoTitle) newState.newAndNoTitleChangeNoteId = note.id;
if (!options.autoTitle) newState.newAndNoTitleChangeNoteId = null;
comp.setState(newState);
// await shared.refreshAttachedResources(comp, newState.note.body);
if (isNew) {
if (isProvisionalNote) {
Note.updateGeolocation(note.id).then(geoNote => {
const stateNote = comp.state.note;
if (!stateNote || !geoNote) return;
@ -116,15 +110,6 @@ shared.saveNoteButton_press = async function(comp, folderId = null, options = nu
});
}
if (isNew) {
// Clear the newNote item now that the note has been saved, and
// make sure that the note we're editing is selected.
comp.props.dispatch({
type: 'NOTE_SELECT',
id: savedNote.id,
});
}
releaseMutex();
};