Skip to content

Commit 7d756b9

Browse files
committed
Add AppShare component with lazy loading and route in App.tsx; update API endpoint in SheetSegmentModal test
1 parent d4c0a45 commit 7d756b9

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const Planviewer = lazy(() => import("./routes/planviewer/Planviewer.tsx"));
5555
const PrivacyPolicy = lazy(
5656
() => import("./routes/privacy-policy/PrivacyPolicy.tsx"),
5757
);
58+
const AppShare = lazy(() => import("./routes/app-share/AppShare.tsx"));
5859

5960
type Auth0UserType = {
6061
getIdTokenClaims: () => Promise<any>;
@@ -171,6 +172,7 @@ function App() {
171172
<Suspense>
172173
<Routes>
173174
<Route element={<AuthLayout />}>
175+
<Route path="/app/share" element={<AppShare />} />
174176
<Route path="/login" element={<UserLogin />} />
175177
<Route path="/register" element={<UserRegistration />} />
176178
<Route path="/forgot-password" element={<ForgotPassword />} />

src/routes/app-share/AppShare.tsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { useEffect, useState } from "react";
2+
import { APP_STORE_URL, PLAY_STORE_URL, siteName } from "../../utils/constants";
3+
4+
type MobileDeviceType = "android" | "apple" | null;
5+
6+
const getMobileDeviceType = (): MobileDeviceType => {
7+
if (typeof window === "undefined" || !window.navigator?.userAgent)
8+
return null;
9+
10+
const userAgent = window.navigator.userAgent.toLowerCase();
11+
12+
if (/iphone|ipad|ipod/.test(userAgent)) return "apple";
13+
if (/android/.test(userAgent)) return "android";
14+
15+
return null;
16+
};
17+
18+
const STORE_URLS: Record<NonNullable<MobileDeviceType>, string> = {
19+
apple: APP_STORE_URL,
20+
android: PLAY_STORE_URL,
21+
};
22+
23+
const AppShare = () => {
24+
const [showDownloadLinks, setShowDownloadLinks] = useState(false);
25+
26+
useEffect(() => {
27+
const deviceType = getMobileDeviceType();
28+
29+
if (deviceType) {
30+
window.location.replace(STORE_URLS[deviceType]);
31+
return;
32+
}
33+
34+
setShowDownloadLinks(true);
35+
}, []);
36+
37+
if (!showDownloadLinks) {
38+
return (
39+
<div className="flex min-h-screen items-center justify-center bg-gray-50 px-4">
40+
<p className="text-sm text-gray-500">Redirecting to the app store…</p>
41+
</div>
42+
);
43+
}
44+
45+
return (
46+
<div className="flex min-h-screen items-center justify-center bg-gray-50 px-4">
47+
<div className="w-full max-w-md rounded-lg border border-gray-200 bg-white p-8 shadow-sm">
48+
<h1 className="text-center text-2xl font-semibold text-gray-900">
49+
Get {siteName}
50+
</h1>
51+
<p className="mt-2 text-center text-sm text-gray-500">
52+
Download the app for daily reading, practice, and community on your
53+
device.
54+
</p>
55+
56+
<div className="mt-8 flex flex-col gap-3">
57+
<a
58+
href={APP_STORE_URL}
59+
target="_blank"
60+
rel="noopener noreferrer"
61+
aria-label={`Download ${siteName} on the App Store`}
62+
className="flex items-center justify-center rounded-md bg-amber-600 px-4 py-3 text-sm font-medium text-white hover:bg-amber-700"
63+
>
64+
Download on the App Store
65+
</a>
66+
<a
67+
href={PLAY_STORE_URL}
68+
target="_blank"
69+
rel="noopener noreferrer"
70+
aria-label={`Download ${siteName} on Google Play`}
71+
className="flex items-center justify-center rounded-md border border-gray-300 bg-white px-4 py-3 text-sm font-medium text-gray-900 hover:bg-gray-50"
72+
>
73+
Get it on Google Play
74+
</a>
75+
</div>
76+
</div>
77+
</div>
78+
);
79+
};
80+
81+
export default AppShare;

src/routes/sheets/local-components/modals/sheet-segment-modal/SheetSegmentModal.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe("SheetSegmentModal", () => {
198198
});
199199

200200
expect(axiosInstance.get).toHaveBeenCalledWith(
201-
"/api/v1/search/multilingual",
201+
"/api/v/search/multilingual",
202202
{
203203
params: {
204204
query: "test query",

0 commit comments

Comments
 (0)