Fix share button: add clipboard fallback for HTTP/mobile
This commit is contained in:
@@ -27,11 +27,22 @@ export default function RecommendationCard({ recommendation, onToggleSave, onDis
|
||||
setSharing(true)
|
||||
try {
|
||||
const { share_url } = await shareRecommendation(recommendation.id)
|
||||
// Try clipboard first, fall back to prompt
|
||||
try {
|
||||
await navigator.clipboard.writeText(share_url)
|
||||
} catch {
|
||||
// Clipboard blocked (HTTP/mobile) — use fallback
|
||||
const input = document.createElement('textarea')
|
||||
input.value = share_url
|
||||
document.body.appendChild(input)
|
||||
input.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(input)
|
||||
}
|
||||
setShared(true)
|
||||
setTimeout(() => setShared(false), 2000)
|
||||
} catch {
|
||||
// Fallback: if clipboard fails, silently ignore
|
||||
// API call failed
|
||||
} finally {
|
||||
setSharing(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user