diff --git a/src/lib/components/finds/FindCard.svelte b/src/lib/components/finds/FindCard.svelte index d1dca54..1677f7a 100644 --- a/src/lib/components/finds/FindCard.svelte +++ b/src/lib/components/finds/FindCard.svelte @@ -53,6 +53,35 @@ function toggleComments() { showComments = !showComments; } + + function handleShare() { + const url = `${window.location.origin}/finds/${id}`; + + if (navigator.share) { + navigator + .share({ + title: title, + text: description || `Check out this find: ${title}`, + url: url + }) + .catch((error) => { + // User cancelled or error occurred + if (error.name !== 'AbortError') { + console.error('Error sharing:', error); + } + }); + } else { + // Fallback: Copy to clipboard + navigator.clipboard + .writeText(url) + .then(() => { + alert('Find URL copied to clipboard!'); + }) + .catch((error) => { + console.error('Error copying to clipboard:', error); + }); + } + }
@@ -135,7 +164,7 @@ {commentCount || 'comment'} - diff --git a/src/lib/components/finds/FindPreview.svelte b/src/lib/components/finds/FindPreview.svelte index 7ed79a8..77c25d0 100644 --- a/src/lib/components/finds/FindPreview.svelte +++ b/src/lib/components/finds/FindPreview.svelte @@ -88,14 +88,28 @@ const url = `${window.location.origin}/finds/${find.id}`; if (navigator.share) { - navigator.share({ - title: find.title, - text: find.description || `Check out this find: ${find.title}`, - url: url - }); + navigator + .share({ + title: find.title, + text: find.description || `Check out this find: ${find.title}`, + url: url + }) + .catch((error) => { + // User cancelled or error occurred + if (error.name !== 'AbortError') { + console.error('Error sharing:', error); + } + }); } else { - navigator.clipboard.writeText(url); - alert('Find URL copied to clipboard!'); + // Fallback: Copy to clipboard + navigator.clipboard + .writeText(url) + .then(() => { + alert('Find URL copied to clipboard!'); + }) + .catch((error) => { + console.error('Error copying to clipboard:', error); + }); } } diff --git a/src/routes/finds/[findId]/+page.svelte b/src/routes/finds/[findId]/+page.svelte index 20b892c..03eacfc 100644 --- a/src/routes/finds/[findId]/+page.svelte +++ b/src/routes/finds/[findId]/+page.svelte @@ -48,14 +48,28 @@ const url = `${window.location.origin}/finds/${data.find.id}`; if (navigator.share) { - navigator.share({ - title: data.find.title, - text: data.find.description || `Check out this find: ${data.find.title}`, - url: url - }); + navigator + .share({ + title: data.find.title, + text: data.find.description || `Check out this find: ${data.find.title}`, + url: url + }) + .catch((error) => { + // User cancelled or error occurred + if (error.name !== 'AbortError') { + console.error('Error sharing:', error); + } + }); } else { - navigator.clipboard.writeText(url); - alert('Find URL copied to clipboard!'); + // Fallback: Copy to clipboard + navigator.clipboard + .writeText(url) + .then(() => { + alert('Find URL copied to clipboard!'); + }) + .catch((error) => { + console.error('Error copying to clipboard:', error); + }); } }