fix: handle unsupported Share API gracefully

This commit is contained in:
2026-04-14 23:05:49 +05:30
parent cdeb7afcae
commit 9fa1375435
+25 -7
View File
@@ -30,8 +30,17 @@
const copyInvite = () => clip(invite) const copyInvite = () => clip(invite)
const shareInvite = () => Share.share({url: invite}) const shareInvite = async () => {
if (!canShare) return
try {
await Share.share({url: invite})
} catch (e) {
console.error(e)
}
}
let canShare = $state(false)
let claim = $state("") let claim = $state("")
let loading = $state(true) let loading = $state(true)
@@ -45,6 +54,13 @@
}) })
onMount(async () => { onMount(async () => {
try {
const {value} = await Share.canShare()
canShare = value
} catch {
canShare = false
}
const [[event]] = await Promise.all([ const [[event]] = await Promise.all([
request({ request({
relays: [url], relays: [url],
@@ -84,12 +100,14 @@
<Field> <Field>
{#snippet input()} {#snippet input()}
<div class="flex w-full gap-2"> <div class="flex w-full gap-2">
<Button {#if canShare}
class="input input-bordered flex shrink-0 w-12 items-center justify-center p-0" <Button
onclick={shareInvite} class="input input-bordered flex shrink-0 w-12 items-center justify-center p-0"
> onclick={shareInvite}
<Icon icon={NativeShare} /> >
</Button> <Icon icon={NativeShare} />
</Button>
{/if}
<label class="input input-bordered flex min-w-0 flex-1 items-center gap-2"> <label class="input input-bordered flex min-w-0 flex-1 items-center gap-2">
<Icon icon={LinkRound} class="shrink-0" /> <Icon icon={LinkRound} class="shrink-0" />