@@ -77,6 +77,7 @@ export default function Dashboard ({ user }: PaybuttonsProps): React.ReactElemen
7777 const [ selectedButtonIds , setSelectedButtonIds ] = useState < any [ ] > ( [ ] )
7878 const [ showFilters , setShowFilters ] = useState < boolean > ( false )
7979 const [ buttons , setButtons ] = useState < any [ ] > ( [ ] )
80+ const [ isLoading , setIsLoading ] = useState < boolean > ( false )
8081
8182 const setPeriodFromString = ( data ?: DashboardData , periodString ?: PeriodString ) : void => {
8283 if ( data === undefined ) return
@@ -118,6 +119,7 @@ export default function Dashboard ({ user }: PaybuttonsProps): React.ReactElemen
118119
119120 useEffect ( ( ) => {
120121 const fetchData = async ( ) : Promise < void > => {
122+ setIsLoading ( true )
121123 let url = 'api/dashboard'
122124 if ( selectedButtonIds . length > 0 ) {
123125 url += `?buttonIds=${ selectedButtonIds . join ( ',' ) } `
@@ -129,6 +131,7 @@ export default function Dashboard ({ user }: PaybuttonsProps): React.ReactElemen
129131 } )
130132 const json = await res . json ( )
131133 setDashboardData ( json )
134+ setIsLoading ( false )
132135 }
133136 fetchData ( ) . catch ( console . error )
134137 const savedActivePeriodString = loadStateFromCookie ( COOKIE_NAMES . DASHBOARD_FILTER , undefined ) as ( PeriodString | undefined )
@@ -152,15 +155,16 @@ export default function Dashboard ({ user }: PaybuttonsProps): React.ReactElemen
152155 if ( dashboardData === undefined || activePeriod === undefined ) {
153156 return (
154157 < >
155- < TopBar title = "Dashboard" user = { user . stUser ?. email } />
158+ < TopBar title = "Dashboard" user = { user ? .stUser ?. email } />
156159 < Loading />
157160 </ >
158161 )
159162 }
160163
161164 return (
162165 < >
163- < TopBar title = "Dashboard" user = { user . stUser ?. email } />
166+ < TopBar title = "Dashboard" user = { user ?. stUser ?. email } />
167+ { isLoading && < Loading /> }
164168 < div className = { style . filter_btns } >
165169 < div
166170 onClick = { ( ) => setShowFilters ( ! showFilters ) }
0 commit comments