Use share API in Community modal

dev
gravel 2 years ago
parent 76f1a4b84e
commit 9ab954326a
Signed by: gravel
GPG Key ID: C0538F3C906B308F

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

Loading…
Cancel
Save