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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skeleton loading #1241

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"react-helmet-async": "^2.0.4",
"react-hook-form": "^7.49.3",
"react-icons": "^4.10.1",
"react-loading-skeleton": "^3.4.0",
"react-redux": "^9.1.0",
"react-router-dom": "^6.11.2",
"react-scripts": "^5.0.1",
Expand Down
1 change: 1 addition & 0 deletions src/components/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { default as Loading } from "./loading/Loading";
export { default as Modal } from "./modal/Modal";
export { default as Navbar } from "./navbar/Navbar";
export { default as ProfileCompletion } from "./profileCompletion/ProfileCompletion";
export { default as SkeletonCard } from "./skeleton/Skeleton";
15 changes: 15 additions & 0 deletions src/components/shared/skeleton/Skeleton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

.skeleton-container{
margin:1em;
padding: 1em;
border-radius: 15px;
background-color: #f5f6fa;
}
.skeleton-footer{
display: flex;
justify-content: space-between;
/* padding-right: 1em; */
margin-top: 2em;
position: relative;
bottom: 0;
}
31 changes: 31 additions & 0 deletions src/components/shared/skeleton/Skeleton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import "./Skeleton.css";
import "react-loading-skeleton/dist/skeleton.css";
import Skeleton, { SkeletonTheme } from "react-loading-skeleton";

const SkeletonCard = () => {
return (
<SkeletonTheme baseColor="#bdc3c7" highlightColor="#f1f2f6">
<p style={{ height: "100%" }}>
<div className="skeleton-container">
<div className="grid-1">
{/* Image */}
<Skeleton width={290} count={1} height={150} />
<br />
{/* Tags */}
<Skeleton width={180} count={3} height={15} />
</div>
<div className="grid-2">
{/* Button */}
<div className="skeleton-footer">
<Skeleton width={210} count={1} height={35} />
<Skeleton width={50} count={1} height={35} />
</div>
</div>
</div>
</p>
</SkeletonTheme>
);
};

export default SkeletonCard;
26 changes: 21 additions & 5 deletions src/pages/clubs/Clubs.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from "react";
import React, { useState, useEffect } from "react";
import useSWR from "swr";
import { Footer, Navbar } from "../../components/shared";
import { Footer, Navbar, SkeletonCard } from "../../components/shared";
import ClubCard from "../../components/shared/cards/club/ClubCard";
import { clubEndpoints } from "../../static/ApiEndpoints";
import ComponentHelmet from "../../utils/ComponentHelmet";
Expand All @@ -9,8 +9,12 @@ import "./Clubs.css";

const Clubs = () => {
const { data: clubs } = useSWR(clubEndpoints.all, fetcher);
let [loading, setLoading] = useState(true);

Piyush-linux marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 5000);
window.scrollTo(0, 0);
Piyush-linux marked this conversation as resolved.
Show resolved Hide resolved
}, []);

Expand All @@ -22,9 +26,21 @@ const Clubs = () => {
<main className="container">
<div className="clubspage_main_parent">
<div className="clubspage_cardsdiv">
{clubs?.map((club, id) => (
<ClubCard club={club} key={id} />
))}
{loading ? (
<div
style={{
display: "flex",
width: "100%",
justifyContent: "space-evenly",
}}
>
{" "}
<SkeletonCard /> <SkeletonCard /> <SkeletonCard />{" "}
<SkeletonCard />{" "}
</div>
) : (
clubs?.map((club, id) => <ClubCard club={club} key={id} />)
)}
</div>
</div>
</main>
Expand Down
32 changes: 28 additions & 4 deletions src/pages/events/all/Events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { useSelector } from "react-redux";
import useSWR from "swr";
import { EventsCard } from "../../../components/private";
import CreateEvents from "../../../components/private/events/create/CreateEvents";
import { Button, Footer, Navbar } from "../../../components/shared";
import {
Button,
Footer,
Navbar,
SkeletonCard,
} from "../../../components/shared";
import { eventEndpoints } from "../../../static/ApiEndpoints";
import ComponentHelmet from "../../../utils/ComponentHelmet";
import fetcher from "../../../utils/Fetcher";
Expand All @@ -16,7 +21,12 @@ const Events = () => {
const userType = useSelector((state) => state.user.userType);
// const isLoggedIn = useSelector((state) => state.auth.isLoggedIn);

let [loading, setLoading] = useState(true);

Piyush-linux marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 1000);
Piyush-linux marked this conversation as resolved.
Show resolved Hide resolved
window.scrollTo(0, 0);
}, []);

Expand Down Expand Up @@ -45,9 +55,23 @@ const Events = () => {
)}
</div>
<div className="events_div">
{events?.map((event, id) => (
<EventsCard event={event} key={id} />
))}
{/* <SkeletonCard/> */}
{/* loading? <SkeletonCard/> : */}
{loading ? (
<div
style={{
display: "flex",
width: "100%",
justifyContent: "space-evenly",
}}
>
{" "}
<SkeletonCard /> <SkeletonCard /> <SkeletonCard />{" "}
<SkeletonCard />{" "}
</div>
) : (
events?.map((event, id) => <EventsCard event={event} key={id} />)
)}
</div>
</div>
</main>
Expand Down