`core:open-note` select notebook from sidebar

When calling core:open-note it would be nice to have an argument like selectInSidebar where when the passed noteID belongs to a notebook, that notebook is also selected on the sidebar so it keeps the context consistent.

Or if this is not possible, a separate API (command) to select a notebook from the sidebar would be enough. I can just call those one after the other.

Would be more than happy to contribute this, but not sure if the source code is open or closed?

Thanks.

Hi Marconi,

Thank you for the suggestion.
core:open-note should not affect other UIs because user interaction flow is basically side bar → note list → editor.
Sidebar’s selection state is tied with query context which represents currenty used query for showing the content of note list in order to make consistent between components.
So, you have to manipulate query context to change the sidebar state based on currently editing note.
There are some commands to help do that:

But those commands automatically open the first note in the note list. It would be nice to add an option like selectFirstNote so that you can disable this behavior in the next version.

Hey @craftzdog,

I ended-up with:

const { config } = inkdrop.store.getState();

inkdrop.commands.dispatch(document.body, 'core:note-list-show-notes-in-book', {
  bookId: config.core.defaultBook,
});

Yes, I want my default notebook selected on sidebar. :smile:

This works when run through dev console but not when added to init.js, I presume that’s because init.js is exercuted early on while the sidebar hasn’t been loaded yet so will try this on a plugin later.

Will keep you posted, cheers!

Great!
You can use onAppReady event :slight_smile:

Oh that’s pretty cool! Will try that first instead. :wink:

Its not working :confused:

I tried:

inkdrop.onAppReady(() => {
  inkdrop.commands.dispatch(document.body, 'core:note-list-show-notes-in-book', {
    bookId: config.core.defaultBook,
  });
});

Event tried wrapping with setTimeout like:

inkdrop.onAppReady(() => {
  setTimeout(() => {
    inkdrop.commands.dispatch(document.body, 'core:note-list-show-notes-in-book', {
      bookId: config.core.defaultBook,
    });
  }, 5000);
});

I can see everything loaded but when the callback is called, nothing happens. These were all tested just in init.js.

Thoughts?

Config should be loaded on the event:

inkdrop.onAppReady(() => {
  const config = inkdrop.store.getState().config
  inkdrop.commands.dispatch(document.body, 'core:note-list-show-notes-in-book', {
    bookId: config.core.defaultBook
  });
});

It works! well that was silly of me. :smile:, thanks. Now time to turn this into a plugin, can’t believe I’ve been putting this off when it was an easy implementation. :smile:

And here’s my first ever plugin https://github.com/marconi/default-notebook :smile:, thanks for the support and a great app!

Cool! I applied you a plugin developer license.
Thank you for creating a plugin :raised_hands:

2 Likes

No freakin way! so I can use the app I’m more than willing to pay for, for FREE!? Super! :smile:

2 Likes

Yeah! Please enjoy :smiley: