feat:better sharing of finds
This commit is contained in:
@@ -53,6 +53,35 @@
|
|||||||
function toggleComments() {
|
function toggleComments() {
|
||||||
showComments = !showComments;
|
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>
|
</script>
|
||||||
|
|
||||||
<div class="find-card">
|
<div class="find-card">
|
||||||
@@ -135,7 +164,7 @@
|
|||||||
<MessageCircle size={16} />
|
<MessageCircle size={16} />
|
||||||
<span>{commentCount || 'comment'}</span>
|
<span>{commentCount || 'comment'}</span>
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="sm" class="action-button">
|
<Button variant="ghost" size="sm" class="action-button" onclick={handleShare}>
|
||||||
<Share size={16} />
|
<Share size={16} />
|
||||||
<span>share</span>
|
<span>share</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -88,14 +88,28 @@
|
|||||||
const url = `${window.location.origin}/finds/${find.id}`;
|
const url = `${window.location.origin}/finds/${find.id}`;
|
||||||
|
|
||||||
if (navigator.share) {
|
if (navigator.share) {
|
||||||
navigator.share({
|
navigator
|
||||||
|
.share({
|
||||||
title: find.title,
|
title: find.title,
|
||||||
text: find.description || `Check out this find: ${find.title}`,
|
text: find.description || `Check out this find: ${find.title}`,
|
||||||
url: url
|
url: url
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// User cancelled or error occurred
|
||||||
|
if (error.name !== 'AbortError') {
|
||||||
|
console.error('Error sharing:', error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
navigator.clipboard.writeText(url);
|
// Fallback: Copy to clipboard
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(url)
|
||||||
|
.then(() => {
|
||||||
alert('Find URL copied to clipboard!');
|
alert('Find URL copied to clipboard!');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error copying to clipboard:', error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -48,14 +48,28 @@
|
|||||||
const url = `${window.location.origin}/finds/${data.find.id}`;
|
const url = `${window.location.origin}/finds/${data.find.id}`;
|
||||||
|
|
||||||
if (navigator.share) {
|
if (navigator.share) {
|
||||||
navigator.share({
|
navigator
|
||||||
|
.share({
|
||||||
title: data.find.title,
|
title: data.find.title,
|
||||||
text: data.find.description || `Check out this find: ${data.find.title}`,
|
text: data.find.description || `Check out this find: ${data.find.title}`,
|
||||||
url: url
|
url: url
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// User cancelled or error occurred
|
||||||
|
if (error.name !== 'AbortError') {
|
||||||
|
console.error('Error sharing:', error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
navigator.clipboard.writeText(url);
|
// Fallback: Copy to clipboard
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(url)
|
||||||
|
.then(() => {
|
||||||
alert('Find URL copied to clipboard!');
|
alert('Find URL copied to clipboard!');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('Error copying to clipboard:', error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user