From ed90588101fcac08ab9c44bfefc119f0839d71fa Mon Sep 17 00:00:00 2001 From: thecodrr Date: Sat, 4 Apr 2020 15:20:21 +0500 Subject: [PATCH] ui: improve focus mode transition --- apps/web/src/components/editor/header.js | 97 +++++++++++++--------- apps/web/src/components/editor/index.js | 6 +- apps/web/src/components/editor/titlebox.js | 67 +++++---------- 3 files changed, 82 insertions(+), 88 deletions(-) diff --git a/apps/web/src/components/editor/header.js b/apps/web/src/components/editor/header.js index 7fa193f1e..c74cd8ac2 100644 --- a/apps/web/src/components/editor/header.js +++ b/apps/web/src/components/editor/header.js @@ -1,6 +1,8 @@ import React from "react"; import "./editor.css"; -import { Text } from "rebass"; +import { Flex, Text } from "rebass"; +import * as Icon from "../icons"; +import { useStore as useAppStore } from "../../stores/app-store"; import TitleBox from "./title-box"; import { useStore, SESSION_STATES } from "../../stores/editor-store"; import { timeConverter } from "../../utils/time"; @@ -22,48 +24,65 @@ function Header() { const isSaving = useStore((store) => store.session.isSaving); const sessionState = useStore((store) => store.session.state); const setSession = useStore((store) => store.setSession); + const isFocusMode = useAppStore((store) => store.isFocusMode); + const toggleFocusMode = useAppStore((store) => store.toggleFocusMode); return ( - <> - - setSession((state) => { - state.session.title = title; - }) - } - sx={{ - paddingTop: 2, - paddingBottom: 0, - }} - /> - + + + setSession((state) => { + state.session.title = title; + }) + } + sx={{ + paddingTop: 2, + paddingBottom: 0, + }} + /> + + {dateEdited > 0 ? ( + <> + {timeConverter(dateEdited)} + + + ) : null} + {text.length > 0 ? ( + <> + {countWords(text) + " words"} + + + ) : null} + {id && id.length > 0 ? <>{isSaving ? "Saving" : "Saved"} : null} + + + { + toggleFocusMode(); }} > - {dateEdited > 0 ? ( - <> - {timeConverter(dateEdited)} - - - ) : null} - {text.length > 0 ? ( - <> - {countWords(text) + " words"} - - - ) : null} - {id && id.length > 0 ? <>{isSaving ? "Saving" : "Saved"} : null} - - + {isFocusMode ? ( + + ) : ( + + )} + + ); } export default Header; diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js index be672c7cc..3d0725fac 100644 --- a/apps/web/src/components/editor/index.js +++ b/apps/web/src/components/editor/index.js @@ -30,14 +30,14 @@ function Editor() { return ( diff --git a/apps/web/src/components/editor/titlebox.js b/apps/web/src/components/editor/titlebox.js index 92dafa139..5ca3a88d0 100644 --- a/apps/web/src/components/editor/titlebox.js +++ b/apps/web/src/components/editor/titlebox.js @@ -1,20 +1,11 @@ import React from "react"; import "./editor.css"; import { Input } from "@rebass/forms"; -import { Flex } from "rebass"; -import * as Icon from "../icons"; -import { store as appStore } from "../../stores/app-store"; class TitleBox extends React.Component { - state = { isFocusMode: false }; - inputRef; - shouldComponentUpdate(nextProps, nextState) { - return ( - nextProps.title !== this.props.title || - nextProps.shouldFocus || - nextState.isFocusMode !== this.state.isFocusMode - ); + shouldComponentUpdate(nextProps) { + return nextProps.title !== this.props.title || nextProps.shouldFocus; } componentDidUpdate() { @@ -26,41 +17,25 @@ class TitleBox extends React.Component { render() { const { title, setTitle, sx } = this.props; return ( - - (this.inputRef = ref)} - maxLength={120} - placeholder="Untitled" - fontFamily="heading" - fontWeight="heading" - fontSize="heading" - display={["none", "flex", "flex"]} - px={2} - sx={{ - borderWidth: 0, - ":focus": { outline: "none" }, - ...sx - }} - value={title} - onChange={e => { - setTitle(e.target.value); - }} - /> - { - appStore.toggleFocusMode(); - this.setState({ isFocusMode: !this.state.isFocusMode }); - }} - > - {this.state.isFocusMode ? ( - - ) : ( - - )} - - + (this.inputRef = ref)} + maxLength={120} + placeholder="Untitled" + fontFamily="heading" + fontWeight="heading" + fontSize="heading" + display={["none", "flex", "flex"]} + px={2} + sx={{ + borderWidth: 0, + ":focus": { outline: "none" }, + ...sx, + }} + value={title} + onChange={(e) => { + setTitle(e.target.value); + }} + /> ); } }