From fbcc85ad822a9870ebebfdbd6bbbaa41ef1dff4c Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 11 Mar 2024 13:34:31 +0000 Subject: mobile: An ugly but function share button --- packages/mobile/app/[bookmark]/[slug].tsx | 9 ++++++ packages/mobile/app/_layout.tsx | 2 +- packages/mobile/app/error.tsx | 9 ++++++ packages/mobile/app/sharing.tsx | 47 +++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 packages/mobile/app/[bookmark]/[slug].tsx create mode 100644 packages/mobile/app/error.tsx create mode 100644 packages/mobile/app/sharing.tsx diff --git a/packages/mobile/app/[bookmark]/[slug].tsx b/packages/mobile/app/[bookmark]/[slug].tsx new file mode 100644 index 00000000..2ca88701 --- /dev/null +++ b/packages/mobile/app/[bookmark]/[slug].tsx @@ -0,0 +1,9 @@ +import { View, Text } from "react-native"; + +export default function Bookmark() { + return ( + + Hoarded! + + ); +} diff --git a/packages/mobile/app/_layout.tsx b/packages/mobile/app/_layout.tsx index d3cbbee1..bd269060 100644 --- a/packages/mobile/app/_layout.tsx +++ b/packages/mobile/app/_layout.tsx @@ -16,7 +16,7 @@ export default function RootLayout() { useEffect(() => { if (hasShareIntent) { router.replace({ - pathname: "shareintent", + pathname: "sharing", params: { shareIntent: JSON.stringify(shareIntent) }, }); resetShareIntent(); diff --git a/packages/mobile/app/error.tsx b/packages/mobile/app/error.tsx new file mode 100644 index 00000000..a6a18023 --- /dev/null +++ b/packages/mobile/app/error.tsx @@ -0,0 +1,9 @@ +import { View, Text } from "react-native"; + +export default function Error() { + return ( + + Error! + + ); +} diff --git a/packages/mobile/app/sharing.tsx b/packages/mobile/app/sharing.tsx new file mode 100644 index 00000000..948fed05 --- /dev/null +++ b/packages/mobile/app/sharing.tsx @@ -0,0 +1,47 @@ +import { useLocalSearchParams, useRouter } from "expo-router"; +import { ShareIntent } from "expo-share-intent"; +import { useEffect, useMemo } from "react"; +import { View, Text } from "react-native"; + +import { api } from "@/lib/trpc"; + +export default function Sharing() { + const router = useRouter(); + const params = useLocalSearchParams(); + + const shareIntent = useMemo(() => { + if (params && params.shareIntent) { + if (typeof params.shareIntent === "string") { + return JSON.parse(params.shareIntent) as ShareIntent; + } + } + return null; + }, [params]); + + const { mutate, isPending } = api.bookmarks.createBookmark.useMutation({ + onSuccess: (d) => { + router.replace(`bookmark/${d.id}`); + }, + onError: () => { + router.replace("error"); + }, + }); + + useEffect(() => { + if (!isPending && shareIntent?.text) { + mutate({ type: "link", url: shareIntent.text }); + } + }, []); + + useEffect(() => { + if (!shareIntent) { + router.replace("/"); + } + }, []); + + return ( + + Hoarding ... + + ); +} -- cgit v1.2.3-70-g09d2