Skip to content

Commit 25cc9c7

Browse files
authored
Fix TypeScript error in ShareDialog Web Share API detection (#12)
1 parent b53cbe9 commit 25cc9c7

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/ShareDialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default function ShareDialog({ workout, buttonStyle }: { workout: Workout
88
const { maxes } = useMassStorage();
99
const dialogRef = useRef<HTMLDialogElement>(null);
1010
const [shareUrl, setShareUrl] = useState<string | null>(null);
11+
const canUseWebShare = typeof (navigator as { share?: unknown }).share === 'function';
1112

1213
async function handleShare() {
1314
const encoded = await exportWorkout(workout, maxes);
@@ -43,14 +44,14 @@ export default function ShareDialog({ workout, buttonStyle }: { workout: Workout
4344
type="button"
4445
style={{ marginTop: "1rem" }}
4546
onClick={() => {
46-
if (navigator.share) {
47+
if (canUseWebShare) {
4748
navigator.share({ url: shareUrl, title: workout.name || "Workout" });
4849
} else {
4950
navigator.clipboard.writeText(shareUrl);
5051
}
5152
}}
5253
>
53-
{navigator.share ? "Share" : "Copy link"}
54+
{canUseWebShare ? "Share" : "Copy link"}
5455
</button>
5556
</div>
5657
</div>

0 commit comments

Comments
 (0)