From a80869cee9e841c319e603a51daa9cd34d1e83e8 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Wed, 13 Mar 2024 16:35:17 +0000
Subject: mobile: Add support for sharing text to the app

---
 packages/mobile/app/sharing.tsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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

diff --git a/packages/mobile/app/sharing.tsx b/packages/mobile/app/sharing.tsx
index 41c3212e..59c6fc25 100644
--- a/packages/mobile/app/sharing.tsx
+++ b/packages/mobile/app/sharing.tsx
@@ -2,6 +2,7 @@ import { Link, useLocalSearchParams, useRouter } from "expo-router";
 import { ShareIntent } from "expo-share-intent";
 import { useEffect, useMemo, useState } from "react";
 import { View, Text } from "react-native";
+import { z } from "zod";
 
 import { api } from "@/lib/trpc";
 
@@ -27,7 +28,13 @@ function SaveBookmark({ setMode }: { setMode: (mode: Mode) => void }) {
 
   useEffect(() => {
     if (!isPending && shareIntent?.text) {
-      mutate({ type: "link", url: shareIntent.text });
+      const val = z.string().url();
+      if (val.safeParse(shareIntent.text).success) {
+        // This is a URL, else treated as text
+        mutate({ type: "link", url: shareIntent.text });
+      } else {
+        mutate({ type: "text", text: shareIntent.text });
+      }
     }
   }, []);
 
-- 
cgit v1.2.3-70-g09d2

