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: sticky statusbar
Ammar Ahmed75561ed03196
diff --git a/packages/editor-mobile/src/components/statusbar.tsx b/packages/editor-mobile/src/components/statusbar.tsxindex c32254566..56abbe2f8 100644--- a/packages/editor-mobile/src/components/statusbar.tsx+++ b/packages/editor-mobile/src/components/statusbar.tsx@@ -1,11 +1,20 @@-import { Editor } from "@tiptap/react";-import { useRef, useState } from "react";+import { Editor } from "notesnook-editor/dist/types";+import React, { RefObject, useEffect, useRef, useState } from "react";-export default function StatusBar({ editor }: { editor: Editor | null }) {+export default function StatusBar({+ editor,+ container,+}: {+ editor: Editor | null;+ container: RefObject<HTMLDivElement>;+}) {const [status, setStatus] = useState({date: "",saved: "",});+ const [sticky, setSticky] = useState(false);+ const prevScroll = useRef(0);+ const lastStickyChangeTime = useRef(0);const words = editor?.storage?.characterCount?.words() + " words";const statusBar = useRef({set: setStatus,@@ -13,6 +22,27 @@ export default function StatusBar({ editor }: { editor: Editor | null }) {//@ts-ignoreglobalThis.statusBar = statusBar;+ const onScroll = React.useCallback((event) => {+ //@ts-ignore+ const currentOffset = event.target.scrollTop;+ if (Date.now() - lastStickyChangeTime.current < 300) return;+ if (currentOffset > prevScroll.current) {+ setSticky(false);+ } else {+ setSticky(true);+ }+ lastStickyChangeTime.current = Date.now();+ prevScroll.current = currentOffset;+ }, []);++ useEffect(() => {+ const node = container.current;+ node?.addEventListener("scroll", onScroll);+ return () => {+ node?.removeEventListener("scroll", onScroll);+ };+ }, [onScroll, container]);+const paragraphStyle = {marginTop: 0,marginBottom: 0,@@ -26,9 +56,13 @@ export default function StatusBar({ editor }: { editor: Editor | null }) {style={{flexDirection: "row",display: "flex",- height: 15,+ height: sticky ? 20 : 15,paddingRight: 12,paddingLeft: 12,+ position: sticky ? "sticky" : "relative",+ top: 0,+ backgroundColor: "var(--nn_bg)",+ zIndex: 1,}}><p style={paragraphStyle}>{words}</p>