Skip to content

Commit 91bcb99

Browse files
committed
Add app redirect on mobile
1 parent 4324641 commit 91bcb99

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/App.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import "./App.css";
22
import logo from "./assets/wordmark-white-text.svg";
33

4+
import { useEffect } from "react";
45
import { FormattedMessage } from "react-intl";
56

67
import { ShareSheet } from "./ShareSheet";
@@ -17,14 +18,31 @@ const Logo = () => (
1718
);
1819

1920
function App() {
20-
const hasText = useTextParam() !== null;
21+
const text = useTextParam();
22+
23+
useEffect(() => {
24+
let frame;
25+
26+
if (text !== null && "ontouchstart" in document.documentElement) {
27+
frame = document.createElement("iframe");
28+
frame.style.position = "fixed";
29+
frame.src = `mastodon://share?text=${encodeURIComponent(text)}`;
30+
document.body.appendChild(frame);
31+
}
32+
33+
return () => {
34+
if (frame) {
35+
document.body.removeChild(frame);
36+
}
37+
};
38+
}, [text]);
2139

2240
return (
2341
<div className="w-full sm:max-w-lg py-12 sm:py-20 sm:m-auto flex flex-col items-center">
2442
<Logo />
2543

2644
<div className="p-8 sm:min-w-lg rounded-2xl sm:bg-white">
27-
{hasText ? <ShareSheet /> : <Instructions />}
45+
{text !== null ? <ShareSheet /> : <Instructions />}
2846
</div>
2947

3048
<div className="mt-12 sm:mt-30 text-slate-500 text-sm">

0 commit comments

Comments
 (0)