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
fix: impl focus mode for editor (#78)
Abdullah Atta11a8f24247ed
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex 18baf2c94..571738792 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -15,6 +15,7 @@ import { useStore as useNotesStore } from "./stores/note-store";import { COLORS } from "./common";import { toTitleCase } from "./utils/string";import * as Icon from "react-feather";+import { useStore as useAppStore } from "./stores/app-store";const NavMenuItem = props => {const [fill, setFill] = useState();@@ -87,11 +88,17 @@ function App() {const refreshColors = useStore(store => store.refreshColors);const setSelectedContext = useNotesStore(store => store.setSelectedContext);+ const isFocusModeEnabled = appStore(store => store.isFocusModeEnabled);+useEffect(() => {RootNavigator.navigate(selectedKey);refreshColors();// eslint-disable-next-line react-hooks/exhaustive-deps}, []);++ useEffect(() => {+ isFocusModeEnabled ? setShow(false) : setShow(true);+ }, [isFocusModeEnabled]);const colors = useStore(store => store.colors);return (<ThemeProvider>@@ -101,87 +108,92 @@ function App() {height="100%"alignContent="stretch">- <Flex- flexDirection="column"- justifyContent="space-between"- sx={{- zIndex: 999,- borderRight: "1px solid",- borderRightColor: "primary",- minWidth: ["85%", 50, 50],- maxWidth: ["85%", 50, 50],- display: [isSideMenuOpen ? "flex" : "none", "flex", "flex"],- position: ["absolute", "relative", "relative"]- }}- bg={"background"}- px={0}- >- <Box+ {!isFocusModeEnabled && (+ <Flex+ flexDirection="column"+ justifyContent="space-between"sx={{- overflow: "scroll",- scrollbarWidth: "none",- //TODO: need to test this on webkit and internet explorer- "::-webkit-scrollbar": { width: 0, height: 0 },- msOverflowStyle: "none"- //"-ms-overflow-style": "none"+ zIndex: 999,+ borderRight: "1px solid",+ borderRightColor: "primary",+ minWidth: ["85%", 50, 50],+ maxWidth: ["85%", 50, 50],+ display: [isSideMenuOpen ? "flex" : "none", "flex", "flex"],+ position: ["absolute", "relative", "relative"]}}+ bg={"background"}+ px={0}>- {Object.values(routes).map((item, index) => (- <NavMenuItem- onSelected={async () => {- if (selectedKey === item.key) {- setShow(!show);- return;- }- if (RootNavigator.navigate(item.key)) {- setSelectedKey(item.key);- }- }}- key={item.key}- item={item}- selected={selectedKey === item.key}- />- ))}- {colors.map(color => {- return (+ <Box+ sx={{+ overflow: "scroll",+ scrollbarWidth: "none",+ //TODO: need to test this on webkit and internet explorer+ "::-webkit-scrollbar": { width: 0, height: 0 },+ msOverflowStyle: "none"+ //"-ms-overflow-style": "none"+ }}+ >+ {Object.values(routes).map((item, index) => (<NavMenuItemonSelected={async () => {- setSelectedKey(undefined);- setSelectedContext({ type: "color", value: color.title });- RootNavigator.navigate("color", {- title: toTitleCase(color.title),- context: { colors: [color.title] }- });+ if (selectedKey === item.key) {+ setShow(!show);+ return;+ }+ if (RootNavigator.navigate(item.key)) {+ setSelectedKey(item.key);+ }}}- key={color.title}- item={{- color: COLORS[color.title],- title: toTitleCase(color.title),- icon: Icon.Circle,- count: color.count+ key={item.key}+ item={item}+ selected={selectedKey === item.key}+ />+ ))}+ {colors.map(color => {+ return (+ <NavMenuItem+ onSelected={async () => {+ setSelectedKey(undefined);+ setSelectedContext({+ type: "color",+ value: color.title+ });+ RootNavigator.navigate("color", {+ title: toTitleCase(color.title),+ context: { colors: [color.title] }+ });+ }}+ key={color.title}+ item={{+ color: COLORS[color.title],+ title: toTitleCase(color.title),+ icon: Icon.Circle,+ count: color.count+ }}+ />+ );+ })}+ </Box>+ <Box>+ {Object.values(bottomRoutes).map((item, index) => (+ <NavMenuItem+ onSelected={async () => {+ if (item.onClick) {+ return item.onClick();+ }+ if (RootNavigator.navigate(item.key)) {+ setSelectedKey(item.key);+ }}}+ key={item.key}+ item={item}+ selected={selectedKey === item.key}/>- );- })}- </Box>- <Box>- {Object.values(bottomRoutes).map((item, index) => (- <NavMenuItem- onSelected={async () => {- if (item.onClick) {- return item.onClick();- }- if (RootNavigator.navigate(item.key)) {- setSelectedKey(item.key);- }- }}- key={item.key}- item={item}- selected={selectedKey === item.key}- />- ))}- </Box>- </Flex>+ ))}+ </Box>+ </Flex>+ )}<Flex flex="1 1 auto" flexDirection="row" alignContent="stretch" px={0}><FlexclassName="RootNavigator"diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex 5749218f1..a49f5035d 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -31,6 +31,7 @@ function Editor() {const setSession = useStore(store => store.setSession);const saveSession = useStore(store => store.saveSession);const reopenLastSession = useStore(store => store.reopenLastSession);+ const isFocusModeEnabled = useAppStore(store => store.isFocusModeEnabled);const hideProperties = useAppStore(store => store.hideProperties);useEffect(() => {@@ -47,7 +48,14 @@ function Editor() {}, [reopenLastSession]);return (- <Flex width={["0%", "0%", "100%"]} sx={{ position: "relative" }}>+ <Flex+ width={["0%", "0%", "100%"]}+ sx={{+ position: "relative",+ marginLeft: isFocusModeEnabled ? "25%" : "0px",+ marginRight: isFocusModeEnabled ? "25%" : "0px"+ }}+ ><FlexclassName="editor"flex="1 1 auto"diff --git a/apps/web/src/components/editor/titlebox.js b/apps/web/src/components/editor/titlebox.jsindex f6165eca1..b58f032b3 100644--- a/apps/web/src/components/editor/titlebox.js+++ b/apps/web/src/components/editor/titlebox.js@@ -1,11 +1,35 @@import React from "react";import "./editor.css";import { Input } from "@rebass/forms";+import { Flex } from "rebass";+import * as Icon from "react-feather";+import { store as appStore } from "../../stores/app-store";export default class TitleBox extends React.Component {+ constructor(props) {+ super(props);+ this.state = {+ iconType: Icon.PlusCircle+ };+ //this.ChangeIcon.bind(this);+ }++ ChangeIcon() {+ this.setState({+ iconType:+ this.state.iconType === Icon.PlusCircle+ ? Icon.MinusCircle+ : Icon.PlusCircle+ });+ }+inputRef;- shouldComponentUpdate(nextProps) {- return nextProps.title !== this.props.title || nextProps.shouldFocus;+ shouldComponentUpdate(nextProps, nextState) {+ return (+ nextProps.title !== this.props.title ||+ nextProps.shouldFocus ||+ nextState.iconType !== this.state.iconType+ );}componentDidUpdate() {@@ -17,25 +41,41 @@ export default class TitleBox extends React.Component {render() {const { title, setTitle, sx } = this.props;return (- <Input- ref={ref => (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);- }}- />+ <Flex>+ <Input+ ref={ref => (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);+ }}+ />+ <Flex+ alignItems="center"+ pr={3}+ onClick={() => {+ if (this.state.iconType === Icon.PlusCircle) {+ appStore.getState().enableFocusMode();+ } else {+ appStore.getState().disableFocusMode();+ }+ this.ChangeIcon();+ }}+ >+ <this.state.iconType size="30px"></this.state.iconType>+ </Flex>+ </Flex>);}}diff --git a/apps/web/src/components/properties/index.js b/apps/web/src/components/properties/index.jsindex be73107cd..a9a7521f2 100644--- a/apps/web/src/components/properties/index.js+++ b/apps/web/src/components/properties/index.js@@ -18,171 +18,170 @@ const Properties = props => {const setSession = useStore(store => store.setSession);const setColor = useStore(store => store.setColor);const setTag = useStore(store => store.setTag);+ const hideProperties = useAppStore(store => store.hideProperties);+ const showProperties = useAppStore(store => store.showProperties);+ const arePropertiesVisible = useAppStore(store => store.arePropertiesVisible);+ const isFocusModeEnabled = useAppStore(store => store.isFocusModeEnabled);+function changeState(prop, value) {setSession(state => {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={() => {- showProperties();- }}- sx={{- display: arePropertiesVisible ? "none" : "flex",- position: "absolute",- top: "50%",- right: 0,- color: "static",- borderRadius: "100px 0px 0px 100px",- cursor: "pointer",- height: [0, 0, 60]- }}- alignItems="center"- justifyContent="center"- bg="primary"- >- <Icon.ChevronLeft size={32} />- </Box>- <Box- sx={{- position: arePropertiesVisible ? "absolute" : "relative",- right: 0,- display: arePropertiesVisible ? "flex" : "none",- borderLeft: "1px solid",- borderColor: "border",- width: [0, 0, "20%"]- }}- flexDirection="column"- bg="background"- px={3}- py={0}- >- <Text- variant="title"- color="primary"- my={2}+ !isFocusModeEnabled && (+ <>+ <Box+ onClick={() => showProperties()}+ sx={{+ display: arePropertiesVisible ? "none" : "flex",+ position: "absolute",+ top: "50%",+ right: 0,+ color: "static",+ borderRadius: "100px 0px 0px 100px",+ cursor: "pointer",+ height: [0, 0, 60]+ }}alignItems="center"- justifyContent="space-between"- sx={{ display: "flex" }}+ justifyContent="center"+ bg="primary">- Properties- <Text- as="span"- onClick={() => {- hideProperties();- }}- sx={{- color: "red",- height: 24,- ":active": { color: "darkRed" }- }}- >- <Icon.X />- </Text>- </Text>- <CheckBox- checked={pinned}- icon={PinIcon}- label="Pin"- onChecked={state => changeState("pinned", state)}- />- <CheckBox- icon={Icon.Star}- checked={favorite}- label="Favorite"- onChecked={state => changeState("favorite", state)}- />- <CheckBox icon={Icon.Lock} label="Lock" onChecked={props.onLocked} />- <Flex fontSize="body" sx={{ marginBottom: 3 }} alignItems="center">- <Icon.Book size={18} />- <Text sx={{ marginLeft: 1 }}>Move to notebook</Text>- </Flex>- <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">- <Icon.Tag size={18} />- <Text sx={{ marginLeft: 1 }}>Tags:</Text>- </Flex>- <Input- variant="default"- placeholder="#tag"- sx={{ marginBottom: 2 }}- onKeyUp={event => {- if (- event.key === "Enter" ||- event.key === " " ||- event.key === ","- ) {- const value = event.target.value;- setTag(value.trim().replace(",", ""));- event.target.value = "";- }+ <Icon.ChevronLeft size={32} />+ </Box>+ <Box+ sx={{+ position: arePropertiesVisible ? "absolute" : "relative",+ right: 0,+ display: arePropertiesVisible ? "flex" : "none",+ borderLeft: "1px solid",+ borderColor: "border",+ width: [0, 0, "20%"]}}- />- <Flex- fontSize="body"- sx={{ marginBottom: 2 }}- alignItems="center"- justifyContent="flex-start"- flexWrap="wrap"+ flexDirection="column"+ bg="background"+ px={3}+ py={0}>- {tags.map(tag => (+ <Text+ variant="title"+ color="primary"+ my={2}+ alignItems="center"+ justifyContent="space-between"+ sx={{ display: "flex" }}+ >+ Properties<Text+ as="span"+ onClick={() => hideProperties()}sx={{- backgroundColor: "primary",- color: "static",- borderRadius: "default",- padding: "2px 5px 2px 5px",- marginBottom: 1,- marginRight: 1,- cursor: "pointer"- }}- onClick={() => {- setTag(tag);+ color: "red",+ height: 24,+ ":active": { color: "darkRed" }}}>- #{tag}+ <Icon.X /></Text>- ))}- </Flex>- <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">- <Icon.Octagon size={18} />- <Text sx={{ marginLeft: 1 }}>Colors:</Text>- </Flex>- <Flex flexWrap="wrap" sx={{ marginBottom: 2 }}>- {objectMap(COLORS, (label, code) => (- <Flex- sx={{ position: "relative" }}- justifyContent="center"- alignItems="center"- onClick={() => setColor(label)}- key={label}- >- <Icon.Circle- size={40}- style={{ cursor: "pointer" }}- fill={code}- strokeWidth={0}- />- {colors.includes(label) && (- <Icon.Check- style={{- position: "absolute",- cursor: "pointer",- color: "white"- }}- size={20}+ </Text>+ <CheckBox+ checked={pinned}+ icon={PinIcon}+ label="Pin"+ onChecked={state => changeState("pinned", state)}+ />+ <CheckBox+ icon={Icon.Star}+ checked={favorite}+ label="Favorite"+ onChecked={state => changeState("favorite", state)}+ />+ <CheckBox icon={Icon.Lock} label="Lock" onChecked={props.onLocked} />+ <Flex fontSize="body" sx={{ marginBottom: 3 }} alignItems="center">+ <Icon.Book size={18} />+ <Text sx={{ marginLeft: 1 }}>Move to notebook</Text>+ </Flex>+ <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">+ <Icon.Tag size={18} />+ <Text sx={{ marginLeft: 1 }}>Tags:</Text>+ </Flex>+ <Input+ variant="default"+ placeholder="#tag"+ sx={{ marginBottom: 2 }}+ onKeyUp={event => {+ if (+ event.key === "Enter" ||+ event.key === " " ||+ event.key === ","+ ) {+ const value = event.target.value;+ setTag(value.trim().replace(",", ""));+ event.target.value = "";+ }+ }}+ />+ <Flex+ fontSize="body"+ sx={{ marginBottom: 2 }}+ alignItems="center"+ justifyContent="flex-start"+ flexWrap="wrap"+ >+ {tags.map(tag => (+ <Text+ sx={{+ backgroundColor: "primary",+ color: "static",+ borderRadius: "default",+ padding: "2px 5px 2px 5px",+ marginBottom: 1,+ marginRight: 1,+ cursor: "pointer"+ }}+ onClick={() => {+ setTag(tag);+ }}+ >+ #{tag}+ </Text>+ ))}+ </Flex>+ <Flex fontSize="body" sx={{ marginBottom: 2 }} alignItems="center">+ <Icon.Octagon size={18} />+ <Text sx={{ marginLeft: 1 }}>Colors:</Text>+ </Flex>+ <Flex flexWrap="wrap" sx={{ marginBottom: 2 }}>+ {objectMap(COLORS, (label, code) => (+ <Flex+ sx={{ position: "relative" }}+ justifyContent="center"+ alignItems="center"+ onClick={() => setColor(label)}+ key={label}+ >+ <Icon.Circle+ size={40}+ style={{ cursor: "pointer" }}+ fill={code}+ strokeWidth={0}/>- )}- </Flex>- ))}- </Flex>- </Box>- </>+ {colors.includes(label) && (+ <Icon.Check+ style={{+ position: "absolute",+ cursor: "pointer",+ color: "white"+ }}+ size={20}+ />+ )}+ </Flex>+ ))}+ </Flex>+ </Box>+ </>+ ));};diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.jsindex f4fc818a0..33a5d7eff 100644--- a/apps/web/src/stores/app-store.js+++ b/apps/web/src/stores/app-store.js@@ -4,21 +4,36 @@ import { db } from "../common";function appStore(set, get) {return {isSideMenuOpen: false,+ isFocusModeEnabled: false,arePropertiesVisible: false,isSelectionMode: false,selectedItems: [],colors: [],closeSideMenu: function() {- set(state => (state.isSideMenuOpen = false));+ set(state => {+ state.isSideMenuOpen = false;+ });},openSideMenu: function() {- set(state => (state.isSideMenuOpen = true));+ set(state => {+ state.isSideMenuOpen = true;+ });},refreshColors: function() {set(state => {state.colors = db.colors.all;});},+ enableFocusMode: function() {+ set(state => {+ state.isFocusModeEnabled = true;+ });+ },+ disableFocusMode: function() {+ set(state => {+ state.isFocusModeEnabled = false;+ });+ },hideProperties: function() {set(state => {state.arePropertiesVisible = false;