()
| 28 | }); |
| 29 | |
| 30 | const App: FC = () => { |
| 31 | const queryClient = useCustomQueryClient(); |
| 32 | const { user, isAuthenticated } = useAuthState(); |
| 33 | |
| 34 | // The total time spent on the app |
| 35 | // It is used to show force the user to login after a certain amount of time |
| 36 | const [startTime, setStartTime] = useState<boolean>(false); |
| 37 | |
| 38 | // Time limit in seconds |
| 39 | const timeLimit = 75; // 75 seconds |
| 40 | |
| 41 | // The AuthDialog is shown when the user is not authenticated and the time limit is reached |
| 42 | const initialShowDialog = localStorage.getItem("expiredFreeTrial") === "true"; |
| 43 | const [showAuthDialog, setShowAuthDialog] = |
| 44 | useState<boolean>(initialShowDialog); |
| 45 | |
| 46 | // Create time context |
| 47 | const unauthenticatedTimeContext: UnauthenticatedTimeContextProps = { |
| 48 | setStartTime, |
| 49 | }; |
| 50 | |
| 51 | const userID = useMemo(() => { |
| 52 | if (user) { |
| 53 | return user.uid; |
| 54 | } |
| 55 | |
| 56 | return ""; |
| 57 | }, [user]); |
| 58 | |
| 59 | useEffect(() => { |
| 60 | // The time limit is only active in production |
| 61 | const devMode = import.meta.env.DEV; |
| 62 | |
| 63 | if (!devMode && startTime && !isAuthenticated) { |
| 64 | console.log("Starting time"); |
| 65 | const interval = setInterval(() => { |
| 66 | console.log("Time limit reached"); |
| 67 | setShowAuthDialog(true); |
| 68 | localStorage.setItem("expiredFreeTrial", "true"); |
| 69 | }, timeLimit * 1000); |
| 70 | return () => clearInterval(interval); |
| 71 | } |
| 72 | }, [startTime, isAuthenticated]); |
| 73 | |
| 74 | useEffect(() => { |
| 75 | if (isAuthenticated) { |
| 76 | setShowAuthDialog(false); |
| 77 | } |
| 78 | }, [isAuthenticated]); |
| 79 | |
| 80 | // Ensure that context is never scoped outside of the current instance of the app |
| 81 | const helmetContext = {}; |
| 82 | return ( |
| 83 | <> |
| 84 | <HelmetProvider context={helmetContext}> |
| 85 | <QueryClientProvider client={queryClient}> |
| 86 | <MobileWarningTemplate className="h-screen w-screen sm:hidden" /> |
| 87 | <div className="hidden h-fit w-fit sm:block"> |
nothing calls this directly
no test coverage detected