From 2ce42a8978163470b33085bbfd93172ce01a8d69 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 21 Oct 2024 15:23:46 +0100 Subject: feature(mobile): Use inline WebView for expanding bookmarks --- apps/mobile/components/bookmarks/BookmarkCard.tsx | 21 +-- .../components/bookmarks/ViewBookmarkModal.tsx | 144 +-------------------- 2 files changed, 14 insertions(+), 151 deletions(-) (limited to 'apps/mobile/components') diff --git a/apps/mobile/components/bookmarks/BookmarkCard.tsx b/apps/mobile/components/bookmarks/BookmarkCard.tsx index 14eb3cf3..5d84ee6f 100644 --- a/apps/mobile/components/bookmarks/BookmarkCard.tsx +++ b/apps/mobile/components/bookmarks/BookmarkCard.tsx @@ -9,6 +9,7 @@ import { View, } from "react-native"; import * as Haptics from "expo-haptics"; +import { useRouter } from "expo-router"; import useAppSettings from "@/lib/settings"; import { api } from "@/lib/trpc"; import { BottomSheetModal } from "@gorhom/bottom-sheet"; @@ -34,7 +35,6 @@ import BookmarkAssetImage from "./BookmarkAssetImage"; import BookmarkTextMarkdown from "./BookmarkTextMarkdown"; import ListPickerModal from "./ListPickerModal"; import TagPill from "./TagPill"; -import ViewBookmarkModal from "./ViewBookmarkModal"; function ActionBar({ bookmark }: { bookmark: ZBookmark }) { const { toast } = useToast(); @@ -341,7 +341,7 @@ export default function BookmarkCard({ }, ); - const viewBookmarkModal = useRef(null); + const router = useRouter(); let comp; switch (bookmark.content.type) { @@ -349,7 +349,9 @@ export default function BookmarkCard({ comp = ( viewBookmarkModal.current?.present()} + onOpenBookmark={() => + router.push(`/dashboard/bookmarks/${bookmark.id}`) + } /> ); break; @@ -357,7 +359,9 @@ export default function BookmarkCard({ comp = ( viewBookmarkModal.current?.present()} + onOpenBookmark={() => + router.push(`/dashboard/bookmarks/${bookmark.id}`) + } /> ); break; @@ -365,7 +369,9 @@ export default function BookmarkCard({ comp = ( viewBookmarkModal.current?.present()} + onOpenBookmark={() => + router.push(`/dashboard/bookmarks/${bookmark.id}`) + } /> ); break; @@ -373,11 +379,6 @@ export default function BookmarkCard({ return ( - {comp} ); diff --git a/apps/mobile/components/bookmarks/ViewBookmarkModal.tsx b/apps/mobile/components/bookmarks/ViewBookmarkModal.tsx index 059b990e..df513a89 100644 --- a/apps/mobile/components/bookmarks/ViewBookmarkModal.tsx +++ b/apps/mobile/components/bookmarks/ViewBookmarkModal.tsx @@ -1,9 +1,5 @@ -import React, { useState } from "react"; -import { Keyboard, Pressable, Text } from "react-native"; -import ImageView from "react-native-image-viewing"; -import * as WebBrowser from "expo-web-browser"; -import { useAssetUrl } from "@/lib/hooks"; -import { cn } from "@/lib/utils"; +import React from "react"; +import { Keyboard, Text } from "react-native"; import { BottomSheetBackdrop, BottomSheetModal, @@ -12,23 +8,14 @@ import { BottomSheetView, TouchableWithoutFeedback, } from "@gorhom/bottom-sheet"; -import { ExternalLink } from "lucide-react-native"; -import { - useUpdateBookmark, - useUpdateBookmarkText, -} from "@hoarder/shared-react/hooks/bookmarks"; +import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks"; import { isBookmarkStillTagging } from "@hoarder/shared-react/utils/bookmarkUtils"; import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks"; -import { TailwindResolver } from "../TailwindResolver"; -import { buttonVariants } from "../ui/Button"; import { Input } from "../ui/Input"; import PageTitle from "../ui/PageTitle"; import { Skeleton } from "../ui/Skeleton"; -import { useToast } from "../ui/Toast"; -import BookmarkAssetImage from "./BookmarkAssetImage"; -import BookmarkTextMarkdown from "./BookmarkTextMarkdown"; import TagPill from "./TagPill"; function TagList({ bookmark }: { bookmark: ZBookmark }) { @@ -79,126 +66,6 @@ function NotesEditor({ bookmark }: { bookmark: ZBookmark }) { ); } -function BookmarkLinkView({ bookmark }: { bookmark: ZBookmark }) { - const [imageZoom, setImageZoom] = useState(false); - if (bookmark.content.type !== BookmarkTypes.LINK) { - throw new Error("Wrong content type rendered"); - } - const url = new URL(bookmark.content.url); - - const imageAssetId = - bookmark.content.imageAssetId ?? bookmark.content.screenshotAssetId ?? ""; - const assetSource = useAssetUrl(imageAssetId); - return ( - - WebBrowser.openBrowserAsync(url.toString())} - > - {url.host} - ( - - )} - /> - - setImageZoom(false)} - doubleTapToZoomEnabled={true} - images={[assetSource]} - /> - - setImageZoom(true)}> - - - - ); -} - -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 [content, setContent] = useState(bookmark.content.text); - - const { mutate, isPending } = useUpdateBookmarkText({ - onError: () => { - toast({ - message: "Something went wrong", - variant: "destructive", - }); - }, - onSuccess: () => { - setIsEditing(false); - }, - }); - - return ( - - {isEditing ? ( - - mutate({ - bookmarkId: bookmark.id, - text: content, - }) - } - value={content} - onChangeText={setContent} - multiline - autoFocus - /> - ) : ( - setIsEditing(true)}> - - - - - )} - - ); -} - -function BookmarkAssetView({ bookmark }: { bookmark: ZBookmark }) { - const [imageZoom, setImageZoom] = useState(false); - if (bookmark.content.type !== BookmarkTypes.ASSET) { - throw new Error("Wrong content type rendered"); - } - const assetSource = useAssetUrl(bookmark.content.assetId); - return ( - - setImageZoom(false)} - doubleTapToZoomEnabled={true} - images={[assetSource]} - /> - - setImageZoom(true)}> - - - - ); -} - const ViewBookmarkModal = React.forwardRef< BottomSheetModal, Omit< @@ -208,20 +75,16 @@ const ViewBookmarkModal = React.forwardRef< bookmark: ZBookmark; } >(({ bookmark, ...props }, ref) => { - let comp; let title = null; switch (bookmark.content.type) { case BookmarkTypes.LINK: title = bookmark.title ?? bookmark.content.title; - comp = ; break; case BookmarkTypes.TEXT: title = bookmark.title; - comp = ; break; case BookmarkTypes.ASSET: title = bookmark.title ?? bookmark.content.fileName; - comp = ; break; } return ( @@ -241,7 +104,6 @@ const ViewBookmarkModal = React.forwardRef< - {comp} -- cgit v1.2.3-70-g09d2