From b9c7857c5bb16d024fed6544eebf0ef6cd10390f Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sat, 14 Sep 2024 13:26:50 +0100 Subject: feature(mobile): Add proper error handling for server errors --- apps/mobile/app/dashboard/(tabs)/lists.tsx | 11 ++++++++--- apps/mobile/app/dashboard/(tabs)/search.tsx | 14 +++++++++---- apps/mobile/app/dashboard/lists/[slug].tsx | 11 +++++++++-- apps/mobile/app/dashboard/tags/[slug].tsx | 7 +++++-- apps/mobile/components/FullPageError.tsx | 23 ++++++++++++++++++++++ .../components/bookmarks/UpdatingBookmarkList.tsx | 5 +++-- 6 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 apps/mobile/components/FullPageError.tsx diff --git a/apps/mobile/app/dashboard/(tabs)/lists.tsx b/apps/mobile/app/dashboard/(tabs)/lists.tsx index c7e3a874..fa97f67a 100644 --- a/apps/mobile/app/dashboard/(tabs)/lists.tsx +++ b/apps/mobile/app/dashboard/(tabs)/lists.tsx @@ -2,9 +2,11 @@ import { useEffect, useRef, useState } from "react"; import { FlatList, Pressable, Text, View } from "react-native"; import * as Haptics from "expo-haptics"; import { Link } from "expo-router"; +import FullPageError from "@/components/FullPageError"; import NewListModal from "@/components/lists/NewListModal"; import { TailwindResolver } from "@/components/TailwindResolver"; import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView"; +import FullPageSpinner from "@/components/ui/FullPageSpinner"; import PageTitle from "@/components/ui/PageTitle"; import { api } from "@/lib/trpc"; import { BottomSheetModal } from "@gorhom/bottom-sheet"; @@ -65,7 +67,7 @@ function traverseTree( export default function Lists() { const [refreshing, setRefreshing] = useState(false); - const { data: lists, isPending } = useBookmarkLists(); + const { data: lists, isPending, error, refetch } = useBookmarkLists(); const [showChildrenOf, setShowChildrenOf] = useState>( {}, ); @@ -76,9 +78,12 @@ export default function Lists() { setRefreshing(isPending); }, [isPending]); + if (error) { + return refetch()} />; + } + if (!lists) { - // Add spinner - return ; + return ; } const onRefresh = () => { diff --git a/apps/mobile/app/dashboard/(tabs)/search.tsx b/apps/mobile/app/dashboard/(tabs)/search.tsx index ee029ab8..d29c3b05 100644 --- a/apps/mobile/app/dashboard/(tabs)/search.tsx +++ b/apps/mobile/app/dashboard/(tabs)/search.tsx @@ -1,6 +1,7 @@ import { useState } from "react"; import { View } from "react-native"; import BookmarkList from "@/components/bookmarks/BookmarkList"; +import FullPageError from "@/components/FullPageError"; import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView"; import FullPageSpinner from "@/components/ui/FullPageSpinner"; import { Input } from "@/components/ui/Input"; @@ -16,10 +17,15 @@ export default function Search() { const onRefresh = api.useUtils().bookmarks.searchBookmarks.invalidate; - const { data, isPending } = api.bookmarks.searchBookmarks.useQuery( - { text: query }, - { placeholderData: keepPreviousData }, - ); + const { data, error, refetch, isPending } = + api.bookmarks.searchBookmarks.useQuery( + { text: query }, + { placeholderData: keepPreviousData }, + ); + + if (error) { + return refetch()} />; + } if (!data) { return ; diff --git a/apps/mobile/app/dashboard/lists/[slug].tsx b/apps/mobile/app/dashboard/lists/[slug].tsx index 10b9243d..72e3d0ae 100644 --- a/apps/mobile/app/dashboard/lists/[slug].tsx +++ b/apps/mobile/app/dashboard/lists/[slug].tsx @@ -2,6 +2,7 @@ import { Alert, Platform, View } from "react-native"; import * as Haptics from "expo-haptics"; import { router, Stack, useLocalSearchParams } from "expo-router"; import UpdatingBookmarkList from "@/components/bookmarks/UpdatingBookmarkList"; +import FullPageError from "@/components/FullPageError"; import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView"; import FullPageSpinner from "@/components/ui/FullPageSpinner"; import PageTitle from "@/components/ui/PageTitle"; @@ -14,7 +15,11 @@ export default function ListView() { if (typeof slug !== "string") { throw new Error("Unexpected param type"); } - const { data: list } = api.lists.get.useQuery({ listId: slug }); + const { + data: list, + error, + refetch, + } = api.lists.get.useQuery({ listId: slug }); return ( @@ -25,7 +30,9 @@ export default function ListView() { headerTransparent: true, }} /> - {list ? ( + {error ? ( + refetch()} /> + ) : list ? ( @@ -23,7 +24,9 @@ export default function TagView() { headerTransparent: true, }} /> - {tag ? ( + {error ? ( + refetch()} /> + ) : tag ? ( void; +}) { + return ( + + + + Something Went Wrong + + {error} +