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
feat: implement status info in editor
thecodrr09f93c3d8590
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.jsindex e23f5484d..64771e342 100644--- a/apps/web/src/components/editor/index.js+++ b/apps/web/src/components/editor/index.js@@ -1,13 +1,29 @@import React, { useEffect } from "react";import "./editor.css";import ReactQuill from "./react-quill";-import { Flex, Box } from "rebass";+import { Flex, Box, Text } from "rebass";import TitleBox from "./title-box";+import * as Icon from "react-feather";import Properties from "../properties";import { useStore, SESSION_STATES } from "../../stores/editor-store";+import { timeConverter } from "../../utils/time";+import { countWords } from "../../utils/string";+import { useTheme } from "emotion-theming";++const TextSeperator = props => {+ const theme = useTheme();+ return (+ <Text as="span" mx={1}>+ <Icon.Circle size={6} fill={theme.colors.fontTertiary} />+ </Text>+ );+};function Editor() {const title = useStore(store => store.session.title);+ const dateEdited = useStore(store => store.session.dateEdited);+ const text = useStore(store => store.session.content.text);+ const isSaving = useStore(store => store.session.isSaving);const delta = useStore(store => store.session.content.delta);const sessionState = useStore(store => store.session.state);const setSession = useStore(store => store.setSession);@@ -32,7 +48,25 @@ function Editor() {state.session.title = title;})}+ sx={{+ paddingTop: 2,+ paddingBottom: dateEdited > 0 ? 0 : 2+ }}/>+ {dateEdited > 0 && (+ <Text+ fontSize={"subBody"}+ mx={2}+ color="fontTertiary"+ sx={{ display: "flex", alignItems: "center", marginBottom: 2 }}+ >+ {timeConverter(dateEdited)}+ <TextSeperator />+ {countWords(text) + " words"}+ <TextSeperator />+ {isSaving ? "Saving" : "Saved"}+ </Text>+ )}<Box id="toolbar" display={["none", "flex", "flex"]} /><ReactQuillrefresh={sessionState === SESSION_STATES.new}diff --git a/apps/web/src/components/editor/titlebox.js b/apps/web/src/components/editor/titlebox.jsindex 27c3751cb..f6165eca1 100644--- a/apps/web/src/components/editor/titlebox.js+++ b/apps/web/src/components/editor/titlebox.js@@ -15,7 +15,7 @@ export default class TitleBox extends React.Component {}render() {- const { title, setTitle } = this.props;+ const { title, setTitle, sx } = this.props;return (<Inputref={ref => (this.inputRef = ref)}@@ -25,12 +25,12 @@ export default class TitleBox extends React.Component {fontWeight="heading"fontSize="heading"display={["none", "flex", "flex"]}+ px={2}sx={{borderWidth: 0,- ":focus": { outline: "none" }+ ":focus": { outline: "none" },+ ...sx}}- py={2}- px={2}value={title}onChange={e => {setTitle(e.target.value);diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.jsindex 9a7c0abc8..fcc039d0c 100644--- a/apps/web/src/stores/editor-store.js+++ b/apps/web/src/stores/editor-store.js@@ -10,6 +10,7 @@ const SESSION_STATES = {const DEFAULT_SESSION = {state: "",+ isSaving: false,title: "",timeout: 0,id: "",@@ -17,6 +18,7 @@ const DEFAULT_SESSION = {favorite: false,tags: [],colors: [],+ dateEdited: 0,content: {text: "",delta: {@@ -44,12 +46,16 @@ function editorStore(set, get) {favorite: note.favorite,colors: note.colors,tags: note.tags,+ dateEdited: note.dateEdited,content,state: SESSION_STATES.new};});},saveSession: function(oldSession) {+ set(state => {+ state.session.isSaving = true;+ });const { session } = get();const { title, id, content, pinned, favorite, tags, colors } = session;let note = {@@ -72,6 +78,7 @@ function editorStore(set, get) {noteStore.getState().setSelectedNote(id);}state.session.id = id;+ state.session.isSaving = false;noteStore.getState().refresh();// we update favorites only if favorite has changeddiff --git a/apps/web/src/utils/string.js b/apps/web/src/utils/string.jsindex 9953d7717..d2e7f4752 100644--- a/apps/web/src/utils/string.js+++ b/apps/web/src/utils/string.js@@ -1,3 +1,13 @@export function toTitleCase(str) {return str[0].toUpperCase() + str.substring(1);}++/**+ *+ * @param {String} str+ */+export function countWords(str) {+ str = str.trim();+ if (!str.length) return 0;+ return str.split(/\W+\S/).length + (str[str.length] === " " ? 0 : 1);+}diff --git a/apps/web/src/utils/time.js b/apps/web/src/utils/time.jsnew file mode 100644index 000000000..b6550ff22--- /dev/null+++ b/apps/web/src/utils/time.js@@ -0,0 +1,63 @@+const days = [+ "Sunday",+ "Monday",+ "Tuesday",+ "Wednesday",+ "Thursday",+ "Friday",+ "Saturday"+];+const months = [+ "Jan",+ "Feb",+ "Mar",+ "Apr",+ "May",+ "Jun",+ "Jul",+ "Aug",+ "Sep",+ "Oct",+ "Nov",+ "Dec"+];+export const timeConverter = timestamp => {+ if (!timestamp) return;+ var d = new Date(timestamp), // Convert the passed timestamp to milliseconds+ yyyy = d.getFullYear(),+ dd = ("0" + d.getDate()).slice(-2), // Add leading 0.+ currentDay = d.getDay(),+ hh = d.getHours(),+ h = hh,+ min = ("0" + d.getMinutes()).slice(-2), // Add leading 0.+ ampm = "AM",+ time;++ if (hh > 12) {+ h = hh - 12;+ ampm = "PM";+ } else if (hh === 12) {+ h = 12;+ ampm = "PM";+ } else if (hh === 0) {+ h = 12;+ }++ // ie: 2013-02-18, 8:35 AM+ time =+ days[currentDay] ++ " " ++ dd ++ " " ++ months[d.getMonth()] ++ ", " ++ yyyy ++ ", " ++ h ++ ":" ++ min ++ " " ++ ampm;++ return time;+};