mgsloan/todoist-shortcuts

navigateToLeftMenuItem

mdbraber opened this issue · 5 comments

I wanted a function that could navigate directly to a specific top section, favorite or project - see the code below. I've used the updated withLeftMenuItems from #232. The itemId can be today, upcoming or any itemId that Todoist creates for projects or filters. This way you can easily navigate to projects with the same name (and code doesn't have to be updated if projects get renamed).

  function navigateToLeftMenuItem(itemId) {
      return () => {
          withLeftMenuItems(['top','favorites','projects'], (menuItems, current) => {
              for (const menuItem of menuItems) {
                  if(menuItem.href.indexOf(itemId) > 0) {
                      click(menuItem);
                  }
              }
          });
      }
  }

You can make keybinding as follows:

    ['command+1', navigateToLeftMenuItem('377156504')],
    ['command+2', navigateToLeftMenuItem('today')],
    ['command+3', navigateToLeftMenuItem('upcoming')],

Cool, thanks! I've added this code to version 173

Thanks @mgsloan - I think we also then need the updated code from #232 which also fixes the navigation issues mentioned there (issue is closed officially - maybe reopen if it needs work?)

Welcome! Yeah, was going to try to include that in this release but didn't get around to it. Will write more on that issue

No problem. Just mentioning that the withLeftMenuLinks code is from my updated function so not from < v173. So if that code fron #232 is not integrated in v173 it might need some (temporary updating). Check the sections part of the code.