Skip to content

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

editor: load theme from local storage on init

ammarahm-ed3831b9409ec7
diff --git a/packages/editor-mobile/src/App.tsx b/packages/editor-mobile/src/App.tsx
index be01f6621..eb86ecea4 100644
--- a/packages/editor-mobile/src/App.tsx
+++ b/packages/editor-mobile/src/App.tsx
@@ -27,6 +27,12 @@ import Tiptap from "./components/editor";
import { EmotionEditorTheme } from "./theme-factory";
import { Global, css } from "@emotion/react";
import { useMemo } from "react";
+import { getTheme } from "./utils";
+
+const currentTheme = getTheme();
+if (currentTheme) {
+ useThemeEngineStore.getState().setTheme(currentTheme);
+}
function App(): JSX.Element {
return (
diff --git a/packages/editor-mobile/src/hooks/useEditorController.ts b/packages/editor-mobile/src/hooks/useEditorController.ts
index a91498aa3..fdbb7872e 100644
--- a/packages/editor-mobile/src/hooks/useEditorController.ts
+++ b/packages/editor-mobile/src/hooks/useEditorController.ts
@@ -18,6 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Editor } from "@notesnook/editor";
+import {
+ ThemeDefinition,
+ useThemeColors,
+ useThemeEngineStore
+} from "@notesnook/theme";
import {
MutableRefObject,
useCallback,
@@ -25,8 +30,7 @@ import {
useRef,
useState
} from "react";
-import { EventTypes, isReactNative, post } from "../utils";
-import { useThemeColors, useThemeEngineStore } from "@notesnook/theme";
+import { EventTypes, isReactNative, post, saveTheme } from "../utils";
import { injectCss, transform } from "../utils/css";
type Attachment = {
@@ -190,6 +194,9 @@ export function useEditorController(update: () => void): EditorController {
break;
case "native:theme":
setTheme(message.value);
+ setTimeout(() => {
+ saveTheme(message.value as ThemeDefinition);
+ });
break;
case "native:title":
setTitle(value);
diff --git a/packages/editor-mobile/src/utils/index.ts b/packages/editor-mobile/src/utils/index.ts
index 353009dc8..eba14ae60 100644
--- a/packages/editor-mobile/src/utils/index.ts
+++ b/packages/editor-mobile/src/utils/index.ts
@@ -21,6 +21,7 @@ import { ToolbarGroupDefinition } from "@notesnook/editor";
import { Editor } from "@notesnook/editor";
import { Dispatch, MutableRefObject, RefObject, SetStateAction } from "react";
import { useEditorController } from "../hooks/useEditorController";
+import { ThemeDefinition } from "@notesnook/theme";
export type SafeAreaType = {
top: number;
@@ -191,3 +192,15 @@ export function post<T extends keyof typeof EventTypes>(
globalThis.logger = logger;
globalThis.post = post;
+
+export function saveTheme(theme: ThemeDefinition) {
+ localStorage.setItem("editor-theme", JSON.stringify(theme));
+}
+
+export function getTheme() {
+ const json = localStorage.getItem("editor-theme");
+ if (json) {
+ return JSON.parse(json) as ThemeDefinition;
+ }
+ return undefined;
+}