diff --git a/src/assets/symbols.svg b/src/assets/symbols.svg index 2fb8eac7..72214eaf 100644 --- a/src/assets/symbols.svg +++ b/src/assets/symbols.svg @@ -251,5 +251,12 @@ + + + + + + + diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index cfaa81ee..fd9b883e 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -22,7 +22,7 @@ import { SavePost, TransferCommunity, } from "lemmy-js-client"; -import { getExternalHost } from "../../env"; +import { getExternalHost, getHttpBase } from "../../env"; import { i18n } from "../../i18next"; import { BanType, PostFormParams, PurgeType } from "../../interfaces"; import { UserService, WebSocketService } from "../../services"; @@ -32,6 +32,7 @@ import { amMod, canAdmin, canMod, + canShare, futureDaysToUnixTime, hostname, isAdmin, @@ -46,6 +47,7 @@ import { numToSI, relTags, setupTippy, + share, showScores, wsClient, } from "../../utils"; @@ -567,9 +569,19 @@ export class PostListing extends Component { commentsLine(mobile = false) { let post = this.props.post_view.post; + return (
{this.commentsButton} + {canShare() && ( + + )} {!post.local && ( { this.setState({ showEdit: false }); } + handleShare(i: PostListing) { + const { name, body, id } = i.props.post_view.post; + share({ + title: name, + text: body?.slice(0, 50), + url: `${getHttpBase()}/post/${id}`, + }); + } + handleShowReportDialog(i: PostListing) { i.setState({ showReportDialog: !i.state.showReportDialog }); } diff --git a/src/shared/utils.ts b/src/shared/utils.ts index b5b39c4f..2e18e2b8 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -1593,3 +1593,13 @@ export function isAuthPath(pathname: string) { pathname ); } + +export function canShare() { + return isBrowser() && !!navigator.canShare; +} + +export function share(shareData: ShareData) { + if (isBrowser()) { + navigator.share(shareData); + } +}