Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
fforres committed Nov 21, 2024
1 parent e762420 commit 4200a77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 13 additions & 1 deletion app/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Link, useNavigate } from "@remix-run/react";
import Bowser from "bowser";
import InAppSpy from "inapp-spy";
import { LogOut, Tickets, UserIcon, VenetianMaskIcon } from "lucide-react";
import { useMemo, useState } from "react";

Expand All @@ -25,6 +27,14 @@ export const Navbar = () => {
const myProfile = useMyProfileQuery({
skip: !isLogged || !isAuthReady,
});

const [{ isInApp }] = useState(() => InAppSpy());
const browser = Bowser.getParser(window.navigator.userAgent);
const isMobileSafari = browser.satisfies({
mobile: {
safari: ">=9",
},
});
const isSafariMobileWebview = useIsSafariMobileWebview();

const { impersonation, setImpersonation } = useAuthContext();
Expand Down Expand Up @@ -97,7 +107,7 @@ export const Navbar = () => {
],
},
{
content: "Login",
content: `Login${JSON.stringify({ isInApp, isMobileSafari, isSafariMobileWebview })}`,
link: urls.login,
fullLink: isSafariMobileWebview
? `x-safari-https://tickets.communityos.io/${urls.login}`
Expand All @@ -111,6 +121,8 @@ export const Navbar = () => {
isLogged,
impersonation,
myProfile?.data?.me?.isSuperAdmin,
isInApp,
isMobileSafari,
isSafariMobileWebview,
setImpersonation,
navigate,
Expand Down
11 changes: 4 additions & 7 deletions app/components/useIsSafariMobile.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import Bowser from "bowser";
import InAppSpy from "inapp-spy";
import { useMemo, useState } from "react";
export const useIsSafariMobileWebview = () => {
const [isInApp] = useState(() => InAppSpy());
const browser = Bowser.getParser(window.navigator.userAgent);
const isMobileSafari = browser.satisfies({
mobile: {
safari: ">=9",
},
});
const ua = window.navigator.userAgent;
const iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i);
const webkit = !!ua.match(/WebKit/i);
const isMobileSafari = iOS && webkit && !ua.match(/CriOS/i);

return useMemo(() => isInApp && isMobileSafari, [isInApp, isMobileSafari]);
};

0 comments on commit 4200a77

Please sign in to comment.