Use share API in Community modal

dev
gravel 5 months ago
parent 1d580dff1f
commit 539757b985
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -344,7 +344,7 @@ function addQRModalHandlers() {
document.querySelector('#details-modal-copy-room-details-link')?.addEventListener(
'click',
function() {
copyToClipboard(location.href, DETAILS_LINK_PASTE);
shareOrCopyToClipboard(location.href, DETAILS_LINK_PASTE);
}
)
@ -437,6 +437,14 @@ function hideCommunity(communityID) {
return element ? 1 : 0;
}
function shareOrCopyToClipboard(text, toastText) {
if (navigator.share) {
navigator.share({text});
} else {
copyToClipboard(text, toastText)
}
}
/**
* Copies text to clipboard and shows an informative toast.
* @param {string} text - Text to copy to clipboard.
@ -546,13 +554,7 @@ function addSearchInteractions() {
const hash = searchTermIsTag ? searchTerm : `#q=${searchTerm}`;
const newLocation = new URL(location.href);
newLocation.hash = hash;
if (navigator.share) {
navigator.share({
text: newLocation.href
});
} else {
copyToClipboard(newLocation.href, "Share link copied to clipboard.")
}
shareOrCopyToClipboard(newLocation.href, "Share link copied to clipboard");
});
Array.from(dom.sample_searches()).forEach(button => button.addEventListener('click', function() {

Loading…
Cancel
Save