From 3971bcedda4e6c192a461dbb55382af717d0076b Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Tue, 17 Oct 2023 00:55:33 -0700 Subject: [PATCH] PWA: add Web Share helpers --- src/common/util/pwaUtils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/common/util/pwaUtils.ts b/src/common/util/pwaUtils.ts index 45a490b54..d557e83fd 100644 --- a/src/common/util/pwaUtils.ts +++ b/src/common/util/pwaUtils.ts @@ -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