diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-13 16:35:17 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-13 16:35:17 +0000 |
| commit | a80869cee9e841c319e603a51daa9cd34d1e83e8 (patch) | |
| tree | 28baa59eea45ec846ea29ecaae8db9813143d1d9 /packages/mobile/app | |
| parent | e40a18132119a90d9b4bf035ecf741b930342688 (diff) | |
| download | karakeep-a80869cee9e841c319e603a51daa9cd34d1e83e8.tar.zst | |
mobile: Add support for sharing text to the app
Diffstat (limited to 'packages/mobile/app')
| -rw-r--r-- | packages/mobile/app/+not-found.tsx | 6 | ||||
| -rw-r--r-- | packages/mobile/app/sharing.tsx | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/packages/mobile/app/+not-found.tsx b/packages/mobile/app/+not-found.tsx new file mode 100644 index 00000000..466505b6 --- /dev/null +++ b/packages/mobile/app/+not-found.tsx @@ -0,0 +1,6 @@ +import { View } from "react-native"; + +// This is kinda important given that the sharing modal always resolve to an unknown route +export default function NotFound() { + return <View />; +} 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 }); + } } }, []); |
