A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: make unlock note UI responsive
thecodrr207a8061cb26
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex d8c1c754c..03899370f 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -23,7 +23,7 @@ function App() {const initUser = useUserStore((store) => store.init);const initNotes = useNotesStore((store) => store.init);const openLastSession = useEditorStore((store) => store.openLastSession);- const sessionState = useEditorStore((store) => store.session.state);+ const isEditorOpen = useStore((store) => store.isEditorOpen);const isMobile = useMobile();const routeResult = useRoutes(routes);@@ -48,9 +48,9 @@ function App() {useEffect(() => {if (!isMobile) return;- setShow(!sessionState);+ setShow(!isEditorOpen);// eslint-disable-next-line react-hooks/exhaustive-deps- }, [sessionState, isMobile]);+ }, [isEditorOpen, isMobile]);useEffect(() => {return () => {diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex 40a4e2ef7..ffdbde68f 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -16,6 +16,8 @@ import Header from "./header";import { useHashParam } from "../../utils/useHashParam";import SplitEditor from "../spliteditor";import Unlock from "../unlock";+import RouteContainer from "../route-container";+import useMobile from "../../utils/use-mobile";function Editor() {console.log("rendering editor");@@ -26,6 +28,7 @@ function Editor() {const updateWordCount = useStore((store) => store.updateWordCount);const init = useStore((store) => store.init);const isFocusMode = useAppStore((store) => store.isFocusMode);+ const isMobile = useMobile();const isTrial = useUserStore((store) => store.user.notesnook?.subscription?.isTrial);@@ -66,7 +69,13 @@ function Editor() {}}, [sessionState, quillRef]);- if (unlock) return <Unlock noteId={unlock} />;+ if (unlock)+ return (+ <RouteContainer+ onlyBackButton={isMobile}+ route={<Unlock noteId={unlock} />}+ />+ );if (diff) return <SplitEditor diffId={diff} />;return (<Animated.Flexdiff --git a/apps/web/src/components/route-container/index.js b/apps/web/src/components/route-container/index.jsindex fb45d3a62..a5908030d 100644--- a/apps/web/src/components/route-container/index.js+++ b/apps/web/src/components/route-container/index.js@@ -7,7 +7,7 @@ import { useStore as useSelectionStore } from "../../stores/selection-store";import { SELECTION_OPTIONS_MAP } from "../../common";function RouteContainer(props) {- const { type, route, canGoBack, title, subtitle } = props;+ const { type, route, canGoBack, title, subtitle, onlyBackButton } = props;return (<Animated.Flexsx={{ overflow: "hidden" }}@@ -22,6 +22,7 @@ function RouteContainer(props) {canGoBack={canGoBack}title={title}subtitle={subtitle}+ onlyBackButton={onlyBackButton}selectionOptions={SELECTION_OPTIONS_MAP[type]}/>{route}@@ -32,16 +33,22 @@ function RouteContainer(props) {export default RouteContainer;function Header(props) {- const { title, subtitle, canGoBack, selectionOptions } = props;+ const {+ title,+ subtitle,+ canGoBack,+ selectionOptions,+ onlyBackButton,+ } = props;const toggleSideMenu = useStore((store) => store.toggleSideMenu);- if (!title && !subtitle) return null;+ if (!onlyBackButton && !title && !subtitle) return null;return (<Flex mx={2} flexDirection="column"><Flex alignItems="center" justifyContent="space-between"><Flex alignItems="center" py={2}>- {canGoBack && (+ {(canGoBack || onlyBackButton) && (<BoxonClick={() => window.history.back()}ml={-2}@@ -56,7 +63,7 @@ function Header(props) {sx={{ml: 0,mr: 4,- display: ["block", "none", "none"],+ display: [onlyBackButton ? "none" : "block", "none", "none"],}}size={28}/>diff --git a/apps/web/src/components/unlock/index.js b/apps/web/src/components/unlock/index.jsindex 04cacffe1..89243ed38 100644--- a/apps/web/src/components/unlock/index.js+++ b/apps/web/src/components/unlock/index.js@@ -1,15 +1,17 @@-import React, { useRef, useState, useCallback } from "react";+import React, { useRef, useState, useCallback, useEffect } from "react";import { Flex, Text, Button } from "rebass";import { Input } from "@rebass/forms";import * as Icon from "../icons";import { db } from "../../common";import { useStore as useEditorStore } from "../../stores/editor-store";+import { useStore as useAppStore } from "../../stores/app-store";function Unlock(props) {const { noteId } = props;const passwordRef = useRef();const [isWrong, setIsWrong] = useState(false);const openLockedSession = useEditorStore((store) => store.openLockedSession);+ const setIsEditorOpen = useAppStore((store) => store.setIsEditorOpen);const submit = useCallback(async () => {const password = passwordRef.current.value;@@ -23,14 +25,22 @@ function Unlock(props) {}}, [setIsWrong, noteId, openLockedSession]);+ useEffect(() => {+ setIsEditorOpen(true);+ }, [setIsEditorOpen]);+return (<Flex- width={["0%", "0%", "100%"]}+ width={"100%"}flex="1 1 auto"justifyContent="center"alignItems="center">- <Flex flexDirection="column" width="30%" alignItems="center">+ <Flex+ flexDirection="column"+ width={["95%", "95%", "30%"]}+ alignItems="center"+ ><Flex justifyContent="center" alignItems="center"><Icon.Unlock size={48} color="text" /><Text variant="heading" ml={2} fontSize={48}>diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.jsindex f99d09092..be0c16eee 100644--- a/apps/web/src/stores/app-store.js+++ b/apps/web/src/stores/app-store.js@@ -11,6 +11,7 @@ class AppStore extends BaseStore {// default stateisSideMenuOpen = false;isFocusMode = false;+ isEditorOpen = false;colors = [];globalMenu = { items: [], data: {} };@@ -42,6 +43,10 @@ class AppStore extends BaseStore {setGlobalMenu = (items, data) => {this.set((state) => (state.globalMenu = { items, data }));};++ setIsEditorOpen = (toggleState) => {+ this.set((state) => (state.isEditorOpen = toggleState));+ };}/**diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 768848139..4be36059b 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -7,7 +7,7 @@ import BaseStore from ".";import { isMobile } from "../utils/dimensions";import { getHashParam, setHashParam } from "../utils/useHashParam";-const SESSION_STATES = { stale: "stale", new: "new" };+const SESSION_STATES = { stale: "stale", new: "new", locked: "locked" };const DEFAULT_SESSION = {notebook: undefined,state: undefined,@@ -37,7 +37,7 @@ class EditorStore extends BaseStore {window.addEventListener("hashchange", async () => {const note = getHashParam("note");- if (isMobile() && !note && this.get().session.id) {+ if (isMobile() && !note && appStore.get().isEditorOpen) {return this.clearSession();}@@ -67,6 +67,7 @@ class EditorStore extends BaseStore {state: SESSION_STATES.new,};});+ appStore.setIsEditorOpen(true);};openSession = async (noteId) => {@@ -95,6 +96,7 @@ class EditorStore extends BaseStore {state: SESSION_STATES.new,};});+ appStore.setIsEditorOpen(true);};saveSession = (oldSession) => {@@ -138,6 +140,7 @@ class EditorStore extends BaseStore {};newSession = (context = {}) => {+ appStore.setIsEditorOpen(true);this.set(function (state) {state.session = {...DEFAULT_SESSION,@@ -151,6 +154,7 @@ class EditorStore extends BaseStore {};clearSession = () => {+ appStore.setIsEditorOpen(false);this.set(function (state) {state.session = {...DEFAULT_SESSION,