From 5522e20104da6afe2e4667cf45dbbbbc0e838865 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 23 Nov 2024 20:59:34 +0000 Subject: ui(mobile): Replace bottom sheet with native screens (#690) * Remove bottom sheet from bookmark info page * Remove bottom sheet from manage lists page * Remove bottom sheet from new list page * Remove bottom sheet from new bookmark page * Drop bottom-sheets * Improve the look of the modals * Make the search page fade from bottom --- apps/mobile/app/dashboard/bookmarks/[slug].tsx | 317 --------------------- .../app/dashboard/bookmarks/[slug]/index.tsx | 296 +++++++++++++++++++ .../mobile/app/dashboard/bookmarks/[slug]/info.tsx | 115 ++++++++ .../dashboard/bookmarks/[slug]/manage_lists.tsx | 105 +++++++ apps/mobile/app/dashboard/bookmarks/new.tsx | 76 +++++ 5 files changed, 592 insertions(+), 317 deletions(-) delete mode 100644 apps/mobile/app/dashboard/bookmarks/[slug].tsx create mode 100644 apps/mobile/app/dashboard/bookmarks/[slug]/index.tsx create mode 100644 apps/mobile/app/dashboard/bookmarks/[slug]/info.tsx create mode 100644 apps/mobile/app/dashboard/bookmarks/[slug]/manage_lists.tsx create mode 100644 apps/mobile/app/dashboard/bookmarks/new.tsx (limited to 'apps/mobile/app/dashboard/bookmarks') diff --git a/apps/mobile/app/dashboard/bookmarks/[slug].tsx b/apps/mobile/app/dashboard/bookmarks/[slug].tsx deleted file mode 100644 index 9459488a..00000000 --- a/apps/mobile/app/dashboard/bookmarks/[slug].tsx +++ /dev/null @@ -1,317 +0,0 @@ -import React, { useRef, useState } from "react"; -import { - Alert, - Keyboard, - Linking, - Pressable, - ScrollView, - View, -} from "react-native"; -import ImageView from "react-native-image-viewing"; -import WebView from "react-native-webview"; -import { Stack, useLocalSearchParams, useRouter } from "expo-router"; -import BookmarkAssetImage from "@/components/bookmarks/BookmarkAssetImage"; -import BookmarkTextMarkdown from "@/components/bookmarks/BookmarkTextMarkdown"; -import ListPickerModal from "@/components/bookmarks/ListPickerModal"; -import ViewBookmarkModal from "@/components/bookmarks/ViewBookmarkModal"; -import FullPageError from "@/components/FullPageError"; -import { TailwindResolver } from "@/components/TailwindResolver"; -import { Button } from "@/components/ui/Button"; -import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView"; -import FullPageSpinner from "@/components/ui/FullPageSpinner"; -import { Input } from "@/components/ui/Input"; -import { useToast } from "@/components/ui/Toast"; -import { useAssetUrl } from "@/lib/hooks"; -import { api } from "@/lib/trpc"; -import { BottomSheetModal } from "@gorhom/bottom-sheet"; -import { - ArrowUpFromLine, - ClipboardList, - Globe, - Trash2, -} from "lucide-react-native"; - -import { - useDeleteBookmark, - useUpdateBookmarkText, -} from "@hoarder/shared-react/hooks/bookmarks"; -import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks"; - -function BottomActions({ bookmark }: { bookmark: ZBookmark }) { - const { toast } = useToast(); - const router = useRouter(); - const viewBookmarkModal = useRef(null); - const manageListsSheetRef = useRef(null); - const { mutate: deleteBookmark, isPending: isDeletionPending } = - useDeleteBookmark({ - onSuccess: () => { - router.back(); - toast({ - message: "The bookmark has been deleted!", - showProgress: false, - }); - }, - onError: () => { - toast({ - message: "Something went wrong", - variant: "destructive", - showProgress: false, - }); - }, - }); - - const deleteBookmarkAlert = () => - Alert.alert( - "Delete bookmark?", - "Are you sure you want to delete this bookmark?", - [ - { text: "Cancel", style: "cancel" }, - { - text: "Delete", - onPress: () => deleteBookmark({ bookmarkId: bookmark.id }), - style: "destructive", - }, - ], - ); - - const actions = [ - { - id: "lists", - icon: ( - } - /> - ), - shouldRender: true, - onClick: () => manageListsSheetRef.current?.present(), - disabled: false, - }, - { - id: "open", - icon: ( - ( - - )} - /> - ), - shouldRender: true, - onClick: () => viewBookmarkModal.current?.present(), - disabled: false, - }, - { - id: "delete", - icon: ( - } - /> - ), - shouldRender: true, - onClick: deleteBookmarkAlert, - disabled: isDeletionPending, - }, - { - id: "browser", - icon: ( - } - /> - ), - shouldRender: bookmark.content.type == BookmarkTypes.LINK, - onClick: () => - bookmark.content.type == BookmarkTypes.LINK && - Linking.openURL(bookmark.content.url), - disabled: false, - }, - ]; - return ( - - - - - {actions.map( - (a) => - a.shouldRender && ( - - {a.icon} - - ), - )} - - - ); -} - -function BookmarkLinkView({ bookmark }: { bookmark: ZBookmark }) { - if (bookmark.content.type !== BookmarkTypes.LINK) { - throw new Error("Wrong content type rendered"); - } - return ( - - ); -} - -function BookmarkTextView({ bookmark }: { bookmark: ZBookmark }) { - if (bookmark.content.type !== BookmarkTypes.TEXT) { - throw new Error("Wrong content type rendered"); - } - const { toast } = useToast(); - - const [isEditing, setIsEditing] = useState(false); - const initialText = bookmark.content.text; - const [content, setContent] = useState(initialText); - - const { mutate, isPending } = useUpdateBookmarkText({ - onError: () => { - toast({ - message: "Something went wrong", - variant: "destructive", - }); - }, - onSuccess: () => { - setIsEditing(false); - }, - }); - - return ( - - {isEditing && ( - -