1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-07 19:30:04 +02:00

Mobile: Fixes #902: Don't change existing note when sharing with mobile app

This commit is contained in:
Laurent Cozic 2018-10-24 19:10:05 +01:00
parent 739a6a4a9c
commit 2cb24bf198
2 changed files with 30 additions and 10 deletions

View File

@ -73,8 +73,12 @@ class Note extends BaseItem {
} }
static defaultTitle(note) { static defaultTitle(note) {
if (note.body && note.body.length) { return this.defaultTitleFromBody(note.body);
const lines = note.body.trim().split("\n"); }
static defaultTitleFromBody(body) {
if (body && body.length) {
const lines = body.trim().split("\n");
let output = lines[0].trim(); let output = lines[0].trim();
// Remove the first #, *, etc. // Remove the first #, *, etc.
while (output.length) { while (output.length) {

View File

@ -542,16 +542,32 @@ class AppComponent extends React.Component {
try { try {
const { type, value } = await ShareExtension.data(); const { type, value } = await ShareExtension.data();
if (type != "" && this.props.selectedFolderId) { // reg.logger().info('Got share data:', type, value);
this.props.dispatch({ if (type != "" && this.props.selectedFolderId) {
type: 'NAV_GO', const newNote = await Note.save({
routeName: 'Note', title: Note.defaultTitleFromBody(value),
noteId: null, body: value,
sharedData: {type: type, value: value}, parent_id: this.props.selectedFolderId
folderId: this.props.selectedFolderId,
itemType: 'note',
}); });
// This is a bit hacky, but the surest way to go to
// the needed note. We go back one screen in case there's
// already a note open - if we don't do this, the dispatch
// below will do nothing (because routeName wouldn't change)
// Then we wait a bit for the state to be set correctly, and
// finally we go to the new note.
this.props.dispatch({
type: 'NAV_BACK',
});
setTimeout(() => {
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Note',
noteId: newNote.id,
});
}, 5);
} }
} catch(e) { } catch(e) {