mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
editor: load theme from local storage on init
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user