From 411aaf3f0cb910979e36fcf5431852e1b2341152 Mon Sep 17 00:00:00 2001 From: HuskyHsu Date: Sat, 20 Jan 2024 21:33:53 +0800 Subject: [PATCH] add share api --- src/pages/Pokemon/components/Header.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pages/Pokemon/components/Header.tsx b/src/pages/Pokemon/components/Header.tsx index 3a6fd7a2..5a5846cf 100644 --- a/src/pages/Pokemon/components/Header.tsx +++ b/src/pages/Pokemon/components/Header.tsx @@ -42,6 +42,20 @@ export function Header({ pm }: Props) { } export function HeaderName({ pm }: Props) { + const shareData = { + title: `${pm.nameZh}`, + text: `${pm.nameZh}圖鑑\n`, + url: document.location.href, + }; + + const share = async () => { + try { + await navigator.share(shareData); + } catch (err) { + alert(err); + } + }; + return (

#{pm.pid.toString().padStart(4, '0')} {pm.nameZh} @@ -54,6 +68,11 @@ export function HeaderName({ pm }: Props) { > wiki + {'share' in navigator && ( + + )}

); }