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
mobile: fix app state
Ammar Ahmed8b207b47dd92
diff --git a/apps/mobile/app/components/tabs/index.tsx b/apps/mobile/app/components/tabs/index.tsxindex f4f45b506..11d58c90b 100644--- a/apps/mobile/app/components/tabs/index.tsx+++ b/apps/mobile/app/components/tabs/index.tsx@@ -42,6 +42,7 @@ import { eSendEvent } from "../../services/event-manager";import { useSettingStore } from "../../stores/use-setting-store";import { eClearEditor } from "../../utils/events";import { useSideBarDraggingStore } from "../side-menu/dragging-store";+import { useTabStore } from "../../screens/editor/tiptap/use-tab-store";interface TabProps extends ViewProps {dimensions: { width: number; height: number };@@ -85,7 +86,9 @@ export const FluidTabs = forwardRef<TabsRef, TabProps>(function FluidTabs();const translateX = useSharedValue(widths- ? appState && !appState?.movedAway+ ? appState &&+ appState?.movedAway === false &&+ useTabStore.getState().getCurrentNoteId()? widths.sidebar + widths.list: widths.sidebar: 0@@ -121,9 +124,9 @@ export const FluidTabs = forwardRef<TabsRef, TabProps>(function FluidTabs(} else {if (prevWidths.current?.sidebar !== widths.sidebar) {translateX.value =- !appState || (appState && appState?.movedAway)- ? widths.sidebar- : editorPosition;+ appState && appState?.movedAway === false+ ? editorPosition+ : widths.sidebar;if (translateX.value === editorPosition) {onChangeTab?.({ i: 2, from: 1 });}diff --git a/apps/mobile/app/navigation/tabs-holder.js b/apps/mobile/app/navigation/tabs-holder.jsindex fc0040fc3..fa7237c03 100644--- a/apps/mobile/app/navigation/tabs-holder.js+++ b/apps/mobile/app/navigation/tabs-holder.js@@ -71,10 +71,9 @@ import {import { editorRef, tabBarRef } from "../utils/global-refs";import { sleep } from "../utils/time";import { NavigationStack } from "./navigation-stack";-import { changeSystemBarColors } from "../stores/use-theme-store";const _TabsHolder = () => {- const { colors, isDark } = useThemeColors();+ const { colors } = useThemeColors();const deviceMode = useSettingStore((state) => state.deviceMode);const setFullscreen = useSettingStore((state) => state.setFullscreen);const fullscreen = useSettingStore((state) => state.fullscreen);@@ -270,33 +269,29 @@ const _TabsHolder = () => {}const state = getAppState();-- setTimeout(() => {- switch (current) {- case "tablet":- tabBarRef.current?.goToIndex(0, false);- break;- case "smallTablet":- if (!fullscreen) {- tabBarRef.current?.closeDrawer(false);- } else {- tabBarRef.current?.openDrawer(false);- }- break;- case "mobile":- if (- (state &&- !state?.movedAway &&- useTabStore.getState().getCurrentNoteId()) ||- editorState().movedAway === false- ) {- tabBarRef.current?.goToIndex(2, false);- } else {- tabBarRef.current?.goToIndex(1, false);- }- break;- }- }, 1000);+ switch (current) {+ case "tablet":+ tabBarRef.current?.goToIndex(0, false);+ break;+ case "smallTablet":+ if (!fullscreen) {+ tabBarRef.current?.closeDrawer(false);+ } else {+ tabBarRef.current?.openDrawer(false);+ }+ break;+ case "mobile":+ if (+ state &&+ editorState().movedAway === false &&+ useTabStore.getState().getCurrentNoteId()+ ) {+ tabBarRef.current?.goToIndex(2, false);+ } else {+ tabBarRef.current?.goToIndex(1, false);+ }+ break;+ }}const onScroll = (scrollOffset) => {diff --git a/apps/mobile/app/screens/editor/tiptap/types.ts b/apps/mobile/app/screens/editor/tiptap/types.tsindex 92ccd89e8..d8e382157 100644--- a/apps/mobile/app/screens/editor/tiptap/types.ts+++ b/apps/mobile/app/screens/editor/tiptap/types.ts@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import type { ToolbarGroupDefinition } from "@notesnook/editor/dist/toolbar/types";import { useEditor } from "./use-editor";-import { Note } from "@notesnook/core";export type useEditorType = ReturnType<typeof useEditor>;export type EditorState = {@@ -91,7 +90,6 @@ export type SavePayload = {};export type AppState = {- note?: Note;editing: boolean;movedAway: boolean;timestamp: number;diff --git a/apps/mobile/app/screens/editor/tiptap/utils.ts b/apps/mobile/app/screens/editor/tiptap/utils.tsindex 42373e8bf..44c70cc77 100644--- a/apps/mobile/app/screens/editor/tiptap/utils.ts+++ b/apps/mobile/app/screens/editor/tiptap/utils.ts@@ -17,21 +17,20 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/+import { parseInternalLink } from "@notesnook/core";import { createRef, MutableRefObject, RefObject } from "react";import { TextInput } from "react-native";import WebView from "react-native-webview";-import { MMKV } from "../../../common/database/mmkv";+import { db } from "../../../common/database";import {eSendEvent,eSubscribeEvent,eUnSubscribeEvent} from "../../../services/event-manager";-import { AppState, EditorState, useEditorType } from "./types";-import { useTabStore } from "./use-tab-store";-import { parseInternalLink } from "@notesnook/core";import { eOnLoadNote } from "../../../utils/events";-import { db } from "../../../common/database";import { NotesnookModule } from "../../../utils/notesnook-module";+import { AppState, EditorState, useEditorType } from "./types";+import { useTabStore } from "./use-tab-store";export const textInput = createRef<TextInput>();export const editorController =createRef<useEditorType>() as MutableRefObject<useEditorType>;@@ -155,12 +154,7 @@ export function isContentInvalid(content: string | undefined) {}const canRestoreAppState = (appState: AppState) => {- return (- appState.editing &&- !appState.note?.locked &&- appState.note?.id &&- Date.now() < appState.timestamp + 3600000- );+ return appState.editing && Date.now() < appState.timestamp + 3600000;};let appState: AppState | undefined;