From a80869cee9e841c319e603a51daa9cd34d1e83e8 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 13 Mar 2024 16:35:17 +0000 Subject: [PATCH] mobile: Add support for sharing text to the app --- packages/mobile/app.json | 3 ++- packages/mobile/app/+not-found.tsx | 6 ++++++ packages/mobile/app/sharing.tsx | 9 ++++++++- packages/mobile/package.json | 3 ++- pnpm-lock.yaml | 6 ++++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 packages/mobile/app/+not-found.tsx diff --git a/packages/mobile/app.json b/packages/mobile/app.json index 56773b57..96eb93a0 100644 --- a/packages/mobile/app.json +++ b/packages/mobile/app.json @@ -38,7 +38,8 @@ "NSExtensionActivationSupportsWebURLWithMaxCount": 1, "NSExtensionActivationSupportsWebPageWithMaxCount": 0, "NSExtensionActivationSupportsImageWithMaxCount": 0, - "NSExtensionActivationSupportsMovieWithMaxCount": 0 + "NSExtensionActivationSupportsMovieWithMaxCount": 0, + "NSExtensionActivationSupportsText": true } } ], 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 ; +} 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 }); + } } }, []); diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 37cc5ee4..9a9198c7 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -35,7 +35,8 @@ "react-native-screens": "~3.29.0", "react-native-svg": "^15.1.0", "tailwind-merge": "^2.2.1", - "use-debounce": "^10.0.0" + "use-debounce": "^10.0.0", + "zod": "^3.22.4" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 99194c39..835ad5f5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -193,6 +193,9 @@ importers: packages/mobile: dependencies: + '@hoarder/trpc': + specifier: 0.1.0 + version: link:../trpc '@tanstack/react-query': specifier: ^5.24.8 version: 5.24.8(react@18.2.0) @@ -268,6 +271,9 @@ importers: use-debounce: specifier: ^10.0.0 version: 10.0.0(react@18.2.0) + zod: + specifier: ^3.22.4 + version: 3.22.4 devDependencies: '@babel/core': specifier: ^7.20.0