Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivateNewNote broken in 0.48.1-beta #2243

Closed
1 task done
elementc opened this issue Oct 17, 2021 · 2 comments
Closed
1 task done

ActivateNewNote broken in 0.48.1-beta #2243

elementc opened this issue Oct 17, 2021 · 2 comments

Comments

@elementc
Copy link
Sponsor Contributor

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

Trilium Version

0.48.1-beta

What operating system are you using?

Ubuntu

What is your setup?

Local + server sync

Operating System Version

Linux WATERFALCON 5.13.0-19-generic #19-Ubuntu SMP Thu Oct 7 21:58:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linu

Expected Behavior

I have a code note that is ~ similar to the "create new task" button in the demo. Full source:

api.addButtonToToolbar({
    title: 'New task',
    icon: 'check',
    shortcut: 'alt+n',
    action: async () => {
        // creating notes is backend (server) responsibility so we need to pass
        // the control there
        const taskNoteId = await api.runOnServer(async () => {
            const todoRootNote = await api.getNoteWithLabel('taskTodoRoot');
            const todoNoteId = todoRootNote.noteId;
            const newNoteParams = {"parentNoteId": todoNoteId, "title": "new task", "type": "text", "content": ""};
            const {note} = await api.createNewNote(newNoteParams);

            return note.noteId;
        });

        // we got an ID of newly created note and we want to immediatelly display it
        await api.activateNewNote(taskNoteId);
    }
});

Upon clicking the button this note creates, I expect for the script to create a note and open it.

Actual Behavior

The new note is created, but it isn't focused or found.
I note the following error in the frontend console:

tree.js:28 Uncaught (in promise) TypeError: t.split is not a function
    at l (tree.js:28)
    at Object.resolveNotePath (tree.js:12)
    at I.getResolvedNotePath (note_context.js:94)
    at I.setNote (note_context.js:31)
    at x.activateNewNote (frontend_script_api.js:83)
    at async HTMLSpanElement.action (eval at <anonymous> (bundle.js:18), <anonymous>:22:9)
l	@	tree.js:28
resolveNotePath	@	tree.js:12
getResolvedNotePath	@	note_context.js:94
setNote	@	note_context.js:31
activateNewNote	@	frontend_script_api.js:83
async function (async)		
action	@	VM91:12
dispatch	@	jquery.min.js:2
v.handle	@	jquery.min.js:2

Additional Information

No response

@elementc
Copy link
Sponsor Contributor Author

(also, 0.48 is really awesome and I am very impressed. you should be proud, @zadam :) )

@zadam
Copy link
Owner

zadam commented Oct 20, 2021

Hi, thanks for the report and the praise.

It doesn't work because 0.48 had the limitation for backend functions to be sync, not async as descibed here.

But it's somewhat confusing when exactly use sync and when async code, so I relaxed this again, and async backend will be allowed again.

(The trouble with async in backend is that it can't be transactional, but many scripts don't necessarily need to be, as e.g. your example).

@zadam zadam closed this as completed in 069fbee Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants