From cd2ca94c3de45ca7c7be552aea87be67600464a5 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed <40239442+ammarahm-ed@users.noreply.github.com> Date: Fri, 7 Apr 2023 01:10:52 +0500 Subject: [PATCH] mobile: Fix crash when leaving note after search (#2289) --- apps/mobile/app/hooks/use-actions.js | 2 +- apps/mobile/app/screens/settings/home.tsx | 90 +++++++++---------- .../app/screens/settings/section-group.tsx | 4 +- .../settings/trash-interval-selector.jsx | 2 +- apps/mobile/app/services/navigation.ts | 8 +- apps/mobile/app/services/search.js | 2 +- apps/mobile/e2e/tests/note.e2e.js | 22 ++--- apps/mobile/e2e/tests/search.e2e.js | 8 +- 8 files changed, 73 insertions(+), 65 deletions(-) diff --git a/apps/mobile/app/hooks/use-actions.js b/apps/mobile/app/hooks/use-actions.js index 30f9d4801..aeec775ea 100644 --- a/apps/mobile/app/hooks/use-actions.js +++ b/apps/mobile/app/hooks/use-actions.js @@ -623,7 +623,7 @@ export const useActions = ({ close = () => null, item }) => { id: "pin-to-notifications", title: notifPinned !== null - ? "Unpin from Notifications" + ? "Unpin from notifications" : "Pin to notifications", icon: "message-badge-outline", on: notifPinned !== null, diff --git a/apps/mobile/app/screens/settings/home.tsx b/apps/mobile/app/screens/settings/home.tsx index 2e8f32f4c..55f0c8e19 100644 --- a/apps/mobile/app/screens/settings/home.tsx +++ b/apps/mobile/app/screens/settings/home.tsx @@ -20,7 +20,7 @@ along with this program. If not, see . import { NativeStackScreenProps } from "@react-navigation/native-stack"; import React, { useEffect, useState } from "react"; import { View } from "react-native"; -import Animated, { FadeInDown, FadeOutDown } from "react-native-reanimated"; +import Animated, { FadeInDown } from "react-native-reanimated"; import DelayLayout from "../../components/delay-layout"; import BaseDialog from "../../components/dialog/base-dialog"; import { ProgressBarComponent } from "../../components/ui/svg/lazy"; @@ -75,57 +75,55 @@ const Home = ({ return ( - - {loading && ( - //@ts-ignore // Migrate to typescript required. - + {loading && ( + //@ts-ignore // Migrate to typescript required. + + + + Logging out + + + Please wait while we log out and clear app data. + - - Logging out - - - Please wait while we log out and clear app data. - - - - + - - )} + + + )} - } - renderItem={renderItem} - /> - + } + renderItem={renderItem} + /> ); }; diff --git a/apps/mobile/app/screens/settings/section-group.tsx b/apps/mobile/app/screens/settings/section-group.tsx index dcbae2bf9..606e3d01b 100644 --- a/apps/mobile/app/screens/settings/section-group.tsx +++ b/apps/mobile/app/screens/settings/section-group.tsx @@ -42,12 +42,12 @@ export const SectionGroup = ({ item }: { item: SettingSection }) => { color={colors.accent} size={SIZE.xs} > - {item.name.toUpperCase()} + {(item.name as string).toUpperCase()} ) : null} {item.sections?.map((item) => ( - + ))} ); diff --git a/apps/mobile/app/screens/settings/trash-interval-selector.jsx b/apps/mobile/app/screens/settings/trash-interval-selector.jsx index 383f9fcbe..6ab611707 100644 --- a/apps/mobile/app/screens/settings/trash-interval-selector.jsx +++ b/apps/mobile/app/screens/settings/trash-interval-selector.jsx @@ -87,7 +87,7 @@ export const TrashIntervalSelector = () => { > {[-1, 7, 30, 365].map((item) => ( { if (item === -1) { await PremiumService.verify(() => { diff --git a/apps/mobile/app/services/navigation.ts b/apps/mobile/app/services/navigation.ts index b118f3490..f5821996a 100755 --- a/apps/mobile/app/services/navigation.ts +++ b/apps/mobile/app/services/navigation.ts @@ -35,6 +35,7 @@ import { eOnNewTopicAdded } from "../utils/events"; import { rootNavigatorRef, tabBarRef } from "../utils/global-refs"; import { eSendEvent } from "./event-manager"; import SettingsService from "./settings"; +import SearchService from "./search"; /** * Routes that should be updated on focus @@ -86,7 +87,8 @@ const routeUpdateFunctions: { ColoredNotes: (params) => eSendEvent("ColoredNotes", params), TopicNotes: (params) => eSendEvent("TopicNotes", params), Monographs: (params) => eSendEvent("Monographs", params), - Reminders: () => useReminderStore.getState().setReminders() + Reminders: () => useReminderStore.getState().setReminders(), + Search: () => SearchService.updateAndSearch() }; function clearRouteFromQueue(routeName: RouteName) { @@ -113,7 +115,7 @@ function queueRoutesForUpdate(...routesToUpdate: RouteName[]) { : (Object.keys(routeNames) as (keyof RouteParams)[]); const currentScreen = useNavigationStore.getState().currentScreen; if (routes.indexOf(currentScreen.name) > -1) { - routeUpdateFunctions[currentScreen.name](); + routeUpdateFunctions[currentScreen.name]?.(); clearRouteFromQueue(currentScreen.name); // Remove focused screen from queue routes.splice(routes.indexOf(currentScreen.name), 1); @@ -129,7 +131,7 @@ function navigate( useNavigationStore.getState().update(screen, !!params?.canGoBack); if (screen.name === "Notebook") routeUpdateFunctions["Notebook"](params); if (screen.name.endsWith("Notes") && screen.name !== "Notes") - routeUpdateFunctions[screen.name](params); + routeUpdateFunctions[screen.name]?.(params); //@ts-ignore Not sure how to fix this for now ignore it. rootNavigatorRef.current?.navigate(screen.name, params); } diff --git a/apps/mobile/app/services/search.js b/apps/mobile/app/services/search.js index 6b5f827bb..44c7acc5e 100644 --- a/apps/mobile/app/services/search.js +++ b/apps/mobile/app/services/search.js @@ -26,7 +26,7 @@ let searchInformation = { placeholder: "Search in all notes", data: [], type: "notes", - get: () => null + get: () => [] }; let keyword = null; diff --git a/apps/mobile/e2e/tests/note.e2e.js b/apps/mobile/e2e/tests/note.e2e.js index 13d9ea1d2..9de2385e7 100644 --- a/apps/mobile/e2e/tests/note.e2e.js +++ b/apps/mobile/e2e/tests/note.e2e.js @@ -55,12 +55,13 @@ describe("NOTE TESTS", () => { await prepare(); let note = await createNote(); await tapById(notesnook.listitem.menu); - await tapById("icon-Favorite"); + await tapById("icon-favorite"); await visibleById("icon-star"); await navigate("Favorites"); await visibleByText(note.body); + await sleep(500); await tapById(notesnook.listitem.menu); - await tapById("icon-Favorite"); + await tapById("icon-favorite"); await expect(element(by.text(note.body))).not.toBeVisible(); await navigate("Notes"); }); @@ -69,11 +70,11 @@ describe("NOTE TESTS", () => { await prepare(); await createNote(); await tapById(notesnook.listitem.menu); - await tapById("icon-Pin"); + await tapById("icon-pin"); await visibleByText("Pinned"); await visibleById("icon-pinned"); await tapById(notesnook.listitem.menu); - await tapById("icon-Pin"); + await tapById("icon-pin"); expect(element(by.id("icon-pinned"))).not.toBeVisible(); }); @@ -81,11 +82,12 @@ describe("NOTE TESTS", () => { await prepare(); await createNote(); await tapById(notesnook.listitem.menu); - await tapById("icon-PinToNotif"); - await visibleByText("Unpin from Notifications"); + await tapById("icon-pin-to-notifications"); + await visibleByText("Unpin from notifications"); await sleep(500); - await tapById("icon-PinToNotif"); - await visibleByText("Pin to Notifications"); + await tapById("icon-pin-to-notifications"); + await sleep(500); + await visibleByText("Pin to notifications"); }); // it("Copy note", async () => { @@ -100,7 +102,7 @@ describe("NOTE TESTS", () => { await prepare(); await createNote(); await tapById(notesnook.listitem.menu); - await tapById("icon-Export"); + await tapById("icon-export"); await visibleByText("PDF"); }); @@ -122,7 +124,7 @@ describe("NOTE TESTS", () => { await prepare(); await createNote(); await tapById(notesnook.listitem.menu); - await tapById("icon-Delete"); + await tapById("icon-delete"); await navigate("Trash"); await tapById(notesnook.listitem.menu); await tapByText("Restore note"); diff --git a/apps/mobile/e2e/tests/search.e2e.js b/apps/mobile/e2e/tests/search.e2e.js index 66224b0d3..013a7571c 100644 --- a/apps/mobile/e2e/tests/search.e2e.js +++ b/apps/mobile/e2e/tests/search.e2e.js @@ -17,13 +17,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +import { notesnook } from "../test.ids"; import { tapById, visibleByText, createNote, prepare, elementById, - sleep + sleep, + tapByText } from "./utils"; describe("Search", () => { @@ -34,6 +36,10 @@ describe("Search", () => { await sleep(300); await elementById("search-input").typeText("n"); await sleep(1000); + await tapByText(note.body); + await sleep(1000); + await device.pressBack(); + await device.pressBack(); await visibleByText(note.body); }); });