Files
notesnook/apps/web/src/navigation/hash-routes.js

117 lines
3.3 KiB
JavaScript
Raw Normal View History

import React from "react";
2021-01-03 10:16:54 +05:00
import Vault from "../common/vault";
import {
showBuyDialog,
showEmailVerificationDialog,
} from "../common/dialog-controller";
import {
showAddNotebookDialog,
showEditNotebookDialog,
2021-02-16 22:28:19 +05:00
} from "../common/dialog-controller";
import { closeOpenedDialog } from "../common/dialog-controller";
import { showLogInDialog } from "../common/dialog-controller";
import { showSignUpDialog } from "../common/dialog-controller";
import RouteContainer from "../components/route-container";
2021-05-27 12:29:58 +05:00
import DiffViewer from "../components/diff-viewer";
import Unlock from "../components/unlock";
2021-01-03 10:16:54 +05:00
import { store as appStore } from "../stores/app-store";
import { store as editorStore } from "../stores/editor-store";
import { isMobile, isTablet } from "../utils/dimensions";
import {
showEditTopicDialog,
showTopicDialog,
2021-02-16 22:28:19 +05:00
} from "../common/dialog-controller";
2021-02-16 11:49:03 +05:00
import { hashNavigate } from ".";
import { Suspense } from "react";
import EditorLoading from "../components/editor/loading";
import EditorPlaceholder from "../components/editor/-placeholder";
2021-04-07 09:28:22 +05:00
import { store as userStore } from "../stores/user-store";
2021-04-14 10:56:24 +05:00
import { upgrade } from "../common/checkout";
2021-04-07 09:28:22 +05:00
import { isUserPremium } from "../common";
const Editor = React.lazy(() => import("../components/editor"));
const hashroutes = {
"/": () => {
closeOpenedDialog();
if (isMobile() || isTablet()) editorStore.clearSession(false);
return !editorStore.get().session.state && <EditorPlaceholder />;
},
2021-01-04 01:57:32 +05:00
"/email/verify": () => {
showEmailVerificationDialog();
},
"/notebooks/create": () => {
showAddNotebookDialog();
},
"/notebooks/:notebookId/edit": ({ notebookId }) => {
showEditNotebookDialog(notebookId);
},
"/topics/create": () => {
showTopicDialog();
},
"/notebooks/:notebookId/topics/:topicId/edit": ({ notebookId, topicId }) => {
showEditTopicDialog(notebookId, topicId);
},
"/notes/create": () => {
hashNavigate("/notes/create", { addNonce: true, replace: true });
},
"/notes/create/:nonce": ({ nonce }) => {
return (
<Suspense fallback={<EditorLoading />}>
<Editor noteId={0} nonce={nonce} />
</Suspense>
);
},
"/notes/:noteId/edit": ({ noteId }) => {
return (
<Suspense fallback={<EditorLoading text="Opening note..." />}>
<Editor noteId={noteId} />
</Suspense>
);
},
"/notes/:noteId/unlock": ({ noteId }) => {
return (
<RouteContainer
2021-02-16 11:49:03 +05:00
buttons={{
back: isMobile()
? {
title: "Go back",
action: () =>
hashNavigate("/notes/create", {
addNonce: true,
replace: true,
}),
2021-02-16 11:49:03 +05:00
}
: undefined,
}}
component={<Unlock noteId={noteId} />}
/>
);
},
"/notes/:noteId/conflict": ({ noteId }) => {
2021-05-27 12:29:58 +05:00
return <DiffViewer noteId={noteId} />;
},
2021-01-03 10:16:54 +05:00
"/signup": () => {
showSignUpDialog();
},
"/vault/changePassword": () => {
Vault.changeVaultPassword();
},
"/vault/create": () => {
Vault.createVault().then((res) => {
appStore.setIsVaultCreated(res);
});
},
"/login": () => {
showLogInDialog();
},
"/buy": () => {
showBuyDialog();
},
2021-04-07 09:28:22 +05:00
"/buy/:code": ({ code }) => {
showBuyDialog(code);
2021-04-07 09:28:22 +05:00
},
};
export default hashroutes;