Skip to content

Commit

Permalink
Merge pull request #365 from starknet-id/ayush/refresh-button-fix
Browse files Browse the repository at this point in the history
feat: add loading state on achievements page
  • Loading branch information
fricoben authored Nov 27, 2023
2 parents 81aa7f8 + 35c7798 commit 5d916bc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
6 changes: 4 additions & 2 deletions app/achievements/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function Page() {
const [userAchievements, setUserAchievements] = useState<
AchievementsDocument[]
>([]);
const [loading, setLoading] = useState<boolean>(false);

useEffect(() => {
// If a call was made with an address in the first second, the call with 0 address should be cancelled
Expand Down Expand Up @@ -128,8 +129,9 @@ export default function Page() {
}
}
);

setLoading(true);
await Promise.all(promises);
setLoading(false);
};
if (userAchievements.length === 0 || !address) return;
checkAchievements();
Expand Down Expand Up @@ -158,7 +160,7 @@ export default function Page() {
Complete achievements and grow your Starknet on-chain reputation
</p>
</div>
{userAchievements.length > 0 ? (
{!loading && userAchievements.length > 0 ? (
userAchievements.map(
(achievementCategory: AchievementsDocument, index: number) => {
return (
Expand Down
38 changes: 37 additions & 1 deletion components/skeletons/achievementSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,43 @@ const AchievementSkeleton: FunctionComponent = () => {
sx={{
bgcolor: "grey.900",
borderRadius: "30px",
margin: "40px auto",
margin: "10px auto 0",
}}
/>
</div>
<div className={styles.achievementSkeleton}>
<Skeleton
variant="rounded"
className={styles.achievementLoading}
height={200}
sx={{
bgcolor: "grey.900",
borderRadius: "30px",
margin: "10px auto 0",
}}
/>
</div>
<div className={styles.achievementSkeleton}>
<Skeleton
variant="rounded"
className={styles.achievementLoading}
height={200}
sx={{
bgcolor: "grey.900",
borderRadius: "30px",
margin: "10px auto 0",
}}
/>
</div>
<div className={styles.achievementSkeleton}>
<Skeleton
variant="rounded"
className={styles.achievementLoading}
height={200}
sx={{
bgcolor: "grey.900",
borderRadius: "30px",
margin: "10px auto 0",
}}
/>
</div>
Expand Down
11 changes: 4 additions & 7 deletions styles/achievements.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@

.cardWrapper {
display: flex;
margin: 0 auto;
justify-content: center;
}

.cards {
min-width: min(1500px, calc(100% - 32px));
text-align: left;
margin-top: 42px;
width: 100%;
max-width: 1330px;
}

.card {
Expand Down Expand Up @@ -310,18 +310,15 @@
align-items: center;
gap: 20px;
}

.subtitle {
margin-left: 40px;
margin-right: 40px;
text-align: center;
}
}

.skeleton {
min-width: min(1500px, calc(100vw - 4rem));
}

.container:has(.skeleton) {
padding: 0 30px;
}
}

1 comment on commit 5d916bc

@vercel
Copy link

@vercel vercel bot commented on 5d916bc Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.