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
web: focus item in list when switching tabs
Abdullah Atta4989dc430170
diff --git a/apps/web/patches/allotment+1.19.3.patch b/apps/web/patches/allotment+1.19.3.patchnew file mode 100644index 000000000..f66c9bbc2--- /dev/null+++ b/apps/web/patches/allotment+1.19.3.patch@@ -0,0 +1,36 @@+diff --git a/node_modules/allotment/dist/modern.mjs b/node_modules/allotment/dist/modern.mjs+index d5dbdc6..e2d9d2e 100644+--- a/node_modules/allotment/dist/modern.mjs++++ b/node_modules/allotment/dist/modern.mjs+@@ -1156,11 +1156,11 @@ class Ne extends W {+ return e < 0 || e >= this.viewItems.length ? -1 : this.viewItems[e].size;+ }+ isViewVisible(e) {+- if (e < 0 || e >= this.viewItems.length) throw new Error("Index out of bounds");++ if (e < 0 || e >= this.viewItems.length) return false;+ return this.viewItems[e].visible;+ }+ setViewVisible(e, t) {+- if (e < 0 || e >= this.viewItems.length) throw new Error("Index out of bounds");++ if (e < 0 || e >= this.viewItems.length) return;+ this.viewItems[e].setVisible(t), this.distributeEmptySpace(e), this.layoutViews(), this.saveProportions();+ }+ distributeViewSizes() {+diff --git a/node_modules/allotment/dist/module.js b/node_modules/allotment/dist/module.js+index 0de655f..f296aff 100644+--- a/node_modules/allotment/dist/module.js++++ b/node_modules/allotment/dist/module.js+@@ -1168,11 +1168,11 @@ class Ne extends W {+ return e < 0 || e >= this.viewItems.length ? -1 : this.viewItems[e].size;+ }+ isViewVisible(e) {+- if (e < 0 || e >= this.viewItems.length) throw new Error("Index out of bounds");++ if (e < 0 || e >= this.viewItems.length) return false;+ return this.viewItems[e].visible;+ }+ setViewVisible(e, t) {+- if (e < 0 || e >= this.viewItems.length) throw new Error("Index out of bounds");++ if (e < 0 || e >= this.viewItems.length) return;+ this.viewItems[e].setVisible(t), this.distributeEmptySpace(e), this.layoutViews(), this.saveProportions();+ }+ distributeViewSizes() {diff --git a/apps/web/src/common/app-events.ts b/apps/web/src/common/app-events.tsindex 7b6c007d1..ab1d44d53 100644--- a/apps/web/src/common/app-events.ts+++ b/apps/web/src/common/app-events.ts@@ -36,5 +36,7 @@ export const AppEvents = {notificationClicked: "notificationClicked",createItem: "createItem",- changeNoteTitle: "changeNoteTitle"+ changeNoteTitle: "changeNoteTitle",++ revealItemInList: "list:revealItem"};diff --git a/apps/web/src/components/cached-router/index.tsx b/apps/web/src/components/cached-router/index.tsxindex 7bb769a77..43a452668 100644--- a/apps/web/src/components/cached-router/index.tsx+++ b/apps/web/src/components/cached-router/index.tsx@@ -23,8 +23,9 @@ import { store as selectionStore } from "../../stores/selection-store";import useRoutes from "../../hooks/use-routes";import RouteContainer from "../route-container";import routes from "../../navigation/routes";-import { Flex } from "@theme-ui/components";import { isRouteResult } from "../../navigation/types";+import { Freeze } from "react-freeze";+import { Flex } from "@theme-ui/components";function CachedRouter() {const [RouteResult, location] = useRoutes(routes, {@@ -52,18 +53,19 @@ function CachedRouter() {buttons={RouteResult.buttons}>{Object.entries(cachedRoutes.current).map(([key, Component]) => (- <Flex- id={key}- key={key}- sx={{- display: key === RouteResult.key ? "flex" : "none",- flexDirection: "column",- flex: 1,- overflow: "hidden"- }}- >- <Component key={key} {...RouteResult.props} />- </Flex>+ <Freeze key={key} freeze={key !== RouteResult.key}>+ <Flex+ id={key}+ key={key}+ sx={{+ flexDirection: "column",+ flex: 1,+ overflow: "hidden"+ }}+ >+ <Component key={key} {...RouteResult.props} />+ </Flex>+ </Freeze>))}</RouteContainer>);diff --git a/apps/web/src/components/editor/action-bar.tsx b/apps/web/src/components/editor/action-bar.tsxindex e4db2d64f..2d8af954e 100644--- a/apps/web/src/components/editor/action-bar.tsx+++ b/apps/web/src/components/editor/action-bar.tsx@@ -63,6 +63,7 @@ import {useSortable} from "@dnd-kit/sortable";import { CSS } from "@dnd-kit/utilities";+import { AppEventManager, AppEvents } from "../../common/app-events";export function EditorActionBar() {const editorMargins = useEditorStore((store) => store.editorMargins);@@ -303,6 +304,13 @@ function TabStrip() {.map((s) => s.id))}+ onRevealInList={() =>+ AppEventManager.publish(+ AppEvents.revealItemInList,+ "note" in session ? session.note.id : session.id,+ true+ )+ }onPin={() => {useEditorStore.setState((state) => {// preview tabs can never be pinned.@@ -336,6 +344,7 @@ type TabProps = {onCloseToTheRight: () => void;onCloseToTheLeft: () => void;onCloseAll: () => void;+ onRevealInList: () => void;onPin: () => void;};function Tab(props: TabProps) {@@ -354,6 +363,7 @@ function Tab(props: TabProps) {onCloseOthers,onCloseToTheRight,onCloseToTheLeft,+ onRevealInList,onPin} = props;const Icon = isLocked@@ -427,6 +437,13 @@ function Tab(props: TabProps) {onClick: onCloseAll},{ type: "separator", key: "sep" },+ {+ type: "button",+ title: "Reveal in list",+ key: "reveal-in-list",+ onClick: onRevealInList+ },+ { type: "separator", key: "sep" },{type: "button",key: "keep-open",diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex b10602a03..a709e195c 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -388,7 +388,6 @@ function TiptapWrapper(editorContainer={() => {if (editorContainerRef.current) return editorContainerRef.current;const editorContainer = document.createElement("div");- editorContainer.id = "editor-container";editorContainer.classList.add("selectable");editorContainer.style.flex = "1";editorContainer.style.cursor = "text";diff --git a/apps/web/src/components/list-container/index.tsx b/apps/web/src/components/list-container/index.tsxindex 974264da2..133676168 100644--- a/apps/web/src/components/list-container/index.tsx+++ b/apps/web/src/components/list-container/index.tsx@@ -17,8 +17,14 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { forwardRef, useEffect, useRef, useState } from "react";-import { Flex, Button, Box } from "@theme-ui/components";+import {+ forwardRef,+ useEffect,+ useLayoutEffect,+ useRef,+ useState+} from "react";+import { Flex, Button } from "@theme-ui/components";import { Plus } from "../icons";import {useStore as useSelectionStore,@@ -39,6 +45,8 @@ import {} from "react-virtuoso";import { useResolvedItem } from "@notesnook/common";import { Context } from "./types";+import { AppEventManager, AppEvents } from "../../common/app-events";+import { useSessionState } from "../../hooks/use-session-state";export const CustomScrollbarsVirtualList = forwardRef<HTMLDivElement,@@ -69,7 +77,7 @@ type ListContainerProps = {onClick: () => void;};};-+var activeItem: { focus: boolean; id: string } | undefined = undefined;function ListContainer(props: ListContainerProps) {const { group, items, context, refresh, header, button, compact } = props;@@ -92,6 +100,41 @@ function ListContainer(props: ListContainerProps) {};}, []);+ useLayoutEffect(() => {+ if (activeItem) {+ items+ .ids()+ .then(+ (ids) =>+ listRef.current &&+ activeItem &&+ revealItemInList(+ listRef.current,+ activeItem.id,+ ids,+ activeItem.focus+ )+ );+ }++ const event = AppEventManager.subscribe(+ AppEvents.revealItemInList,+ (id, focus) => {+ activeItem = { id, focus };+ items+ .ids()+ .then(+ (ids) =>+ listRef.current &&+ revealItemInList(listRef.current, id, ids, focus)+ );+ }+ );+ return () => {+ event.unsubscribe();+ };+ }, [items]);+const { onFocus, onMouseDown, onKeyDown } = useKeyboardListNavigation({length: items.length,reset: () => toggleSelection(false),@@ -440,3 +483,19 @@ function waitForElement(}});}++function revealItemInList(+ list: VirtuosoHandle,+ itemId: string,+ ids: string[],+ focus: boolean+) {+ const index = ids.indexOf(itemId);+ if (index === -1) return;+ waitForElement(+ list,+ index,+ `id_${itemId}`,+ (element) => focus && element.focus()+ );+}diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex 94fe6c390..3735969a8 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -46,6 +46,7 @@ import { createJSONStorage } from "zustand/middleware";import { getFormattedHistorySessionDate } from "@notesnook/common";import { isCipher } from "@notesnook/core/dist/database/crypto";import { hashNavigate } from "../navigation";+import { AppEventManager, AppEvents } from "../common/app-events";export enum SaveState {NotSaved = -1,@@ -451,6 +452,12 @@ class EditorStore extends BaseStore<EditorStore> {this.updateSession(session.id, [session.type], {activeBlockId});++ if (session)+ AppEventManager.publish(+ AppEvents.revealItemInList,+ "note" in session ? session.note.id : session.id+ );};openDiffSession = async (noteId: string, sessionId: string) => {diff --git a/apps/web/src/views/notebook.tsx b/apps/web/src/views/notebook.tsxindex 38767ff10..5ac3b846f 100644--- a/apps/web/src/views/notebook.tsx+++ b/apps/web/src/views/notebook.tsx@@ -17,7 +17,13 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { useCallback, useEffect, useRef, useState } from "react";+import {+ useCallback,+ useEffect,+ useLayoutEffect,+ useRef,+ useState+} from "react";import { useStore as useAppStore } from "../stores/app-store";import { hashNavigate, navigate } from "../navigation";import { Button, Flex, Text } from "@theme-ui/components";@@ -67,7 +73,7 @@ function Notebook(props: NotebookProps) {const context = useNotesStore((store) => store.context);const notes = useNotesStore((store) => store.contextNotes);- useEffect(() => {+ useLayoutEffect(() => {const { context, setContext } = useNotesStore.getState();if (context &&diff --git a/apps/web/src/views/notes.tsx b/apps/web/src/views/notes.tsxindex de47cc851..230f4b6c0 100644--- a/apps/web/src/views/notes.tsx+++ b/apps/web/src/views/notes.tsx@@ -23,7 +23,6 @@ import {notesFromContext,useStore as useNotesStore} from "../stores/note-store";-import { hashNavigate, navigate } from "../navigation";import Placeholder from "../components/placeholders";import { useSearch } from "../hooks/use-search";import { db } from "../common/db";@@ -48,12 +47,6 @@ function Notes(props: NotesProps) {[context, contextNotes]);- useEffect(() => {- if (context?.type === "color" && contextNotes && contextNotes.length <= 0) {- navigate("/", { replace: true });- }- }, [context, contextNotes]);-if (!context || !contextNotes) return <Placeholder context="notes" />;return (<ListContainer