fix: navigation was possible in moveNote intent

This commit is contained in:
thecodrr
2020-01-07 16:06:21 +05:00
parent 3f0e79ceda
commit 2bd102c016
3 changed files with 11 additions and 7 deletions

View File

@@ -63,8 +63,8 @@ function App() {
> >
{Object.values(routes).map((item, index) => ( {Object.values(routes).map((item, index) => (
<NavMenuItem <NavMenuItem
onSelected={() => { onSelected={async () => {
if (navigate(item.key)) { if (await navigate(item.key)) {
setSelectedIndex(index); setSelectedIndex(index);
} }
}} }}

View File

@@ -12,8 +12,8 @@ const dropdownRefs = [];
const menuItems = note => [ const menuItems = note => [
{ {
title: note.notebook.notebook ? "Move" : "Add to", title: note.notebook.notebook ? "Move" : "Add to",
onClick: () => { onClick: async () => {
navigate(routes.notebooks.key, undefined, { await navigate(routes.notebooks.key, undefined, {
intent: "moveNote", intent: "moveNote",
data: note data: note
}); });

View File

@@ -49,7 +49,11 @@ export const navigationEvents = {
onWillNavigateAway: undefined onWillNavigateAway: undefined
}; };
var lastRoute = undefined; var lastRoute = undefined;
export function navigate(routeName, root = "navigationView", params = {}) { export async function navigate(
routeName,
root = "navigationView",
params = {}
) {
let route = routes[routeName]; let route = routes[routeName];
// do not navigate if the previous route is the same // do not navigate if the previous route is the same
@@ -62,11 +66,11 @@ export function navigate(routeName, root = "navigationView", params = {}) {
if ( if (
navigationEvents.onWillNavigateAway && navigationEvents.onWillNavigateAway &&
!navigationEvents.onWillNavigateAway(routeName, params) !(await navigationEvents.onWillNavigateAway(routeName, params))
) { ) {
navigationEvents.onWillNavigateAway = undefined;
return false; return false;
} }
navigationEvents.onWillNavigateAway = undefined;
let rootView = document.querySelector(`.${root}`); let rootView = document.querySelector(`.${root}`);
if (!rootView) return false; if (!rootView) return false;