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
refactor: use useSettings hook through props in header
Ammar Ahmed2e4d3ef350d7
diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsxindex 46849cdfa..de3a9e275 100644--- a/packages/editor-mobile/src/components/editor.tsx+++ b/packages/editor-mobile/src/components/editor.tsx@@ -122,7 +122,7 @@ const Tiptap = () => {marginBottom: "5px",}}>- <Header noHeader={initialProps.noHeader || false} />+ <Header settings={settings} noHeader={initialProps.noHeader || false} /><divonScroll={controller.scroll}ref={containerRef}@@ -165,7 +165,7 @@ const Tiptap = () => {theme={toolbarTheme}editor={editor}location="bottom"- tools={settings.tools}+ tools={[...settings.tools]}/></div>)}diff --git a/packages/editor-mobile/src/components/header.tsx b/packages/editor-mobile/src/components/header.tsxindex a33c7e328..ee03eaf4e 100644--- a/packages/editor-mobile/src/components/header.tsx+++ b/packages/editor-mobile/src/components/header.tsx@@ -3,10 +3,10 @@ import CloudUploadOutlineIcon from "mdi-react/CloudUploadOutlineIcon";import CrownIcon from "mdi-react/CrownIcon";import DotsHorizontalIcon from "mdi-react/DotsHorizontalIcon";import MagnifyIcon from "mdi-react/MagnifyIcon";-import React, { useEffect } from "react";+import React from "react";import { useSafeArea } from "../hooks/useSafeArea";import { useSettings } from "../hooks/useSettings";-import { EventTypes } from "../utils";+import { EventTypes, Settings } from "../utils";import styles from "./styles.module.css";const Button = ({@@ -42,9 +42,14 @@ const Button = ({};export default React.memo(- function Header({ noHeader }: { noHeader: boolean }) {+ function Header({+ noHeader,+ settings,+ }: {+ noHeader: boolean;+ settings: Settings;+ }) {const insets = useSafeArea();- const settings = useSettings();return (<divstyle={{@@ -175,5 +180,7 @@ export default React.memo(</div>);},- (prev, next) => prev.noHeader !== next.noHeader+ (prev, next) =>+ prev.noHeader !== next.noHeader ||+ prev.settings.premium !== next.settings.premium);diff --git a/packages/editor-mobile/src/hooks/useSettings.ts b/packages/editor-mobile/src/hooks/useSettings.tsindex cef612fd1..48c3faff0 100644--- a/packages/editor-mobile/src/hooks/useSettings.ts+++ b/packages/editor-mobile/src/hooks/useSettings.ts@@ -1,4 +1,5 @@-import { useState } from "react";+import { DEFAULT_TOOLS } from "notesnook-editor";+import { useEffect, useState } from "react";const settingsJson = localStorage.getItem("editorSettings");const initialState = {@@ -6,36 +7,7 @@ const initialState = {fullscreen: false,deviceMode: "mobile",premium: false,- tools: [- [- "insertBlock",- "tableSettings",- "imageSettings",- "embedSettings",- "attachmentSettings",- "linkSettings",- "codeRemove",- ],- [- "bold",- "italic",- "underline",- [- "strikethrough",- "code",- "subscript",- "superscript",- "highlight",- "textColor",- ],- ],- ["fontSize"],- ["headings", "fontFamily"],- ["numberedList", "bulletList"],- ["addLink"],- ["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],- ["clearformatting"],- ],+ tools: DEFAULT_TOOLS,noHeader: false,noToolbar: false,};@@ -43,19 +15,23 @@ const initialState = {global.settingsController = {update: (settings) => {const nextSettings = { ...settingsController.previous, ...settings };- if (settingsController.set) settingsController.set(nextSettings);+ if (global.settingsController.set)+ global.settingsController.set(nextSettings);if (settings) {localStorage.setItem("editorSettings", JSON.stringify(nextSettings));} else {localStorage.removeItem("editorSettings");}- settingsController.previous = nextSettings;+ settingsController.previous = { ...nextSettings };},- previous: settingsJson ? JSON.parse(settingsJson) : initialState,+ previous: settingsJson ? JSON.parse(settingsJson) : { ...initialState },};export const useSettings = () => {- const [settings, setSettings] = useState(global.settingsController.previous);+ const [settings, setSettings] = useState({+ ...global.settingsController.previous,+ });global.settingsController.set = setSettings;+return settings;};