From 175b4ebf041dd421d663b7366b8d13d929b31438 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Sun, 5 Apr 2020 09:49:12 +0500 Subject: [PATCH] feat: reenable properties --- apps/web/src/components/editor/header.js | 4 ++ apps/web/src/components/editor/index.js | 2 + apps/web/src/components/icons/index.js | 4 +- apps/web/src/components/properties/index.js | 49 +++++++++++---------- apps/web/src/stores/editor-store.js | 7 +++ 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/apps/web/src/components/editor/header.js b/apps/web/src/components/editor/header.js index c74cd8ac2..0192e091a 100644 --- a/apps/web/src/components/editor/header.js +++ b/apps/web/src/components/editor/header.js @@ -26,6 +26,7 @@ function Header() { const setSession = useStore((store) => store.setSession); const isFocusMode = useAppStore((store) => store.isFocusMode); const toggleFocusMode = useAppStore((store) => store.toggleFocusMode); + const toggleProperties = useStore((store) => store.toggleProperties); return ( @@ -82,6 +83,9 @@ function Header() { )} + toggleProperties()} pr={3}> + + ); } diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js index 3d0725fac..822e8143f 100644 --- a/apps/web/src/components/editor/index.js +++ b/apps/web/src/components/editor/index.js @@ -16,6 +16,8 @@ function Editor() { const setSession = useStore((store) => store.setSession); const saveSession = useStore((store) => store.saveSession); const isFocusMode = useAppStore((store) => store.isFocusMode); + const arePropertiesVisible = useStore((store) => store.arePropertiesVisible); + const toggleProperties = useStore((store) => store.toggleProperties); const quillRef = useRef(); useEffect(() => { diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js index eff48011f..108360a3c 100644 --- a/apps/web/src/components/icons/index.js +++ b/apps/web/src/components/icons/index.js @@ -17,7 +17,7 @@ function Icon({ name, size = 24, color = "icon", rotate }) { } function createIcon(name) { - return function(props) { + return function (props) { return ( store.session.pinned); - const favorite = useStore(store => store.session.favorite); - const locked = useStore(store => store.session.locked); - const colors = useStore(store => store.session.colors); - const tags = useStore(store => store.session.tags); + const pinned = useStore((store) => store.session.pinned); + const favorite = useStore((store) => store.session.favorite); + const locked = useStore((store) => store.session.locked); + const colors = useStore((store) => store.session.colors); + const tags = useStore((store) => store.session.tags); - const setSession = useStore(store => store.setSession); - const setColor = useStore(store => store.setColor); - const setTag = useStore(store => store.setTag); - const toggleLocked = useStore(store => store.toggleLocked); - const hideProperties = useAppStore(store => store.hideProperties); + const setSession = useStore((store) => store.setSession); + const setColor = useStore((store) => store.setColor); + const setTag = useStore((store) => store.setTag); + const toggleLocked = useStore((store) => store.toggleLocked); + //const hideProperties = useAppStore((store) => store.hideProperties); //const showProperties = useAppStore(store => store.showProperties); - const arePropertiesVisible = useAppStore(store => store.arePropertiesVisible); - const isFocusMode = useAppStore(store => store.isFocusMode); + const arePropertiesVisible = useStore((store) => store.arePropertiesVisible); + const toggleProperties = useStore((store) => store.toggleProperties); + const isFocusMode = useAppStore((store) => store.isFocusMode); function changeState(prop, value) { - setSession(state => { + setSession((state) => { state.session[prop] = value; }); } @@ -40,7 +41,7 @@ function Properties() { duration: 0.5, bounceDamping: 1, bounceStiffness: 1, - ease: "easeOut" + ease: "easeOut", }} initial={false} style={{ @@ -48,7 +49,7 @@ function Properties() { right: 0, display: "flex", width: 300, - height: "100%" + height: "100%", }} > hideProperties()} + onClick={() => toggleProperties()} sx={{ color: "red", height: 24, - ":active": { color: "darkRed" } + ":active": { color: "darkRed" }, }} > @@ -92,13 +93,13 @@ function Properties() { checked={pinned} icon={Icon.Pin} label="Pin" - onChecked={state => changeState("pinned", state)} + onChecked={(state) => changeState("pinned", state)} /> changeState("favorite", state)} + onChecked={(state) => changeState("favorite", state)} /> { + onKeyUp={(event) => { if ( event.key === "Enter" || event.key === " " || @@ -141,7 +142,7 @@ function Properties() { justifyContent="flex-start" flexWrap="wrap" > - {tags.map(tag => ( + {tags.map((tag) => ( { setTag(tag); @@ -184,7 +185,7 @@ function Properties() { style={{ position: "absolute", cursor: "pointer", - color: "white" + color: "white", }} size={20} /> diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js index 3afdbf530..0fd749bd3 100644 --- a/apps/web/src/stores/editor-store.js +++ b/apps/web/src/stores/editor-store.js @@ -31,6 +31,7 @@ const DEFAULT_SESSION = { }; class EditorStore extends BaseStore { session = DEFAULT_SESSION; + arePropertiesVisible = false; openLastSession = async () => { const id = localStorage.getItem("lastOpenedNote"); @@ -137,6 +138,12 @@ class EditorStore extends BaseStore { this._setTagOrColor("tag", tag); }; + toggleProperties = () => { + this.set( + (state) => (state.arePropertiesVisible = !state.arePropertiesVisible) + ); + }; + /** * @private internal * @param {Boolean} isLocked