feat:better sharing of finds

This commit is contained in:
2025-11-22 20:10:13 +01:00
parent 2ac826cbf9
commit 73eeaf0c74
3 changed files with 72 additions and 15 deletions

View File

@@ -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);
});
}
}
</script>
<div class="find-card">
@@ -135,7 +164,7 @@
<MessageCircle size={16} />
<span>{commentCount || 'comment'}</span>
</Button>
<Button variant="ghost" size="sm" class="action-button">
<Button variant="ghost" size="sm" class="action-button" onclick={handleShare}>
<Share size={16} />
<span>share</span>
</Button>

View File

@@ -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);
});
}
}
</script>

View File

@@ -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);
});
}
}