Skip to content

Commit e5b8973

Browse files
authored
feat: added loading spinner on /dashboard when filtering (#1090)
* Added loading spinner on /dashboard when filtering * Less jarring loading spinner bg * Added bg overlay on loading spinner
1 parent c268437 commit e5b8973

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

components/Loading/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface LoadingProps {
99

1010
export default function Loading ({ size = 60, color }: LoadingProps): React.ReactElement {
1111
return (
12-
<div className={style.loading_container}>
12+
<div className={style.loading_overlay}>
1313
<DotLoader
1414
color={color ?? 'var(--accent-color)'}
1515
size={size}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
.loading_container {
1+
.loading_overlay {
2+
--z-overlay-loading: 999999;
3+
position: fixed;
4+
top: 0;
5+
left: 0;
6+
right: 0;
7+
bottom: 0;
28
display: flex;
39
justify-content: center;
410
align-items: center;
5-
min-height: 50vh;
6-
width: 100%;
11+
background-color: rgba(0, 0, 0, 0.4);
12+
z-index: var(--z-overlay-loading);
713
}

pages/dashboard/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)