Skip to content

Commit

Permalink
Merge pull request #6512 from DougReeder/scene-share
Browse files Browse the repository at this point in the history
Scene page: replaces 'Share on Twitter' w/ 'Share' (using Web Share API)
  • Loading branch information
Exairnous authored Oct 31, 2024
2 parents c0adadd + 90f2b0e commit e5eb1a2
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/react-components/scene-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import configs from "../utils/configs";
import { createAndRedirectToNewHub, getReticulumFetchUrl } from "../utils/phoenix-utils";
import { ReactComponent as CodeBranch } from "./icons/CodeBranch.svg";
import { ReactComponent as Pen } from "./icons/Pen.svg";
import { ReactComponent as Twitter } from "./icons/Twitter.svg";
import { ReactComponent as ShareIcon } from "./icons/Share.svg";
import IfFeature from "./if-feature";
import { AppLogo } from "./misc/AppLogo";
import { share } from "../utils/share";

class SceneUI extends Component {
static propTypes = {
Expand Down Expand Up @@ -61,9 +62,13 @@ class SceneUI extends Component {
shareHashtag: configs.translation("share-hashtag")
}
);
const tweetLink = `https://twitter.com/share?url=${encodeURIComponent(sceneUrl)}&text=${encodeURIComponent(
tweetText
)}`;
const onShareClick = async () => {
try {
await share({ url: sceneUrl, title: tweetText });
} catch (error) {
console.error(`while sharing (from scene UI):`, error);
}
};

const unknown = intl.formatMessage({ id: "scene-page.unknown", defaultMessage: "unknown" });

Expand Down Expand Up @@ -235,12 +240,10 @@ class SceneUI extends Component {
)
)}
</IfFeature>
<a href={tweetLink} rel="noopener noreferrer" target="_blank" className={styles.scenePreviewButton}>
<Twitter />
<div>
<FormattedMessage id="scene-page.tweet-button" defaultMessage="Share on Twitter" />
</div>
</a>
<button className={styles.scenePreviewButton} onClick={onShareClick}>
<ShareIcon />
<FormattedMessage id="share-popover.title" defaultMessage="Share" />
</button>
</div>
</div>
<div className={styles.info}>
Expand Down

0 comments on commit e5eb1a2

Please sign in to comment.