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

144 lines
4.0 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2022 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
2021-01-03 10:16:54 +05:00
import Vault from "../common/vault";
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,
2021-07-20 12:47:11 +05:00
showEditTagDialog,
showEmailVerificationDialog,
showFeatureDialog,
showOnboardingDialog
} 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";
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 } from "../utils/dimensions";
import {
showEditTopicDialog,
showCreateTopicDialog
2021-02-16 22:28:19 +05:00
} from "../common/dialog-controller";
2021-02-16 11:49:03 +05:00
import { hashNavigate } from ".";
import EditorPlaceholder from "../components/editor/-placeholder";
2022-07-26 23:19:05 +05:00
import Editor from "../components/editor";
const hashroutes = {
"/": () => {
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": () => {
showCreateTopicDialog();
},
2022-12-26 13:13:42 +05:00
"/reminders/create": () => {
showAddReminderDialog();
},
"/reminders/:reminderId/edit": ({ reminderId }) => {
showEditReminderDialog(reminderId);
},
"/notebooks/:notebookId/topics/:topicId/edit": ({ notebookId, topicId }) => {
showEditTopicDialog(notebookId, topicId);
},
2021-07-20 12:47:11 +05:00
"/tags/create": () => {
showCreateTagDialog();
},
"/tags/:tagId/edit": ({ tagId }) => {
showEditTagDialog(tagId);
},
"/notes/create": () => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
hashNavigate("/notes/create", { addNonce: true, replace: true });
},
"/notes/create/:nonce": ({ nonce }) => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
2022-07-26 23:19:05 +05:00
return <Editor noteId={0} nonce={nonce} />;
},
"/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} />;
},
"/notes/:noteId/unlock": ({ noteId }) => {
2021-06-16 09:59:01 +05:00
closeOpenedDialog();
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
2021-02-16 11:49:03 +05:00
}}
component={<Unlock noteId={noteId} />}
/>
);
},
"/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} />;
},
2021-01-03 10:16:54 +05:00
"/vault/changePassword": () => {
Vault.changeVaultPassword();
},
"/vault/create": () => {
Vault.createVault().then((res) => {
appStore.setIsVaultCreated(res);
});
},
"/buy": () => {
showBuyDialog();
},
2021-04-07 09:28:22 +05:00
"/buy/:code": ({ code }) => {
2021-06-28 20:44:58 +05:00
showBuyDialog("monthly", code);
},
"/buy/:plan/:code": ({ plan, code }) => {
showBuyDialog(plan, code);
2021-04-07 09:28:22 +05:00
},
"/welcome": () => {
showOnboardingDialog("new");
},
"/confirmed": () => {
showFeatureDialog("confirmed");
}
};
export default hashroutes;