mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
fix: use hard navigate for auth pages navigation
This commit is contained in:
@@ -10,6 +10,7 @@ import { registerKeyMap } from "./common/key-map";
|
|||||||
import { isUserPremium } from "./hooks/use-is-user-premium";
|
import { isUserPremium } from "./hooks/use-is-user-premium";
|
||||||
import { loadTrackerScript } from "./utils/analytics";
|
import { loadTrackerScript } from "./utils/analytics";
|
||||||
import Modal from "react-modal";
|
import Modal from "react-modal";
|
||||||
|
import useDatabase from "./hooks/use-database";
|
||||||
|
|
||||||
Modal.setAppElement("#root");
|
Modal.setAppElement("#root");
|
||||||
if (process.env.NODE_ENV === "production") {
|
if (process.env.NODE_ENV === "production") {
|
||||||
@@ -27,9 +28,11 @@ export default function AppEffects({ setShow }) {
|
|||||||
const initUser = useUserStore((store) => store.init);
|
const initUser = useUserStore((store) => store.init);
|
||||||
const initNotes = useNotesStore((store) => store.init);
|
const initNotes = useNotesStore((store) => store.init);
|
||||||
const setIsVaultCreated = useStore((store) => store.setIsVaultCreated);
|
const setIsVaultCreated = useStore((store) => store.setIsVaultCreated);
|
||||||
|
const [isAppLoaded] = useDatabase();
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
function initializeApp() {
|
function initializeApp() {
|
||||||
|
if (!isAppLoaded) return;
|
||||||
refreshColors();
|
refreshColors();
|
||||||
refreshMenuPins();
|
refreshMenuPins();
|
||||||
initUser();
|
initUser();
|
||||||
@@ -41,6 +44,7 @@ export default function AppEffects({ setShow }) {
|
|||||||
})();
|
})();
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
|
isAppLoaded,
|
||||||
updateLastSynced,
|
updateLastSynced,
|
||||||
refreshColors,
|
refreshColors,
|
||||||
refreshMenuPins,
|
refreshMenuPins,
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import React, { useState, Suspense } from "react";
|
import React, { useState, Suspense } from "react";
|
||||||
import { Box, Flex, Text } from "rebass";
|
import { Box, Flex } from "rebass";
|
||||||
import ThemeProvider from "./components/theme-provider";
|
import ThemeProvider from "./components/theme-provider";
|
||||||
import { AnimatedFlex } from "./components/animated";
|
import { AnimatedFlex } from "./components/animated";
|
||||||
import NavigationMenuPlaceholder from "./components/navigationmenu/index.lite";
|
import NavigationMenuPlaceholder from "./components/navigationmenu/index.lite";
|
||||||
import StatusBarPlaceholder from "./components/statusbar/index.lite";
|
import StatusBarPlaceholder from "./components/statusbar/index.lite";
|
||||||
import useMobile from "./utils/use-mobile";
|
import useMobile from "./utils/use-mobile";
|
||||||
import useTablet from "./utils/use-tablet";
|
import useTablet from "./utils/use-tablet";
|
||||||
import { Loading } from "./components/icons";
|
|
||||||
import { LazyMotion, domAnimation } from "framer-motion";
|
import { LazyMotion, domAnimation } from "framer-motion";
|
||||||
import useDatabase from "./hooks/use-database";
|
import useDatabase from "./hooks/use-database";
|
||||||
import Loader from "./components/loader";
|
import Loader from "./components/loader";
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { store as appStore } from "../stores/app-store";
|
|||||||
import * as Icon from "../components/icons";
|
import * as Icon from "../components/icons";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { showRecoveryKeyDialog } from "../common/dialog-controller";
|
import { showRecoveryKeyDialog } from "../common/dialog-controller";
|
||||||
import { hashNavigate, navigate } from "../navigation";
|
import { hardNavigate, hashNavigate } from "../navigation";
|
||||||
import { isDesktop } from "../utils/platform";
|
import { isDesktop } from "../utils/platform";
|
||||||
import saveFile from "../commands/save-file";
|
import saveFile from "../commands/save-file";
|
||||||
import { PATHS } from "@notesnook/desktop/paths";
|
import { PATHS } from "@notesnook/desktop/paths";
|
||||||
@@ -51,7 +51,7 @@ export const Reminders = {
|
|||||||
login: {
|
login: {
|
||||||
title: "Login to sync your notes",
|
title: "Login to sync your notes",
|
||||||
subtitle: "You are not logged in",
|
subtitle: "You are not logged in",
|
||||||
action: () => navigate("/login"),
|
action: () => hardNavigate("/login"),
|
||||||
icon: Icon.User,
|
icon: Icon.User,
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
} from "../icons";
|
} from "../icons";
|
||||||
import { AnimatedFlex } from "../animated";
|
import { AnimatedFlex } from "../animated";
|
||||||
import NavigationItem from "./navigation-item";
|
import NavigationItem from "./navigation-item";
|
||||||
import { navigate } from "../../navigation";
|
import { hardNavigate, navigate } from "../../navigation";
|
||||||
import { db } from "../../common/db";
|
import { db } from "../../common/db";
|
||||||
import useMobile from "../../utils/use-mobile";
|
import useMobile from "../../utils/use-mobile";
|
||||||
import { showRenameColorDialog } from "../../common/dialog-controller";
|
import { showRenameColorDialog } from "../../common/dialog-controller";
|
||||||
@@ -243,7 +243,7 @@ function NavigationMenu(props) {
|
|||||||
<NavigationItem
|
<NavigationItem
|
||||||
title="Login"
|
title="Login"
|
||||||
icon={Login}
|
icon={Login}
|
||||||
onClick={() => navigate("/login")}
|
onClick={() => hardNavigate("/login")}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{bottomRoutes.map((item) => (
|
{bottomRoutes.map((item) => (
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function Toggle(props) {
|
|||||||
<ToggleIcon size={13} sx={{ flexShrink: 0, mr: 1 }} />
|
<ToggleIcon size={13} sx={{ flexShrink: 0, mr: 1 }} />
|
||||||
{label}
|
{label}
|
||||||
</Text>
|
</Text>
|
||||||
<ReactToggle size={20} checked={isOn} icons={false} />
|
<ReactToggle size={20} onChange={() => {}} checked={isOn} icons={false} />
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Circle, Sync, Loading, Update } from "../icons";
|
|||||||
import { useStore as useUserStore } from "../../stores/user-store";
|
import { useStore as useUserStore } from "../../stores/user-store";
|
||||||
import { useStore as useAppStore } from "../../stores/app-store";
|
import { useStore as useAppStore } from "../../stores/app-store";
|
||||||
import TimeAgo from "timeago-react";
|
import TimeAgo from "timeago-react";
|
||||||
import { hashNavigate, navigate } from "../../navigation";
|
import { hardNavigate, hashNavigate, navigate } from "../../navigation";
|
||||||
import useAutoUpdater from "../../hooks/use-auto-updater";
|
import useAutoUpdater from "../../hooks/use-auto-updater";
|
||||||
import downloadUpdate from "../../commands/download-update";
|
import downloadUpdate from "../../commands/download-update";
|
||||||
import installUpdate from "../../commands/install-update";
|
import installUpdate from "../../commands/install-update";
|
||||||
@@ -73,7 +73,7 @@ function StatusBar() {
|
|||||||
<Button
|
<Button
|
||||||
variant="statusitem"
|
variant="statusitem"
|
||||||
display="flex"
|
display="flex"
|
||||||
onClick={() => navigate("/login")}
|
onClick={() => hardNavigate("/login")}
|
||||||
sx={{ alignItems: "center", justifyContent: "center" }}
|
sx={{ alignItems: "center", justifyContent: "center" }}
|
||||||
>
|
>
|
||||||
<Circle size={7} color="error" />
|
<Circle size={7} color="error" />
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { initializeDatabase } from "../common/db";
|
import { initializeDatabase } from "../common/db";
|
||||||
|
|
||||||
|
const memory = {
|
||||||
|
isAppLoaded: false,
|
||||||
|
};
|
||||||
export default function useDatabase() {
|
export default function useDatabase() {
|
||||||
const [isAppLoaded, setIsAppLoaded] = useState(false);
|
const [isAppLoaded, setIsAppLoaded] = useState(memory.isAppLoaded);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (memory.isAppLoaded) return;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await import("../app.css");
|
await import("../app.css");
|
||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
setIsAppLoaded(true);
|
setIsAppLoaded(true);
|
||||||
|
memory.isAppLoaded = true;
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ async function loadNNCrypto() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @returns {Promise<import("nncrypto/src/interfaces").INNCrypto>}
|
||||||
|
*/
|
||||||
export async function getNNCrypto() {
|
export async function getNNCrypto() {
|
||||||
if (instance) return instance;
|
if (instance) return instance;
|
||||||
const NNCrypto = await loadNNCrypto();
|
const NNCrypto = await loadNNCrypto();
|
||||||
|
|||||||
@@ -91,3 +91,7 @@ const HOMEPAGE_ROUTE = {
|
|||||||
export function getHomeRoute() {
|
export function getHomeRoute() {
|
||||||
return HOMEPAGE_ROUTE[Config.get("homepage", 0)];
|
return HOMEPAGE_ROUTE[Config.get("homepage", 0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hardNavigate(route) {
|
||||||
|
window.location.assign(route);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ import { Box, Button, Flex, Text } from "rebass";
|
|||||||
import ThemeProvider from "../components/theme-provider";
|
import ThemeProvider from "../components/theme-provider";
|
||||||
import { CheckCircle, Loading, ArrowRight, Error } from "../components/icons";
|
import { CheckCircle, Loading, ArrowRight, Error } from "../components/icons";
|
||||||
import Field from "../components/field";
|
import Field from "../components/field";
|
||||||
import { getQueryParams, navigate, useQueryParams } from "../navigation";
|
import {
|
||||||
|
getQueryParams,
|
||||||
|
hardNavigate,
|
||||||
|
navigate,
|
||||||
|
useQueryParams,
|
||||||
|
} from "../navigation";
|
||||||
import { store as userstore } from "../stores/user-store";
|
import { store as userstore } from "../stores/user-store";
|
||||||
import { db } from "../common/db";
|
import { db } from "../common/db";
|
||||||
import Config from "../utils/config";
|
import Config from "../utils/config";
|
||||||
@@ -56,7 +61,7 @@ const authTypes = {
|
|||||||
text: "Already have an account?",
|
text: "Already have an account?",
|
||||||
action: {
|
action: {
|
||||||
text: "Log in",
|
text: "Log in",
|
||||||
onClick: () => navigate("/login", getQueryParams()),
|
onClick: () => hardNavigate("/login", getQueryParams()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
labels: { email: "Your email", password: "Set password" },
|
labels: { email: "Your email", password: "Set password" },
|
||||||
@@ -109,7 +114,7 @@ const authTypes = {
|
|||||||
text: "Don't have an account?",
|
text: "Don't have an account?",
|
||||||
action: {
|
action: {
|
||||||
text: "Sign up!",
|
text: "Sign up!",
|
||||||
onClick: () => navigate("/signup", getQueryParams()),
|
onClick: () => hardNavigate("/signup", getQueryParams()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
autoComplete: { password: "current-password" },
|
autoComplete: { password: "current-password" },
|
||||||
@@ -133,7 +138,7 @@ const authTypes = {
|
|||||||
text: "Remember your password?",
|
text: "Remember your password?",
|
||||||
action: {
|
action: {
|
||||||
text: "Log in",
|
text: "Log in",
|
||||||
onClick: () => navigate("/login", getQueryParams()),
|
onClick: () => hardNavigate("/login", getQueryParams()),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
helpTexts: {
|
helpTexts: {
|
||||||
@@ -384,7 +389,7 @@ function Auth(props) {
|
|||||||
alignSelf="start"
|
alignSelf="start"
|
||||||
mt={2}
|
mt={2}
|
||||||
variant="anchor"
|
variant="anchor"
|
||||||
onClick={() => navigate("/recover", getQueryParams())}
|
onClick={() => hardNavigate("/recover", getQueryParams())}
|
||||||
>
|
>
|
||||||
Forgot password?
|
Forgot password?
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import ScrollContainer from "../components/scroll-container";
|
|||||||
import { showLoadingDialog } from "../common/dialog-controller";
|
import { showLoadingDialog } from "../common/dialog-controller";
|
||||||
import { showToast } from "../utils/toast";
|
import { showToast } from "../utils/toast";
|
||||||
import { showPasswordDialog } from "../common/dialog-controller";
|
import { showPasswordDialog } from "../common/dialog-controller";
|
||||||
import { hashNavigate, navigate } from "../navigation";
|
import { hardNavigate, hashNavigate } from "../navigation";
|
||||||
import useVersion from "../utils/useVersion";
|
import useVersion from "../utils/useVersion";
|
||||||
import { CHECK_IDS } from "notes-core/common";
|
import { CHECK_IDS } from "notes-core/common";
|
||||||
import { openPaddleDialog } from "../common/checkout";
|
import { openPaddleDialog } from "../common/checkout";
|
||||||
@@ -179,7 +179,7 @@ function Settings(props) {
|
|||||||
p={1}
|
p={1}
|
||||||
sx={{ borderRadius: "default", cursor: "pointer" }}
|
sx={{ borderRadius: "default", cursor: "pointer" }}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
navigate("/login", { redirect: "/settings" });
|
hardNavigate("/login", { redirect: "/settings" });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Flex
|
<Flex
|
||||||
|
|||||||
Reference in New Issue
Block a user