2021-01-02 22:24:07 +05:00
|
|
|
import React from "react";
|
2021-01-03 10:16:54 +05:00
|
|
|
import Vault from "../common/vault";
|
2021-02-16 22:28:19 +05:00
|
|
|
import { showEmailVerificationDialog } from "../common/dialog-controller";
|
2021-01-02 22:24:07 +05:00
|
|
|
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";
|
2021-01-02 22:24:07 +05:00
|
|
|
import RouteContainer from "../components/route-container";
|
|
|
|
|
import SplitEditor from "../components/spliteditor";
|
|
|
|
|
import Unlock from "../components/unlock";
|
2021-01-03 10:16:54 +05:00
|
|
|
import { store as appStore } from "../stores/app-store";
|
2021-01-02 22:24:07 +05:00
|
|
|
import { store as editorStore } from "../stores/editor-store";
|
2021-01-07 14:31:54 +05:00
|
|
|
import { isMobile, isTablet } from "../utils/dimensions";
|
2021-01-07 17:47:46 +05:00
|
|
|
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 ".";
|
2021-02-17 12:31:54 +05:00
|
|
|
import { Suspense } from "react";
|
|
|
|
|
import EditorLoading from "../components/editor/loading";
|
2021-02-18 20:29:59 +05:00
|
|
|
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";
|
2021-02-17 12:31:54 +05:00
|
|
|
const Editor = React.lazy(() => import("../components/editor"));
|
2021-01-02 22:24:07 +05:00
|
|
|
|
|
|
|
|
const hashroutes = {
|
|
|
|
|
"/": () => {
|
|
|
|
|
closeOpenedDialog();
|
2021-01-07 14:31:54 +05:00
|
|
|
if (isMobile() || isTablet()) editorStore.clearSession(false);
|
2021-02-18 20:29:59 +05:00
|
|
|
|
|
|
|
|
return !editorStore.get().session.state && <EditorPlaceholder />;
|
2021-01-02 22:24:07 +05:00
|
|
|
},
|
2021-01-04 01:57:32 +05:00
|
|
|
"/email/verify": () => {
|
|
|
|
|
showEmailVerificationDialog();
|
|
|
|
|
},
|
2021-01-02 22:24:07 +05:00
|
|
|
"/notebooks/create": () => {
|
|
|
|
|
showAddNotebookDialog();
|
|
|
|
|
},
|
|
|
|
|
"/notebooks/:notebookId/edit": ({ notebookId }) => {
|
|
|
|
|
showEditNotebookDialog(notebookId);
|
|
|
|
|
},
|
2021-01-07 17:47:46 +05:00
|
|
|
"/topics/create": () => {
|
|
|
|
|
showTopicDialog();
|
|
|
|
|
},
|
|
|
|
|
"/notebooks/:notebookId/topics/:topicId/edit": ({ notebookId, topicId }) => {
|
|
|
|
|
showEditTopicDialog(notebookId, topicId);
|
|
|
|
|
},
|
2021-01-04 12:59:45 +05:00
|
|
|
"/notes/create": () => {
|
2021-02-27 10:44:13 +05:00
|
|
|
hashNavigate("/notes/create", { addNonce: true, replace: true });
|
|
|
|
|
},
|
|
|
|
|
"/notes/create/:nonce": ({ nonce }) => {
|
2021-02-17 12:31:54 +05:00
|
|
|
return (
|
|
|
|
|
<Suspense fallback={<EditorLoading />}>
|
2021-02-27 10:44:13 +05:00
|
|
|
<Editor noteId={0} nonce={nonce} />
|
2021-02-17 12:31:54 +05:00
|
|
|
</Suspense>
|
|
|
|
|
);
|
2021-01-04 12:59:45 +05:00
|
|
|
},
|
2021-01-02 22:24:07 +05:00
|
|
|
"/notes/:noteId/edit": ({ noteId }) => {
|
2021-02-17 12:31:54 +05:00
|
|
|
return (
|
|
|
|
|
<Suspense fallback={<EditorLoading text="Opening note..." />}>
|
|
|
|
|
<Editor noteId={noteId} />
|
|
|
|
|
</Suspense>
|
|
|
|
|
);
|
2021-01-02 22:24:07 +05:00
|
|
|
},
|
|
|
|
|
"/notes/:noteId/unlock": ({ noteId }) => {
|
|
|
|
|
return (
|
|
|
|
|
<RouteContainer
|
2021-02-16 11:49:03 +05:00
|
|
|
buttons={{
|
|
|
|
|
back: isMobile()
|
|
|
|
|
? {
|
|
|
|
|
title: "Go back",
|
2021-02-27 10:44:13 +05:00
|
|
|
action: () =>
|
|
|
|
|
hashNavigate("/notes/create", {
|
|
|
|
|
addNonce: true,
|
|
|
|
|
replace: true,
|
|
|
|
|
}),
|
2021-02-16 11:49:03 +05:00
|
|
|
}
|
|
|
|
|
: undefined,
|
|
|
|
|
}}
|
|
|
|
|
component={<Unlock noteId={noteId} />}
|
2021-01-02 22:24:07 +05:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
"/notes/:noteId/conflict": ({ noteId }) => {
|
|
|
|
|
return <SplitEditor 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);
|
|
|
|
|
});
|
|
|
|
|
},
|
2021-01-02 22:24:07 +05:00
|
|
|
"/login": () => {
|
|
|
|
|
showLogInDialog();
|
|
|
|
|
},
|
2021-04-07 09:28:22 +05:00
|
|
|
"/buy/:code": ({ code }) => {
|
|
|
|
|
hashNavigate("/", { notify: false });
|
|
|
|
|
const user = userStore.get().user;
|
|
|
|
|
if (!user || isUserPremium()) return;
|
|
|
|
|
upgrade(user, code);
|
|
|
|
|
},
|
2021-01-02 22:24:07 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default hashroutes;
|