11
2- import { useState , useEffect } from 'react'
3- import { useNavigate } from 'react-router-dom'
42import { useRecoilValue } from 'recoil'
53import useHeadlines from '../api/useHeadlines'
64import ErrorMessage from '../components/ErrorMessage'
@@ -16,6 +14,7 @@ import devDataState from '../state/devDataState'
1614import SecondaryNav from '../components/SecondaryNav'
1715import DevDataStatus from '../components/DevDataStatus'
1816import SecondaryTitle from '../components/SecondaryTitle'
17+ import useIntendedRoute from '../utils/useIntendedRoute'
1918
2019export const secondaryNavRoutes = [
2120 { title : 'Dashboard' , to : routes . dashboard } ,
@@ -25,22 +24,8 @@ export const secondaryNavRoutes = [
2524]
2625
2726const Dashboard = ( ) => {
28- const navigate = useNavigate ( )
29-
30- const [ intendedRouteChecked , setIntendedRouteChecked ] = useState ( false )
31-
3227 const includeDevData = useRecoilValue ( devDataState )
3328
34- useEffect ( ( ) => {
35- const intended = window . localStorage . getItem ( 'intendedRoute' )
36- if ( intended ) {
37- window . localStorage . removeItem ( 'intendedRoute' )
38- navigate ( intended , { replace : true } )
39- } else {
40- setIntendedRouteChecked ( true )
41- }
42- } , [ ] )
43-
4429 const activeGame = useRecoilValue ( activeGameState )
4530
4631 const timePeriods = [
@@ -56,6 +41,8 @@ const Dashboard = () => {
5641 const { headlines, loading : headlinesLoading , error : headlinesError } = useHeadlines ( activeGame , startDate , endDate , includeDevData )
5742 const { stats, loading : statsLoading , error : statsError } = useStats ( activeGame , includeDevData )
5843
44+ const intendedRouteChecked = useIntendedRoute ( )
45+
5946 if ( ! intendedRouteChecked ) return null
6047
6148 if ( ! activeGame ) {
0 commit comments