Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove mobile detection code from root
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent ce5d7ab commit f3d3881
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions app/root.tsx
Expand Up @@ -22,30 +22,18 @@ import {
} from "@remix-run/react";
import { type ErrorResponse } from "@remix-run/router";
import { LinksFunction } from "@remix-run/cloudflare";
import MobileDetect from "mobile-detect";
import Login from "../components/Login.js";
import Navigation from "../components/Navigation.js";
import { type ReactNode, StrictMode, useContext, useEffect } from "react";
import theme from "../theme.js";
import { withEmotionCache } from "@emotion/react";

function isMobile(ua: string | null, secChIsMobile: string | null): string {
if (secChIsMobile && ["?0", "?1"].includes(secChIsMobile))
return secChIsMobile;

if (ua) return `?${Number(new MobileDetect(ua).mobile())}`;

return "?0";
}

export function ErrorBoundary() {
const error = useRouteError() as ErrorResponse;
const { ch, ua } = JSON.parse(error.data);
const mobile = isMobile(ua, ch);

if (!isRouteErrorResponse(error))
return getMarkup(
{ hide: true, mobile },
{ hide: true },
<Container maxW="container.lg" pt="8vh" textAlign="left">
<Heading size="4xl">???</Heading>
<br />
Expand All @@ -69,14 +57,14 @@ export function ErrorBoundary() {
return "";

case 401:
return getMarkup({ hide: true, mobile }, <Login />);
return getMarkup({ hide: true }, <Login />);

case 403:
return getMarkup({ hide: true, mobile }, <Forbidden />);
return getMarkup({ hide: true }, <Forbidden />);

case 404:
return getMarkup(
{ hide: true, mobile },
{ hide: true },
<Container maxW="container.lg" pt="8vh" textAlign="left">
<Heading size="4xl">404</Heading>
<br />
Expand All @@ -92,7 +80,7 @@ export function ErrorBoundary() {

default:
return getMarkup(
{ hide: true, mobile },
{ hide: true },
<Container maxW="container.lg" pt="8vh" textAlign="left">
<Heading size="4xl">500</Heading>
<br />
Expand Down Expand Up @@ -128,11 +116,6 @@ export async function loader({
if (context.env.DSN) data.dsn = context.env.DSN;
if (context.data.theme) data.theme = context.data.theme;

data.mobile = isMobile(
context.request.headers.get("user-agent"),
context.request.headers.get("sec-ch-ua-mobile")
);

return data;
}

Expand Down

0 comments on commit f3d3881

Please sign in to comment.