From 1915fc14b1304eb0e3fb5f9304cac84e06cf780d Mon Sep 17 00:00:00 2001 From: Johnson Mao <86179381+JohnsonMao@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:26:15 +0800 Subject: [PATCH] feature: sharing feature (#81) * fix: prevent skeleton from navigating to links * feat: add sharing feeature --- .../Group/GroupList/SkeletonGroupCard.jsx | 4 +- components/Group/detail/ShareButtonGroup.jsx | 53 +++++++++++++++++++ components/Group/detail/index.jsx | 33 +++++++----- utils/share.js | 41 ++++++++++++++ 4 files changed, 116 insertions(+), 15 deletions(-) create mode 100644 components/Group/detail/ShareButtonGroup.jsx create mode 100644 utils/share.js diff --git a/components/Group/GroupList/SkeletonGroupCard.jsx b/components/Group/GroupList/SkeletonGroupCard.jsx index 11002463..152c01c5 100644 --- a/components/Group/GroupList/SkeletonGroupCard.jsx +++ b/components/Group/GroupList/SkeletonGroupCard.jsx @@ -7,9 +7,9 @@ import { StyledText, } from './GroupCard.styled'; -function SkeletonGroupCard({ _id }) { +function SkeletonGroupCard() { return ( - + + + + + + + + + + + + + + + + + {hasNativeShare && ( + + + + )} + + ); +} diff --git a/components/Group/detail/index.jsx b/components/Group/detail/index.jsx index f0b1c53f..40a6c407 100644 --- a/components/Group/detail/index.jsx +++ b/components/Group/detail/index.jsx @@ -1,7 +1,5 @@ import { useRouter } from 'next/navigation'; import { useSelector } from 'react-redux'; -import styled from '@emotion/styled'; -import Button from '@mui/material/Button'; import Box from '@mui/material/Box'; import Skeleton from '@mui/material/Skeleton'; import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew'; @@ -19,6 +17,7 @@ import { StyledMobileEditButton, } from './Detail.styled'; import ContactButton from './Contact'; +import ShareButtonGroup from './ShareButtonGroup'; function GroupDetail({ id, source, isLoading }) { const router = useRouter(); @@ -38,18 +37,26 @@ function GroupDetail({ id, source, isLoading }) { {source?.photoAlt} )} - {isLoading ? ( - + {isLoading ? ( + + ) : source?.isGrouping ? ( + 揪團中 + ) : ( + 已結束 + )} + - ) : source?.isGrouping ? ( - 揪團中 - ) : ( - 已結束 - )} + {isMyGroup ? ( () => window.open(url, '_blank'); + + const nativeShare = () => { + if (!navigator?.share) return; + navigator.share({ title, text, url }); + }; + + const facebookShare = openInNewTab( + `https://www.facebook.com/sharer/sharer.php?u=${url}&source_surface=external_reshare&display=popup&hashtag=${hashtag}`, + ); + + const lineShare = openInNewTab( + `https://social-plugins.line.me/lineit/share?url=${url}`, + ); + + const linkedinShare = openInNewTab( + `https://www.linkedin.com/sharing/share-offsite/?url=${url}&text=${text}`, + ); + + const threadsShare = openInNewTab( + `https://threads.net/intent/post?text=${url}`, + ); + + const xShare = openInNewTab(`https://x.com/intent/tweet?text=${url}`); + + return { + hasNativeShare: !!navigator?.share, + facebookShare, + lineShare, + linkedinShare, + nativeShare, + threadsShare, + xShare, + }; +}