PWA: add Web Share helpers

This commit is contained in:
Enrico Ros
2023-10-17 00:55:33 -07:00
parent 725b08e021
commit 3971bcedda
+10
View File
@@ -9,6 +9,16 @@ export function isPwa(): boolean {
return false;
}
export function webSharePresent(): boolean {
return typeof navigator !== 'undefined' && !!navigator.share;
}
export function webShare(title: string, text: string, url: string, onShared?: () => void): void {
if (typeof navigator !== 'undefined' && navigator.share)
navigator.share({ title, text, url })
.then(() => onShared?.())
.catch((error) => console.log('Error sharing', error));
}
/**
* An immediate alternative to useMediaQuery, for cases where we can't use CSS and we don't need to listen to changes