From 04ae0eec97ffc6bb2a60c8786cdbcbee685953f7 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Wed, 26 Feb 2025 16:03:59 +0500 Subject: [PATCH] mobile: fix various bugs --- apps/mobile/app/app.tsx | 2 + .../app-lock/index.tsx | 54 +++++++++---------- apps/mobile/app/components/auth/login.js | 12 ++--- .../app/components/fluid-panels/index.tsx | 2 +- .../app/components/list-items/note/index.tsx | 4 +- .../app/components/selection-header/index.tsx | 9 ++-- .../components/sheets/add-notebook/index.tsx | 6 +-- .../components/sheets/export-notes/index.tsx | 29 +++++----- .../components/side-menu/notebook-item.tsx | 2 +- apps/mobile/app/components/toast/index.tsx | 2 +- apps/mobile/app/hooks/use-actions.tsx | 4 +- apps/mobile/app/hooks/use-app-events.tsx | 3 +- .../app/navigation/navigation-stack.tsx | 9 ---- .../app/screens/link-notebooks/index.tsx | 20 ++----- .../app/screens/settings/user-section.js | 27 +++++++--- apps/mobile/app/services/exporter.ts | 9 ++++ .../mobile/app/stores/use-navigation-store.ts | 2 +- packages/editor-mobile/public/fonts.css | 38 ++++++------- packages/editor-mobile/public/index.html | 4 +- .../src/components/styles.module.css | 2 +- .../editor-mobile/src/components/tags.tsx | 4 +- .../editor-mobile/src/components/title.tsx | 4 +- packages/intl/locale/en.po | 4 ++ packages/intl/locale/pseudo-LOCALE.po | 4 ++ packages/intl/src/strings.ts | 5 +- 25 files changed, 136 insertions(+), 125 deletions(-) rename apps/mobile/app/{screens => components}/app-lock/index.tsx (91%) diff --git a/apps/mobile/app/app.tsx b/apps/mobile/app/app.tsx index fd31dabf6..daad96cf9 100644 --- a/apps/mobile/app/app.tsx +++ b/apps/mobile/app/app.tsx @@ -42,6 +42,7 @@ import { TipManager } from "./services/tip-manager"; import { changeSystemBarColors, useThemeStore } from "./stores/use-theme-store"; import { useUserStore } from "./stores/use-user-store"; import RNBootSplash from "react-native-bootsplash"; +import AppLocked from "./components/app-lock"; I18nManager.allowRTL(false); I18nManager.forceRTL(false); @@ -88,6 +89,7 @@ const App = (props: { configureMode: "note-preview" }) => { + ); diff --git a/apps/mobile/app/screens/app-lock/index.tsx b/apps/mobile/app/components/app-lock/index.tsx similarity index 91% rename from apps/mobile/app/screens/app-lock/index.tsx rename to apps/mobile/app/components/app-lock/index.tsx index 4b4942a4f..61d0742f1 100644 --- a/apps/mobile/app/screens/app-lock/index.tsx +++ b/apps/mobile/app/components/app-lock/index.tsx @@ -20,7 +20,6 @@ along with this program. If not, see . import React, { useCallback, useEffect, useRef } from "react"; import { AppStateStatus, - BackHandler, Platform, TextInput, useWindowDimensions, @@ -45,17 +44,16 @@ import SettingsService from "../../services/settings"; import { useSettingStore } from "../../stores/use-setting-store"; import { useUserStore } from "../../stores/use-user-store"; import { NotesnookModule } from "../../utils/notesnook-module"; -import { AppFontSize } from "../../utils/size"; -import { Toast } from "../../components/toast"; -import { Button } from "../../components/ui/button"; -import { IconButton } from "../../components/ui/icon-button"; -import Input from "../../components/ui/input"; -import Seperator from "../../components/ui/seperator"; -import Heading from "../../components/ui/typography/heading"; -import Paragraph from "../../components/ui/typography/paragraph"; +import { Toast } from "../toast"; +import { Button } from "../ui/button"; +import { IconButton } from "../ui/icon-button"; +import Input from "../ui/input"; +import Seperator from "../ui/seperator"; +import Heading from "../ui/typography/heading"; +import Paragraph from "../ui/typography/paragraph"; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; import { strings } from "@notesnook/intl"; -import { DefaultAppStyles } from "../../utils/styles"; +import { AppFontSize } from "../../utils/size"; const getUser = () => { const user = MMKV.getString("user"); @@ -84,7 +82,7 @@ const verifyUserPassword = async (password: string) => { } }; -const AppLockedScreen = () => { +const AppLocked = () => { const initialLaunchBiometricRequest = useRef(true); const { colors } = useThemeColors(); const user = getUser(); @@ -184,7 +182,13 @@ const AppLockedScreen = () => { (prevState === "background" || initialLaunchBiometricRequest.current) ) { if (SettingsService.shouldLockAppOnEnterForeground()) { + if (useSettingStore.getState().appDidEnterBackgroundForAction) { + useSettingStore.getState().setAppDidEnterBackgroundForAction(false); + return; + } + DatabaseLogger.info("Locking app on entering foreground"); + useUserStore.getState().lockApp(true); } if ( @@ -205,24 +209,14 @@ const AppLockedScreen = () => { } }, [appState, onUnlockAppRequested, appLocked]); - useEffect(() => { - let handler: any; - if (appLocked) { - handler = BackHandler.addEventListener("hardwareBackPress", () => { - return true; - }); - } - return () => { - handler?.remove(); - }; - }, [appLocked]); - - return ( + return appLocked ? ( { : Platform.OS == "ios" ? "95%" : "100%", - paddingHorizontal: DefaultAppStyles.GAP, + paddingHorizontal: 12, marginBottom: 30, - marginTop: DefaultAppStyles.GAP, + marginTop: 15, alignSelf: "center" }} > @@ -283,7 +277,7 @@ const AppLockedScreen = () => { @@ -345,7 +339,7 @@ const AppLockedScreen = () => { - ); + ) : null; }; -export default AppLockedScreen; +export default AppLocked; diff --git a/apps/mobile/app/components/auth/login.js b/apps/mobile/app/components/auth/login.js index a815d0b90..d299d2a0c 100644 --- a/apps/mobile/app/components/auth/login.js +++ b/apps/mobile/app/components/auth/login.js @@ -217,7 +217,7 @@ export const Login = ({ changeMode }) => { title={strings.forgotPassword()} style={{ alignSelf: "flex-end", - height: 30, + paddingVertical: DefaultAppStyles.GAP_VERTICAL_SMALL, paddingHorizontal: 0 }} onPress={() => { @@ -247,7 +247,6 @@ export const Login = ({ changeMode }) => { style={{ width: 250 }} - height={50} type="accent" title={!loading ? strings.continue() : null} /> @@ -257,19 +256,16 @@ export const Login = ({ changeMode }) => { title={strings.cancelLogin()} style={{ alignSelf: "center", - height: 30, - marginTop: DefaultAppStyles.GAP_VERTICAL + marginTop: DefaultAppStyles.GAP_VERTICAL, + width: 250 }} onPress={() => { if (loading) return; setStep(LoginSteps.emailAuth); setLoading(false); }} - textStyle={{ - textDecorationLine: "underline" - }} fontSize={AppFontSize.xs} - type="errorShade" + type="secondaryAccented" /> )} diff --git a/apps/mobile/app/components/fluid-panels/index.tsx b/apps/mobile/app/components/fluid-panels/index.tsx index f0b5e4e82..556cf029e 100644 --- a/apps/mobile/app/components/fluid-panels/index.tsx +++ b/apps/mobile/app/components/fluid-panels/index.tsx @@ -295,7 +295,7 @@ export const FluidPanels = forwardRef(function FluidTabs( const gesture = Gesture.Pan() .maxPointers(1) .enabled(enabled && !disabled) - .activeOffsetX([-20, 20]) + .activeOffsetX([-10, 10]) .failOffsetY([-10, 10]) .onBegin((event) => { locked.value = false; diff --git a/apps/mobile/app/components/list-items/note/index.tsx b/apps/mobile/app/components/list-items/note/index.tsx index d7db97415..7fa9d3083 100644 --- a/apps/mobile/app/components/list-items/note/index.tsx +++ b/apps/mobile/app/components/list-items/note/index.tsx @@ -53,6 +53,7 @@ import { TimeSince } from "../../ui/time-since"; import Heading from "../../ui/typography/heading"; import Paragraph from "../../ui/typography/paragraph"; import dayjs from "dayjs"; +import { useRoute } from "@react-navigation/native"; type NoteItemProps = { item: Note | BaseTrashItem; @@ -80,6 +81,7 @@ const NoteItem = ({ locked, noOpen = false }: NoteItemProps) => { + const route = useRoute(); const isEditingNote = useTabStore( (state) => state.tabs.find((t) => t.id === state.currentTab)?.session?.noteId === @@ -93,7 +95,6 @@ const NoteItem = ({ const primaryColors = isEditingNote ? colors.selected : colors.primary; const selectionMode = useSelectionStore((state) => state.selectionMode); const [selected] = useIsSelected(item); - return ( <> + route.name !== "Notebook" || item.id !== useNavigationStore.getState().focusedRouteId ) .map((item) => ( diff --git a/apps/mobile/app/components/selection-header/index.tsx b/apps/mobile/app/components/selection-header/index.tsx index 8d8b81c47..1925ffca1 100644 --- a/apps/mobile/app/components/selection-header/index.tsx +++ b/apps/mobile/app/components/selection-header/index.tsx @@ -210,7 +210,6 @@ export const SelectionHeader = React.memo( { title: strings.manageTags(), onPress: async () => { - await sleep(100); ManageTagsSheet.present(selectedItemsList); }, visible: type === "note", @@ -219,17 +218,17 @@ export const SelectionHeader = React.memo( { title: strings.export(), onPress: async () => { - await sleep(100); ExportNotesSheet.present(selectedItemsList); }, visible: type === "note", icon: "export" }, { - title: strings.linkNotebook(), + title: strings.addToNotebook(), onPress: async () => { - await sleep(100); - // MoveNoteSheet.present(); + Navigation.navigate("LinkNotebooks", { + noteIds: selectedItemsList + }); }, visible: type === "note", icon: "plus" diff --git a/apps/mobile/app/components/sheets/add-notebook/index.tsx b/apps/mobile/app/components/sheets/add-notebook/index.tsx index b091a66d5..4c9c75f20 100644 --- a/apps/mobile/app/components/sheets/add-notebook/index.tsx +++ b/apps/mobile/app/components/sheets/add-notebook/index.tsx @@ -103,12 +103,12 @@ export const AddNotebookSheet = ({ useNotebookStore.getState().refresh(); } - if (showMoveNotesOnComplete && id) { + if (showMoveNotesOnComplete && id && !notebook?.id) { ToastManager.show({ - heading: "Notebook added", + heading: strings.notebookAdded(), type: "success", context: "global", - actionText: "Link notes", + actionText: strings.addNotes(), duration: 8000, func: async () => { Navigation.navigate("MoveNotes", { diff --git a/apps/mobile/app/components/sheets/export-notes/index.tsx b/apps/mobile/app/components/sheets/export-notes/index.tsx index 2911a5ba2..ac49bcb94 100644 --- a/apps/mobile/app/components/sheets/export-notes/index.tsx +++ b/apps/mobile/app/components/sheets/export-notes/index.tsx @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +import { strings } from "@notesnook/intl"; import { useThemeColors } from "@notesnook/theme"; import React, { Fragment, useState } from "react"; import { @@ -39,9 +40,11 @@ import { } from "../../../services/event-manager"; import Exporter from "../../../services/exporter"; import PremiumService from "../../../services/premium"; +import { useSettingStore } from "../../../stores/use-setting-store"; import { useUserStore } from "../../../stores/use-user-store"; import { getElevationStyle } from "../../../utils/elevation"; -import { AppFontSize, defaultBorderRadius, ph, pv } from "../../../utils/size"; +import { AppFontSize, defaultBorderRadius } from "../../../utils/size"; +import { DefaultAppStyles } from "../../../utils/styles"; import { sleep } from "../../../utils/time"; import { Dialog } from "../../dialog"; import DialogHeader from "../../dialog/dialog-header"; @@ -52,15 +55,15 @@ import { Pressable } from "../../ui/pressable"; import Seperator from "../../ui/seperator"; import Heading from "../../ui/typography/heading"; import Paragraph from "../../ui/typography/paragraph"; -import { strings } from "@notesnook/intl"; -import { DefaultAppStyles } from "../../../utils/styles"; const ExportNotesSheet = ({ ids, - update + update, + close }: { ids: string[]; update: ((props: PresentSheetOptions) => void) | undefined; + close: ((ctx?: string) => void) | undefined; }) => { const { colors } = useThemeColors(); const [exporting, setExporting] = useState(false); @@ -297,11 +300,11 @@ const ExportNotesSheet = ({ width={250} fontSize={AppFontSize.md} style={{ - marginTop: DefaultAppStyles.GAP_VERTICAL, - borderRadius: 100 + marginTop: DefaultAppStyles.GAP_VERTICAL }} onPress={async () => { if (!result?.filePath) return; + close?.(); if (Platform.OS === "android") { Linking.openURL(result.fileDir).catch((e) => { ToastManager.error(e as Error); @@ -326,11 +329,14 @@ const ExportNotesSheet = ({ width={250} fontSize={AppFontSize.md} style={{ - marginTop: DefaultAppStyles.GAP_VERTICAL, - borderRadius: 100 + marginTop: DefaultAppStyles.GAP_VERTICAL }} onPress={async () => { if (!result) return; + close?.(); + useSettingStore + .getState() + .setAppDidEnterBackgroundForAction(true); if (Platform.OS === "ios") { Share.open({ url: result?.fileDir + result.fileName @@ -350,12 +356,11 @@ const ExportNotesSheet = ({ />