From fbcc85ad822a9870ebebfdbd6bbbaa41ef1dff4c Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Mon, 11 Mar 2024 13:34:31 +0000
Subject: mobile: An ugly but function share button

---
 packages/mobile/app/sharing.tsx | 47 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 packages/mobile/app/sharing.tsx

(limited to 'packages/mobile/app/sharing.tsx')

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 (
+    <View className="flex-1 items-center justify-center gap-4">
+      <Text className="text-4xl">Hoarding ...</Text>
+    </View>
+  );
+}
-- 
cgit v1.2.3-70-g09d2

