From 2bd102c01626769f9edea18f7f16e4312ff3cba6 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Tue, 7 Jan 2020 16:06:21 +0500 Subject: [PATCH] fix: navigation was possible in moveNote intent --- apps/web/src/app.js | 4 ++-- apps/web/src/components/note/index.js | 4 ++-- apps/web/src/navigation/index.js | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/web/src/app.js b/apps/web/src/app.js index e833eea2d..3d1e327fe 100644 --- a/apps/web/src/app.js +++ b/apps/web/src/app.js @@ -63,8 +63,8 @@ function App() { > {Object.values(routes).map((item, index) => ( { - if (navigate(item.key)) { + onSelected={async () => { + if (await navigate(item.key)) { setSelectedIndex(index); } }} diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js index 7d3a2da4c..86eb88508 100644 --- a/apps/web/src/components/note/index.js +++ b/apps/web/src/components/note/index.js @@ -12,8 +12,8 @@ const dropdownRefs = []; const menuItems = note => [ { title: note.notebook.notebook ? "Move" : "Add to", - onClick: () => { - navigate(routes.notebooks.key, undefined, { + onClick: async () => { + await navigate(routes.notebooks.key, undefined, { intent: "moveNote", data: note }); diff --git a/apps/web/src/navigation/index.js b/apps/web/src/navigation/index.js index f4f715d2f..1a7d4fe9c 100644 --- a/apps/web/src/navigation/index.js +++ b/apps/web/src/navigation/index.js @@ -49,7 +49,11 @@ export const navigationEvents = { onWillNavigateAway: undefined }; var lastRoute = undefined; -export function navigate(routeName, root = "navigationView", params = {}) { +export async function navigate( + routeName, + root = "navigationView", + params = {} +) { let route = routes[routeName]; // do not navigate if the previous route is the same @@ -62,11 +66,11 @@ export function navigate(routeName, root = "navigationView", params = {}) { if ( navigationEvents.onWillNavigateAway && - !navigationEvents.onWillNavigateAway(routeName, params) + !(await navigationEvents.onWillNavigateAway(routeName, params)) ) { - navigationEvents.onWillNavigateAway = undefined; return false; } + navigationEvents.onWillNavigateAway = undefined; let rootView = document.querySelector(`.${root}`); if (!rootView) return false;