remove the need to resource and profile data on landing page

This commit is contained in:
Mo Tarbin
2026-02-08 16:08:56 -05:00
parent 2c1458e026
commit b31bcc2a9c
5 changed files with 18 additions and 22 deletions

View File

@@ -2,13 +2,13 @@ import NavBar from '@/views/components/NavBar'
import { Button, Typography, useColorScheme } from '@mui/joy'
import Tracker from '@openreplay/tracker'
import { useCallback, useEffect } from 'react'
import { Outlet, useNavigate } from 'react-router-dom'
import { Outlet } from 'react-router-dom'
import { useRegisterSW } from 'virtual:pwa-register/react'
import { registerCapacitorListeners } from './CapacitorListener'
import PageTransition from './components/animations/PageTransition'
import { AuthProvider } from './hooks/useAuth.jsx'
import { ImpersonateUserProvider } from './contexts/ImpersonateUserContext'
import SSEProvider from './contexts/SSEContext'
import { AuthProvider } from './hooks/useAuth.jsx'
import { useNotification } from './service/NotificationProvider'
import NetworkBanner from './views/components/NetworkBanner'
@@ -32,7 +32,6 @@ const startOpenReplay = () => {
tracker.start()
}
const AppContent = () => {
const { showNotification } = useNotification()

View File

@@ -18,9 +18,9 @@ const MAX_RECONNECT_ATTEMPTS = 10 // Circuit breaker limit
const CIRCUIT_BREAKER_RESET_TIME = 600000 // 10 minutes
export const useSSE = () => {
const { data: userProfile } = useUserProfile()
const { isAuthenticated, token } = useAuth()
// Only fetch user profile if authenticated - prevents unnecessary API calls on landing page
const { data: userProfile } = useUserProfile()
const [connectionState, setConnectionState] = useState(SSE_STATES.CLOSED)
const [lastEvent, setLastEvent] = useState(null)
const [error, setError] = useState(null)

View File

@@ -1,6 +1,17 @@
import { useQuery } from '@tanstack/react-query'
import { GetResource } from '../utils/Fetcher'
// Helper to check if we have a valid token
const isTokenValid = () => {
const token = localStorage.getItem('token')
if (!token) return false
const expiry = localStorage.getItem('token_expiry')
if (!expiry) return true // No expiry set, assume valid
return new Date() < new Date(expiry)
}
export const useResource = () => {
const { data, isLoading, error } = useQuery({
queryKey: ['resource'],
@@ -11,6 +22,7 @@ export const useResource = () => {
staleTime: 6 * 60 * 60 * 1000, // 6 hours in milliseconds
refetchOnWindowFocus: false,
refetchOnReconnect: false,
enabled: isTokenValid(), // Only run query when we have a valid token
})
return { data, isLoading, error }
}

View File

@@ -54,6 +54,7 @@ export const useUserProfile = () => {
},
staleTime: 30 * 60 * 1000, // 30 minutes in milliseconds
gcTime: 30 * 60 * 1000, // 30 minutes in milliseconds
enabled: isTokenValid(), // Only run query when we have a valid token
})
return {
data,

View File

@@ -115,7 +115,7 @@ const publicPages = [
'/',
]
const AppNavBar = () => {
const NavBar = () => {
const { data: resource } = useResource()
const navigate = useNavigate()
@@ -323,20 +323,4 @@ const AppNavBar = () => {
</nav>
)
}
const LandingNavBar = () => {
return null
}
const NavBar = () => {
// if capacitor app then show AppNavBar, else show LandingNavBar
if (Capacitor.isNativePlatform()) {
return <AppNavBar />
}
if (publicPages.includes(window.location.pathname)) {
return <LandingNavBar />
}
return <AppNavBar />
}
export default NavBar