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) => (
<NavMenuItem
onSelected={() => {
if (navigate(item.key)) {
onSelected={async () => {
if (await navigate(item.key)) {
setSelectedIndex(index);
}
}}

View File

@@ -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
});

View File

@@ -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;