fix: handle unsupported Share API gracefully
This commit is contained in:
@@ -30,8 +30,17 @@
|
||||
|
||||
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 loading = $state(true)
|
||||
|
||||
@@ -45,6 +54,13 @@
|
||||
})
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
const {value} = await Share.canShare()
|
||||
canShare = value
|
||||
} catch {
|
||||
canShare = false
|
||||
}
|
||||
|
||||
const [[event]] = await Promise.all([
|
||||
request({
|
||||
relays: [url],
|
||||
@@ -84,12 +100,14 @@
|
||||
<Field>
|
||||
{#snippet input()}
|
||||
<div class="flex w-full gap-2">
|
||||
<Button
|
||||
class="input input-bordered flex shrink-0 w-12 items-center justify-center p-0"
|
||||
onclick={shareInvite}
|
||||
>
|
||||
<Icon icon={NativeShare} />
|
||||
</Button>
|
||||
{#if canShare}
|
||||
<Button
|
||||
class="input input-bordered flex shrink-0 w-12 items-center justify-center p-0"
|
||||
onclick={shareInvite}
|
||||
>
|
||||
<Icon icon={NativeShare} />
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
<label class="input input-bordered flex min-w-0 flex-1 items-center gap-2">
|
||||
<Icon icon={LinkRound} class="shrink-0" />
|
||||
|
||||
Reference in New Issue
Block a user