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

134 lines
3.9 KiB
TypeScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
2023-01-16 13:44:52 +05:00
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
import {
2022-12-26 13:13:42 +05:00
showAddReminderDialog,
showBuyDialog,
2021-07-20 12:47:11 +05:00
showCreateTagDialog,
2022-12-26 13:13:42 +05:00
showEditReminderDialog,
showEmailVerificationDialog,
showFeatureDialog,
2023-06-16 19:10:02 +05:00
showOnboardingDialog,
showSettings
} 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 RouteContainer from "../components/route-container";
2021-05-27 12:29:58 +05:00
import DiffViewer from "../components/diff-viewer";
import Unlock from "../components/unlock";
import { store as editorStore } from "../stores/editor-store";
import { isMobile } from "../utils/dimensions";
2021-02-16 11:49:03 +05:00
import { hashNavigate } from ".";
2022-07-26 23:19:05 +05:00
import Editor from "../components/editor";
2023-06-20 12:20:16 +05:00
import { defineRoutes } from "./types";
2023-06-20 12:20:16 +05:00
const hashroutes = defineRoutes({
"/": () => {
2023-10-24 11:41:30 +05:00
return !editorStore.get().session.state && <Editor nonce={"-1"} />;
},
2021-01-04 01:57:32 +05:00
"/email/verify": () => {
showEmailVerificationDialog().then(afterAction);
2021-01-04 01:57:32 +05:00
},
"/notebooks/create": () => {
showAddNotebookDialog().then(afterAction);
},
2023-06-20 12:20:16 +05:00
"/notebooks/:notebookId/edit": ({ notebookId }) => {
2023-06-16 19:10:02 +05:00
showEditNotebookDialog(notebookId)?.then(afterAction);
},
2022-12-26 13:13:42 +05:00
"/reminders/create": () => {
showAddReminderDialog().then(afterAction);
2022-12-26 13:13:42 +05:00
},
2023-06-20 12:20:16 +05:00
"/reminders/:reminderId/edit": ({ reminderId }) => {
showEditReminderDialog(reminderId).then(afterAction);
2022-12-26 13:13:42 +05:00
},
2021-07-20 12:47:11 +05:00
"/tags/create": () => {
showCreateTagDialog().then(afterAction);
2021-07-20 12:47:11 +05:00
},
"/notes/create": () => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
hashNavigate("/notes/create", { addNonce: true, replace: true });
},
2023-06-20 12:20:16 +05:00
"/notes/create/:nonce": ({ nonce }) => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
2023-10-24 11:41:30 +05:00
return <Editor nonce={nonce} />;
},
2023-06-20 12:20:16 +05:00
"/notes/:noteId/edit": ({ noteId }) => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
2022-04-01 20:07:57 +05:00
2022-07-26 23:19:05 +05:00
return <Editor noteId={noteId} />;
},
2023-06-20 12:20:16 +05:00
"/notes/:noteId/unlock": ({ noteId }) => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
return (
<RouteContainer
2023-06-20 12:20:16 +05:00
type="unlock"
2021-02-16 11:49:03 +05:00
buttons={{
back: isMobile()
? {
title: "Go back",
2023-06-20 12:20:16 +05:00
onClick: () =>
hashNavigate("/notes/create", {
addNonce: true,
replace: true
})
2021-02-16 11:49:03 +05:00
}
: undefined
2021-02-16 11:49:03 +05:00
}}
2023-06-20 12:20:16 +05:00
>
<Unlock noteId={noteId} />
</RouteContainer>
);
},
2023-06-20 12:20:16 +05:00
"/notes/:noteId/conflict": ({ noteId }) => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
2021-05-27 12:29:58 +05:00
return <DiffViewer noteId={noteId} />;
},
"/buy": () => {
showBuyDialog().then(afterAction);
},
2023-06-16 19:10:02 +05:00
"/buy/:code": ({ code }: { code: string }) => {
showBuyDialog("monthly", code).then(afterAction);
2021-06-28 20:44:58 +05:00
},
2023-06-20 12:20:16 +05:00
"/buy/:plan/:code": ({ plan, code }) => {
showBuyDialog(plan === "monthly" ? "monthly" : "yearly", code).then(
afterAction
);
2021-04-07 09:28:22 +05:00
},
"/welcome": () => {
2023-06-16 19:10:02 +05:00
showOnboardingDialog("new")?.then(afterAction);
},
"/confirmed": () => {
showFeatureDialog("confirmed").then(afterAction);
2023-06-16 19:10:02 +05:00
},
"/settings": () => {
showSettings().then(afterAction);
}
2023-06-20 12:20:16 +05:00
});
export default hashroutes;
2023-06-16 19:10:02 +05:00
export type HashRoute = keyof typeof hashroutes;
function afterAction() {
hashNavigate("/", { replace: true, notify: false });
if (!history.state.replace) history.back();
}