Skip to content

Commit

Permalink
Merge pull request #126 from Eddie992/createloadspinner
Browse files Browse the repository at this point in the history
chore: create a load spinner for data fetching (WEB-100) #115
  • Loading branch information
dgarcia-appdev authored Feb 5, 2025
2 parents 8b2622b + e2aae14 commit 1c39b7c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/app/cohorts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import NotificationForm from './notificationForm';
import { useQuery } from '@tanstack/react-query';
import Button from '../components/button/button';
import { useGlobalState } from '../hooks/useGlobalState/useGlobalState';
import Spinner from '../components/spinner/spinner';

interface Group {
id: number;
Expand Down Expand Up @@ -97,7 +98,7 @@ export default function CohortPage() {
}, [cohortStatusResponse]);

if (isLoading) {
return <h1>Loading...</h1>;
return <Spinner />;
}

return (
Expand Down
3 changes: 2 additions & 1 deletion src/app/community/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styles from './community.module.css';
import Person from '../components/person/person';
import Section from '../components/Section/section';
import { useQuery } from '@tanstack/react-query';
import Spinner from '../components/spinner/spinner';

interface Speaker {
documentId: number;
Expand All @@ -24,7 +25,7 @@ export default function CommunityPage() {
});
const peopleData = (peopleDataResponse ?? []) as Speaker[];
if (isLoading) {
return <h1>Loading...</h1>;
return <Spinner />;
}

return (
Expand Down
35 changes: 35 additions & 0 deletions src/app/components/spinner/spinner.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.load-spinner {
display: inline-block;
width: 50px;
height: 50px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: #8105f6;
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
/* For centering the spinner */
.spinner-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
background: rgba(255, 255, 255);
z-index: 9999;
}
10 changes: 10 additions & 0 deletions src/app/components/spinner/spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import styles from './spinner.module.css'; // Import css modules stylesheet as styles

export default function Spinner() {
return (
<div className={styles['spinner-container']}>
<div className={styles['load-spinner']}></div>
</div>
);
}
3 changes: 2 additions & 1 deletion src/app/hooks/useGlobalState/useGlobalState.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use client';
import Spinner from '../../components/spinner/spinner';

import { useQuery } from '@tanstack/react-query';
import {
Expand Down Expand Up @@ -42,7 +43,7 @@ export const GlobalStateProvider = ({ children }: { children: ReactNode }) => {
}
}, [actionLinksResponse]);

if (isLoading) return <h1>Loading...</h1>;
if (isLoading) return <Spinner />;

return (
<GlobalStateContext.Provider value={state}>
Expand Down

0 comments on commit 1c39b7c

Please sign in to comment.