Skip to content

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

feat: auto hide properties when editor is focused (#67)

Muhammad Alibb3dba1d4b4c
diff --git a/apps/web/src/components/editor/react-quill.js b/apps/web/src/components/editor/react-quill.js
index d8f9d720d..c52d19f03 100644
--- a/apps/web/src/components/editor/react-quill.js
+++ b/apps/web/src/components/editor/react-quill.js
@@ -3,6 +3,7 @@ import Quill from "quill";
import "quill/dist/quill.snow.css";
import MarkdownShortcuts from "./modules/markdown";
import MagicUrl from "quill-magic-url";
+import { store as useAppStore } from "../../stores/app-store";
Quill.register("modules/markdownShortcuts", MarkdownShortcuts);
Quill.register("modules/magicUrl", MagicUrl);
@@ -105,9 +106,15 @@ export default class ReactQuill extends Component {
if (source === "api") return;
this.props.onChange(this.quill);
};
-
render() {
- console.log("rendering + ", this.props.refresh);
- return <pre id="quill" />;
+ return (
+ <pre
+ id="quill"
+ onFocus={() => {
+ //hideProperties();
+ useAppStore.getState().hideProperties();
+ }}
+ />
+ );
}
}
diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.js
index 06d68870f..16ced94fc 100644
--- a/apps/web/src/components/properties/index.js
+++ b/apps/web/src/components/properties/index.js
@@ -8,9 +8,9 @@ import { usePersistentState } from "../../utils/hooks";
import { useStore } from "../../stores/editor-store";
import { COLORS } from "../../common";
import { objectMap } from "../../utils/object";
+import { useStore as useAppStore } from "../../stores/app-store";
const Properties = props => {
- const [visible, setVisible] = usePersistentState("propertiesVisible", false);
const pinned = useStore(store => store.session.pinned);
const favorite = useStore(store => store.session.favorite);
const colors = useStore(store => store.session.colors);
@@ -24,12 +24,18 @@ const Properties = props => {
state.session[prop] = value;
});
}
+ const hideProperties = useAppStore(store => store.hideProperties);
+ const showProperties = useAppStore(store => store.showProperties);
+ const arePropertiesVisible = useAppStore(store => store.arePropertiesVisible);
+
return (
<>
<Box
- onClick={() => setVisible(true)}
+ onClick={() => {
+ showProperties();
+ }}
sx={{
- display: visible ? "none" : "flex",
+ display: arePropertiesVisible ? "none" : "flex",
position: "absolute",
top: "50%",
right: 0,
@@ -46,9 +52,9 @@ const Properties = props => {
</Box>
<Box
sx={{
- position: visible ? "absolute" : "relative",
+ position: arePropertiesVisible ? "absolute" : "relative",
right: 0,
- display: visible ? "flex" : "none",
+ display: arePropertiesVisible ? "flex" : "none",
borderLeft: "1px solid",
borderColor: "border",
width: [0, 0, "20%"]
@@ -69,7 +75,9 @@ const Properties = props => {
Properties
<Text
as="span"
- onClick={() => setVisible(false)}
+ onClick={() => {
+ hideProperties();
+ }}
sx={{
color: "red",
height: 24,
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 62da74dc6..618255ffc 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -4,6 +4,7 @@ import { db } from "../common";
function appStore(set, get) {
return {
isSideMenuOpen: false,
+ arePropertiesVisible: false,
isSelectionMode: false,
selectedItems: [],
colors: [],
@@ -18,6 +19,15 @@ function appStore(set, get) {
state.colors = db.colors.all;
});
},
+ hideProperties: function() {
+ set(state => {
+ state.propState = false;
+ });
+ },
+ showProperties: function() {
+ set(state => {
+ state.propState = true;
+ });
enterSelectionMode: function() {
set(state => {
state.isSelectionMode = true;