34 lines
908 B
TypeScript
34 lines
908 B
TypeScript
import * as Sharing from "expo-sharing"
|
|
import { Platform, Share } from "react-native"
|
|
|
|
import type { MediaShareContext } from "@/lib/media-links"
|
|
import { mediaShareUrl } from "@/lib/media-links"
|
|
import { showError } from "@/lib/toast"
|
|
|
|
export async function shareMediaLink(
|
|
serverUrl: string,
|
|
share: MediaShareContext
|
|
) {
|
|
const url = mediaShareUrl(serverUrl, share)
|
|
|
|
try {
|
|
if (Platform.OS === "web") {
|
|
if (!(await Sharing.isAvailableAsync())) {
|
|
showError("Sharing is not available on this device")
|
|
return
|
|
}
|
|
await Sharing.shareAsync(url, { dialogTitle: "Share" })
|
|
return
|
|
}
|
|
|
|
await Share.share(
|
|
Platform.OS === "ios" ? { url } : { message: url }
|
|
)
|
|
} catch (error) {
|
|
if (error instanceof Error && /cancel/i.test(error.message)) {
|
|
return
|
|
}
|
|
showError(error instanceof Error ? error.message : "Failed to share link")
|
|
}
|
|
}
|