Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene page: replaces 'Share on Twitter' w/ 'Share' (using Web Share API) #6512

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (_event) => {
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
2 changes: 1 addition & 1 deletion src/utils/share.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const isMobileVR = AFRAME.utils.device.isMobileVR();
const isMobileVR = window?.AFRAME?.utils?.device?.isMobileVR();

export function canShare() {
// TODO, fix up when OB/FxR support sharing
Expand Down