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:Want to Add Skeletons In all the Cards #479 #486

Merged
merged 1 commit into from
Aug 5, 2024
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
22 changes: 22 additions & 0 deletions src/components/CanteenCardSkeleton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

const CanteenCardSkeleton = () => {
return (
<div className="sm:w-64 w-[80vw] px-5 bg-white flex flex-col border pt-5 h-[320px] border-white rounded-lg shadow dark:bg-none dark:border-white my-4 mx-2 transition duration-300 ease-in-out transform hover:scale-105 hover:shadow-lg hover:shadow-green-500/50 ... md:justify-center">
{/* Image Skeleton */}
<div className="flex justify-center items-center h-48 w-full bg-gray-300 dark:bg-gray-300 rounded-t-lg animate-pulse">
{/* You can add an icon or leave it empty */}
</div>

<div className="p-5 space-y-3">
{/* Title Skeleton */}
<div className="h-6 bg-gray-300 dark:bg-gray-300 rounded animate-pulse"></div>

{/* Button Skeleton */}
<div className="h-8 flex justify-center items-center w-24 bg-blue-300 dark:bg-blue-700 rounded-lg animate-pulse"></div>
</div>
</div>
);
};

export default CanteenCardSkeleton;
23 changes: 18 additions & 5 deletions src/components/CanteenList.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import CanteenCard from './CanteenCard';
import CanteenCardSkeleton from './CanteenCardSkeleton';

const CanteenList = ({ canteenData }) => {
const [loading, setLoading] = useState(true);

useEffect(() => {
const timer = setTimeout(() => {
setLoading(false);
}, 1000); // Set the loading state to false after 1 second

return () => clearTimeout(timer); // Clean up the timer on component unmount
}, []);

if (!canteenData || !canteenData.data) {
return <p>No canteen data available.</p>;
}

return (
<div className="flex flex-wrap lg:px-28 gap-5 justify-center mt-20">
{canteenData.data.map((canteen) => (
<CanteenCard key={canteen._id} canteen={canteen} />
))}
{loading
? Array(canteenData.data.length).fill().map((_, index) => <CanteenCardSkeleton key={index} />)
: canteenData.data.map((canteen) => (
<CanteenCard key={canteen._id} canteen={canteen} />
))}
</div>
);
};

export default CanteenList;
export default CanteenList;
Loading