Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/loading #69

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/assets/donut-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/components/Leaderboard/Leaderboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
overflow: auto;
}

.loading {
width: 40em;
height: 45em;
}

.exit {
border: none;
background: none;
Expand Down
16 changes: 14 additions & 2 deletions src/components/Leaderboard/Leaderboard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useEffect, useRef, useState } from 'react';
import './Leaderboard.css';
import { fetchLeaderboard } from '../../apiCalls';
import Loading from '../Loading/Loading';

export default function Leaderboard({ handleLeaderboardClick }) {
const [scores, setScores] = useState([]);
const modalRef = useRef();
const [isLoading, setIsLoading] = useState(false)

useEffect(() => {
if (modalRef.current) {
Expand All @@ -13,13 +15,16 @@ export default function Leaderboard({ handleLeaderboardClick }) {
}, []);

useEffect(() => {
setIsLoading(false)
const getLeaderboard = async () => {
setIsLoading(true)
try {
const leaderboardData = await fetchLeaderboard();
setScores(leaderboardData);
} catch (err) {
console.log(err);
}
setIsLoading(false)
};
getLeaderboard();
}, []);
Expand All @@ -41,14 +46,18 @@ export default function Leaderboard({ handleLeaderboardClick }) {
);
});

return (
<div tabIndex="-1" ref={modalRef} className="leaderboard-container">
return (

<div tabIndex="-1" ref={modalRef} className={`leaderboard-container${isLoading ? ' loading' : ''}`}>
{ isLoading ? <Loading /> :
<>
<button
aria-label="close"
className="exit"
onClick={() => handleLeaderboardClick()}>
X
</button>

<h1 tabIndex="0" className="leaderboard">
Leaderboard
</h1>
Expand All @@ -58,6 +67,9 @@ export default function Leaderboard({ handleLeaderboardClick }) {
<div>Time</div>
</div>
<ol className="leaderboard-list">{leaderboardScores}</ol>
</>
}
</div>

);
}
30 changes: 30 additions & 0 deletions src/components/Loading/Loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.loading-container {
display: flex;
justify-content: center;
padding-top: 5em;
}

.alien {
width: 6rem;
animation: spin 1s linear infinite;
}

.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
11 changes: 11 additions & 0 deletions src/components/Loading/Loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import './Loading.css';
import alien from '../../assets/donut-icon.png';

export default function Loading() {
return (
<section className="loading-container">
<span className="sr-only">Loading</span>
<img src={alien} alt="alien" className="alien" aria-hidden="true" />
</section>
);
}
77 changes: 24 additions & 53 deletions src/components/RoomOne/RoomOne.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
.door-btn,
.bike-btn,
.board-btn,
.desk-comp-btn,
.deskComp-btn,
.radio-btn,
.lamp-btn {
border: none;
Expand All @@ -41,15 +41,15 @@
.door-btn:hover,
.bike-btn:hover,
.board-btn:hover,
.desk-comp-btn:hover,
.deskComp-btn:hover,
.radio-btn:hover,
.lamp-btn:hover {
transform: scale(0.95);
cursor: pointer;
}

.clock-btn.disabled,
.desk-comp-btn.disabled,
.deskComp-btn.disabled,
.plant-btn.disabled,
.door-btn.disabled,
.bike-btn.disabled,
Expand Down Expand Up @@ -101,7 +101,7 @@
max-width: 40em;
}

.desk-comp-btn {
.deskComp-btn {
grid-area: desk;
display: flex;
align-items: center;
Expand All @@ -124,7 +124,7 @@

.clock,
.radio,
.desk-comp,
.deskComp,
.plant,
.bike,
.door {
Expand Down Expand Up @@ -160,73 +160,36 @@
.door {
width: 70%;
}
.desk-comp {
.deskComp {
width: 55%;
}
.radio {
width: 80%
}
}

@media screen and (max-height: 585px) {
.board {
width: 80%;
}
.lamp {
width: 110%;
}
.radio {
width: 70%
}
.door {
width: 60%;
}
}

@media screen and (max-height: 480px) {
.room {
grid-template-columns: repeat(5, 1fr);
grid-template-rows: repeat(3, 1fr);
grid-template-areas:
'clock board board board lamp'
'bike door door desk radio'
'plant door door desk radio ';
}
.board {
width: 70%;
}

.radio {
margin-bottom: 0rem;
}
.door {
width: 50%;
}
}


@media screen and (max-width: 768px) {

.room {
padding: 0rem;
}

.alpha-centauri {
padding-left: 1rem;
}

.board,
.clock,
.radio,
.plant,
.bike {
width: 90%;
}

.desk-comp {
.deskComp {
width: 50%;
}

}

@media screen and (max-height: 300px) {
.board {
width: 70%;
.lamp {
width: 140%;
}
}

Expand All @@ -241,7 +204,7 @@
.door {
width: 75%;
}
.desk-comp {
.deskComp {
width: 60%;
}
.lamp {
Expand Down Expand Up @@ -273,7 +236,7 @@
.door {
width: 110%;
}
.desk-comp {
.deskComp {
width: 90%;
}
.lamp {
Expand All @@ -291,4 +254,12 @@
'plant lamp'
'desk radio';
}
.radio {
margin-bottom: 3rem;
width: 60%;
}
.door,
.lamp {
width: 100%;
}
}
Loading
Loading