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: move usePersistentState
thecodrr3d12fc75fdf8
diff --git a/apps/web/package.json b/apps/web/package.jsonindex a3e3f7994..e75bd120c 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -16,6 +16,7 @@"react-quill": "^1.3.3","react-scripts": "3.2.0","react-simple-dropdown": "^3.2.3",+ "react-tracked": "^1.0.2","react-virtuoso": "^0.12.3","rebass": "^4.0.7","timeago-react": "^3.0.0"diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 98d2009df..f33820955 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -39,7 +39,7 @@ function getNavigationViewWidth() {}function App() {const [selectedIndex, setSelectedIndex] = useState(0);- const [hideNavigationView, setHideNavigationView] = useState(false);+ const [show, setShow] = useState(false);useEffect(() => {RootNavigator.navigate("home");}, []);@@ -67,7 +67,7 @@ function App() {return item.onClick();}if (selectedIndex === index) {- setHideNavigationView(!hideNavigationView);+ setShow(s => !s);return;}if (RootNavigator.navigate(item.key)) {@@ -84,7 +84,7 @@ function App() {<FlexclassName="RootNavigator"style={{- display: hideNavigationView ? "none" : "flex"+ display: show ? "flex" : "none"}}sx={{borderRight: "1px solid",@@ -97,7 +97,7 @@ function App() {flex="1 1 auto"//style={{ width: "362px" }}/>- {!hideNavigationView && (+ {show && (<BoxclassName="resize-handle"bg="border"diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.jsindex 4fdb5a855..ba7455847 100644--- a/apps/web/src/components/properties/index.js+++ b/apps/web/src/components/properties/index.js@@ -1,19 +1,10 @@-import React, { useState } from "react";+import React from "react";import * as Icon from "react-feather";-import { Flex, Box, Text } from "rebass";+import { Flex, Text } from "rebass";import { Input } from "@rebass/forms";import CheckBox from "../checkbox";import { PinIcon } from "../icons";--const usePersistentState = (key, def) => {- const defState = JSON.parse(window.localStorage.getItem(key) || def);- const [k, setKey] = useState(defState);- const _setKey = s => {- setKey(s);- window.localStorage.setItem(key, s);- };- return [k, _setKey];-};+import { usePersistentState } from "../../utils/hooks";const Properties = props => {const [visible, setVisible] = usePersistentState("propertiesVisible", false);diff --git a/apps/web/src/utils/hooks.js b/apps/web/src/utils/hooks.jsnew file mode 100644index 000000000..7aec1d3f1--- /dev/null+++ b/apps/web/src/utils/hooks.js@@ -0,0 +1,11 @@+import { useState } from "react";++export const usePersistentState = (key, def) => {+ const defState = JSON.parse(window.localStorage.getItem(key) || def);+ const [k, setKey] = useState(defState);+ const _setKey = s => {+ setKey(s);+ window.localStorage.setItem(key, s);+ };+ return [k, _setKey];+};diff --git a/apps/web/yarn.lock b/apps/web/yarn.lockindex 201c66b80..bf19626ca 100644--- a/apps/web/yarn.lock+++ b/apps/web/yarn.lock@@ -8722,6 +8722,11 @@ react-simple-dropdown@^3.2.3:classnames "^2.1.2"prop-types "^15.5.8"+react-tracked@^1.0.2:+ version "1.0.2"+ resolved "https://registry.yarnpkg.com/react-tracked/-/react-tracked-1.0.2.tgz#a24690b4d7b013289239051c2ca1d389ff4d52fe"+ integrity sha512-X5zvLOd0vRlzsNn6hSUrmVDE6inEEP5wOpBptTKKCLuX7UHmtPGi87qTIop9bUib8pF1qo3YQLU8T4T7m4hOBw==+react-virtuoso@^0.12.3:version "0.12.3"resolved "https://registry.yarnpkg.com/react-virtuoso/-/react-virtuoso-0.12.3.tgz#9fcb32a8dc2ba7b282a3410825c2be85783f8717"