Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: open empty note by default on startup

Abdullah Atta4feb22fc1267
diff --git a/apps/web/src/app.tsx b/apps/web/src/app.tsx
index e642e712b..b1a88c382 100644
--- a/apps/web/src/app.tsx
+++ b/apps/web/src/app.tsx
@@ -26,7 +26,6 @@ import { useStore } from "./stores/app-store";
import { Toaster } from "react-hot-toast";
import NavigationMenu from "./components/navigation-menu";
import StatusBar from "./components/status-bar";
-import { EditorLoader } from "./components/loaders/editor-loader";
import { FlexScrollContainer } from "./components/scroll-container";
import CachedRouter from "./components/cached-router";
import { WebExtensionRelay } from "./utils/web-extension-relay";
@@ -38,15 +37,11 @@ import {
} from "react-resizable-panels";
import GlobalMenuWrapper from "./components/global-menu-wrapper";
import AppEffects from "./app-effects";
+import HashRouter from "./components/hash-router";
new WebExtensionRelay();
-// const GlobalMenuWrapper = React.lazy(
-// () => import("./components/global-menu-wrapper")
-// );
-// const AppEffects = React.lazy(() => import("./app-effects"));
const MobileAppEffects = React.lazy(() => import("./app-effects.mobile"));
-const HashRouter = React.lazy(() => import("./components/hash-router"));
function App() {
const isMobile = useMobile();
@@ -89,32 +84,6 @@ function App() {
export default App;
-type SuspenseLoaderProps<TComponent extends React.JSXElementConstructor<any>> =
- {
- condition: boolean;
- props?: React.ComponentProps<TComponent>;
- component: TComponent;
- fallback: JSX.Element;
- };
-
-function SuspenseLoader<TComponent extends React.JSXElementConstructor<any>>({
- condition,
- props,
- component,
- fallback
-}: SuspenseLoaderProps<TComponent>) {
- if (!condition) return fallback;
-
- const Component = component as (
- props: any
- ) => React.ReactComponentElement<any, any>;
- return (
- <Suspense fallback={IS_DESKTOP_APP ? null : fallback}>
- <Component {...props} />
- </Suspense>
- );
-}
-
type DesktopAppContentsProps = {
show: boolean;
setShow: (show: boolean) => void;
@@ -146,7 +115,6 @@ function DesktopAppContents({ show, setShow }: DesktopAppContentsProps) {
// middlePane.current?.resize(middlePaneSize);
// } else navPane.current?.expand();
// }, [isFocusMode]);
-
return (
<>
<Flex
@@ -226,9 +194,7 @@ function DesktopAppContents({ show, setShow }: DesktopAppContentsProps) {
bg: "background"
}}
>
- <Suspense fallback={<EditorLoader />}>
- <HashRouter />
- </Suspense>
+ <HashRouter />
</Flex>
</Panel>
</PanelGroup>
@@ -303,11 +269,7 @@ function MobileAppContents() {
width: "100vw"
}}
>
- <SuspenseLoader
- fallback={<EditorLoader />}
- component={HashRouter}
- condition={true}
- />
+ <HashRouter />
</Flex>
</FlexScrollContainer>
);
diff --git a/apps/web/src/components/loaders/editor-loader.tsx b/apps/web/src/components/loaders/editor-loader.tsx
deleted file mode 100644
index f3de6ac4d..000000000
--- a/apps/web/src/components/loaders/editor-loader.tsx
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-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/>.
-*/
-
-import { memo } from "react";
-import Skeleton from "react-loading-skeleton";
-import { Box, Flex, Text } from "@theme-ui/components";
-import "react-loading-skeleton/dist/skeleton.css";
-import Config from "../../utils/config";
-import { getHashLocation } from "../../hooks/use-hash-location";
-import makeMatcher from "wouter/matcher";
-import { Lock } from "../icons";
-import { strings } from "@notesnook/intl";
-
-const matcher = makeMatcher();
-const EDITOR_MARGINS = Config.get("editor:margins", true);
-export const EditorLoader = memo(function EditorLoader() {
- const location = getHashLocation();
- const [isNoteLoading] = matcher("/notes/:noteId/edit", location);
- const [isNoteLocked] = matcher("/notes/:noteId/unlock", location);
-
- if (isNoteLocked) {
- return (
- <Flex
- sx={{
- flexDirection: "column",
- flex: 1,
- alignItems: "center",
- justifyContent: "center"
- }}
- >
- <Lock size={100} sx={{ opacity: 0.2 }} />
- </Flex>
- );
- }
-
- return (
- <Flex
- sx={{
- flexDirection: "column",
- p: 2,
- py: 1
- }}
- >
- <Flex sx={{ alignItems: "end", justifyContent: "end", opacity: 0 }}>
- <Skeleton enableAnimation={false} width={76} height={33} />
- </Flex>
- <Flex
- sx={{
- alignSelf: ["stretch", "stretch", "center"],
- maxWidth: EDITOR_MARGINS ? "min(100%, 850px)" : "auto",
- px: 6,
- width: "100%",
- flexDirection: "column"
- }}
- >
- <Skeleton
- enableAnimation={false}
- height={32}
- style={{ marginTop: 5, opacity: 0 }}
- />
- <Box sx={{ mt: 1 }}>
- <Text
- sx={{
- p: 0,
- fontFamily: "heading",
- fontSize: ["1.625em", "1.625em", "2.625em"],
- fontWeight: "heading",
- width: "100%",
- color: "placeholder",
- opacity: 0.8
- }}
- >
- {isNoteLoading ? "Loading..." : strings.noteTitle()}
- </Text>
- <Skeleton
- enableAnimation={false}
- height={22}
- style={{ marginTop: 16 }}
- count={2}
- />
- <Skeleton
- enableAnimation={false}
- height={22}
- width={25}
- style={{ marginTop: 16 }}
- />
- </Box>
- </Flex>
- </Flex>
- );
-});
diff --git a/apps/web/src/hooks/use-hash-routes.tsx b/apps/web/src/hooks/use-hash-routes.tsx
index f55741a88..6393fc0b8 100644
--- a/apps/web/src/hooks/use-hash-routes.tsx
+++ b/apps/web/src/hooks/use-hash-routes.tsx
@@ -20,20 +20,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import makeMatcher from "wouter/matcher";
import useHashLocation from "./use-hash-location";
import { Params, Routes } from "../navigation/types";
+import { useEffect } from "react";
-let lastRoute: unknown | null = null;
export default function useHashRoutes<T extends string>(routes: Routes<T>) {
const [{ location, update }] = useHashLocation();
- if (!update) return lastRoute;
-
- const matcher = makeMatcher();
- for (const key in routes) {
- const [match, params] = matcher(key, location);
- if (match) {
- const route = routes[key]((params as Params<typeof key>) || {});
- if (!route) return lastRoute;
- lastRoute = route;
- return route;
+
+ useEffect(() => {
+ if (!update) return;
+
+ const matcher = makeMatcher();
+ for (const key in routes) {
+ const [match, params] = matcher(key, location);
+ if (match) {
+ const route = routes[key]((params as Params<typeof key>) || {});
+ if (!route) return;
+ }
}
- }
+ }, [update, location, routes]);
}
diff --git a/apps/web/src/navigation/hash-routes.tsx b/apps/web/src/navigation/hash-routes.tsx
index 0c83aacd2..174c6eeb6 100644
--- a/apps/web/src/navigation/hash-routes.tsx
+++ b/apps/web/src/navigation/hash-routes.tsx
@@ -36,9 +36,7 @@ import { CreateTagDialog } from "../dialogs/item-dialog";
import { OnboardingDialog } from "../dialogs/onboarding-dialog";
const hashroutes = defineRoutes({
- "/": () => {
- // return <Editor nonce={"-1"} />;
- },
+ "/": () => {},
"/email/verify": () => {
EmailVerificationDialog.show({}).then(afterAction);
},
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index e02c62b3f..da0d8b88f 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -459,7 +459,8 @@ class EditorStore extends BaseStore<EditorStore> {
openDiffSession,
activateSession,
activeSessionId,
- getSession
+ getSession,
+ newSession
} = this.get();
if (activeSessionId) {
const session = getSession(activeSessionId);
@@ -469,7 +470,7 @@ class EditorStore extends BaseStore<EditorStore> {
openDiffSession(session.note.id, session.id);
else if (session.type === "new") activateSession(session.id);
else openSession(activeSessionId);
- }
+ } else newSession();
};
updateSession = <T extends SessionType[] = SessionType[]>(