Skip to content

Commit 1c39b7c

Browse files
Merge pull request #126 from Eddie992/createloadspinner
chore: create a load spinner for data fetching (WEB-100) #115
2 parents 8b2622b + e2aae14 commit 1c39b7c

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

src/app/cohorts/page.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import NotificationForm from './notificationForm';
88
import { useQuery } from '@tanstack/react-query';
99
import Button from '../components/button/button';
1010
import { useGlobalState } from '../hooks/useGlobalState/useGlobalState';
11+
import Spinner from '../components/spinner/spinner';
1112

1213
interface Group {
1314
id: number;
@@ -97,7 +98,7 @@ export default function CohortPage() {
9798
}, [cohortStatusResponse]);
9899

99100
if (isLoading) {
100-
return <h1>Loading...</h1>;
101+
return <Spinner />;
101102
}
102103

103104
return (

src/app/community/page.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styles from './community.module.css';
44
import Person from '../components/person/person';
55
import Section from '../components/Section/section';
66
import { useQuery } from '@tanstack/react-query';
7+
import Spinner from '../components/spinner/spinner';
78

89
interface Speaker {
910
documentId: number;
@@ -24,7 +25,7 @@ export default function CommunityPage() {
2425
});
2526
const peopleData = (peopleDataResponse ?? []) as Speaker[];
2627
if (isLoading) {
27-
return <h1>Loading...</h1>;
28+
return <Spinner />;
2829
}
2930

3031
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.load-spinner {
2+
display: inline-block;
3+
width: 50px;
4+
height: 50px;
5+
border: 3px solid rgba(255, 255, 255, 0.3);
6+
border-radius: 50%;
7+
border-top-color: #8105f6;
8+
animation: spin 1s ease-in-out infinite;
9+
-webkit-animation: spin 1s ease-in-out infinite;
10+
}
11+
12+
@keyframes spin {
13+
to {
14+
-webkit-transform: rotate(360deg);
15+
}
16+
}
17+
@-webkit-keyframes spin {
18+
to {
19+
-webkit-transform: rotate(360deg);
20+
}
21+
}
22+
/* For centering the spinner */
23+
.spinner-container {
24+
position: fixed;
25+
top: 50%;
26+
left: 50%;
27+
transform: translate(-50%, -50%);
28+
display: flex;
29+
justify-content: center;
30+
align-items: center;
31+
width: 100%;
32+
height: 100%;
33+
background: rgba(255, 255, 255);
34+
z-index: 9999;
35+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import styles from './spinner.module.css'; // Import css modules stylesheet as styles
3+
4+
export default function Spinner() {
5+
return (
6+
<div className={styles['spinner-container']}>
7+
<div className={styles['load-spinner']}></div>
8+
</div>
9+
);
10+
}

src/app/hooks/useGlobalState/useGlobalState.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use client';
2+
import Spinner from '../../components/spinner/spinner';
23

34
import { useQuery } from '@tanstack/react-query';
45
import {
@@ -42,7 +43,7 @@ export const GlobalStateProvider = ({ children }: { children: ReactNode }) => {
4243
}
4344
}, [actionLinksResponse]);
4445

45-
if (isLoading) return <h1>Loading...</h1>;
46+
if (isLoading) return <Spinner />;
4647

4748
return (
4849
<GlobalStateContext.Provider value={state}>

0 commit comments

Comments
 (0)