Skip to content

Commit ad1c73b

Browse files
committed
Display a warning on mobile devices
1 parent b621043 commit ad1c73b

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/components/HomeIntro.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ function WavyLine() {
6363
export function HomeIntro({
6464
activeStep,
6565
showIntro,
66+
isMobile = false,
6667
}: {
6768
activeStep: string | null;
6869
showIntro: boolean;
70+
isMobile?: boolean;
6971
}) {
7072
const [open, setOpen] = useState(
7173
activeStep === null ||
@@ -143,11 +145,18 @@ export function HomeIntro({
143145
Sounds amazing, right? Learn the basics with this interactive
144146
tutorial in 6-7 minutes!
145147
</p>
148+
{isMobile && (
149+
<p className="max-w-sm text-destructive text-center font-bold text-sm">
150+
This interactive tutorial requires features not available on
151+
mobile browsers. Please visit on a desktop computer.
152+
</p>
153+
)}
146154
</CardContent>
147155
<CardFooter className="flex justify-center items-center flex-col gap-10">
148156
<Button
149157
onClick={startTutorial}
150158
className="bg-primary cursor-pointer"
159+
disabled={isMobile}
151160
>
152161
Get started <ArrowRightIcon />
153162
</Button>

src/routeTree.gen.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
1010

1111
import { Route as rootRouteImport } from './routes/__root'
12+
import { Route as MobileRouteImport } from './routes/mobile'
1213
import { Route as TutorialRouteImport } from './routes/_tutorial'
1314
import { Route as IndexRouteImport } from './routes/index'
1415
import { Route as TutorialDbRouteImport } from './routes/_tutorial._db'
@@ -17,6 +18,11 @@ import { Route as TutorialDbProjectRootRouteImport } from './routes/_tutorial._d
1718
import { Route as TutorialDbProjectsIndexRouteImport } from './routes/_tutorial._db.projects.index'
1819
import { Route as TutorialDbProjectsProjectIdRouteImport } from './routes/_tutorial._db.projects.$projectId'
1920

21+
const MobileRoute = MobileRouteImport.update({
22+
id: '/mobile',
23+
path: '/mobile',
24+
getParentRoute: () => rootRouteImport,
25+
} as any)
2026
const TutorialRoute = TutorialRouteImport.update({
2127
id: '/_tutorial',
2228
getParentRoute: () => rootRouteImport,
@@ -54,13 +60,15 @@ const TutorialDbProjectsProjectIdRoute =
5460

5561
export interface FileRoutesByFullPath {
5662
'/': typeof IndexRoute
63+
'/mobile': typeof MobileRoute
5764
'/project-root': typeof TutorialDbProjectRootRoute
5865
'/projects': typeof TutorialDbProjectsRouteWithChildren
5966
'/projects/$projectId': typeof TutorialDbProjectsProjectIdRoute
6067
'/projects/': typeof TutorialDbProjectsIndexRoute
6168
}
6269
export interface FileRoutesByTo {
6370
'/': typeof IndexRoute
71+
'/mobile': typeof MobileRoute
6472
'/project-root': typeof TutorialDbProjectRootRoute
6573
'/projects/$projectId': typeof TutorialDbProjectsProjectIdRoute
6674
'/projects': typeof TutorialDbProjectsIndexRoute
@@ -69,6 +77,7 @@ export interface FileRoutesById {
6977
__root__: typeof rootRouteImport
7078
'/': typeof IndexRoute
7179
'/_tutorial': typeof TutorialRouteWithChildren
80+
'/mobile': typeof MobileRoute
7281
'/_tutorial/_db': typeof TutorialDbRouteWithChildren
7382
'/_tutorial/_db/project-root': typeof TutorialDbProjectRootRoute
7483
'/_tutorial/_db/projects': typeof TutorialDbProjectsRouteWithChildren
@@ -79,16 +88,18 @@ export interface FileRouteTypes {
7988
fileRoutesByFullPath: FileRoutesByFullPath
8089
fullPaths:
8190
| '/'
91+
| '/mobile'
8292
| '/project-root'
8393
| '/projects'
8494
| '/projects/$projectId'
8595
| '/projects/'
8696
fileRoutesByTo: FileRoutesByTo
87-
to: '/' | '/project-root' | '/projects/$projectId' | '/projects'
97+
to: '/' | '/mobile' | '/project-root' | '/projects/$projectId' | '/projects'
8898
id:
8999
| '__root__'
90100
| '/'
91101
| '/_tutorial'
102+
| '/mobile'
92103
| '/_tutorial/_db'
93104
| '/_tutorial/_db/project-root'
94105
| '/_tutorial/_db/projects'
@@ -99,10 +110,18 @@ export interface FileRouteTypes {
99110
export interface RootRouteChildren {
100111
IndexRoute: typeof IndexRoute
101112
TutorialRoute: typeof TutorialRouteWithChildren
113+
MobileRoute: typeof MobileRoute
102114
}
103115

104116
declare module '@tanstack/react-router' {
105117
interface FileRoutesByPath {
118+
'/mobile': {
119+
id: '/mobile'
120+
path: '/mobile'
121+
fullPath: '/mobile'
122+
preLoaderRoute: typeof MobileRouteImport
123+
parentRoute: typeof rootRouteImport
124+
}
106125
'/_tutorial': {
107126
id: '/_tutorial'
108127
path: ''
@@ -197,6 +216,7 @@ const TutorialRouteWithChildren = TutorialRoute._addFileChildren(
197216
const rootRouteChildren: RootRouteChildren = {
198217
IndexRoute: IndexRoute,
199218
TutorialRoute: TutorialRouteWithChildren,
219+
MobileRoute: MobileRoute,
200220
}
201221
export const routeTree = rootRouteImport
202222
._addFileChildren(rootRouteChildren)

src/routes/index.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
import { createFileRoute, redirect } from "@tanstack/react-router";
2+
import { createServerFn } from "@tanstack/react-start";
3+
import { getRequestHeader } from "@tanstack/react-start/server";
4+
5+
const getIsMobile = createServerFn().handler(async () => {
6+
const userAgent = getRequestHeader("user-agent") || "";
7+
const mobileRegex =
8+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
9+
return mobileRegex.test(userAgent);
10+
});
211

312
export const Route = createFileRoute("/")({
413
beforeLoad: async () => {
14+
const isMobile = await getIsMobile();
15+
16+
if (isMobile) {
17+
throw redirect({
18+
to: "/mobile",
19+
});
20+
}
21+
522
throw redirect({
623
to: "/projects",
724
});

src/routes/mobile.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createFileRoute } from "@tanstack/react-router";
2+
import { HomeIntro } from "@/components/HomeIntro";
3+
4+
export const Route = createFileRoute("/mobile")({
5+
component: RouteComponent,
6+
});
7+
8+
function RouteComponent() {
9+
return (
10+
<div className="min-h-screen bg-background">
11+
<HomeIntro activeStep={null} showIntro={true} isMobile={true} />
12+
</div>
13+
);
14+
}

0 commit comments

Comments
 (0)