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

Added skeleton for posts loading #579

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"react-fast-marquee": "^1.6.4",
"react-hot-toast": "^2.4.1",
"react-icons": "^5.2.1",
"react-loading-skeleton": "^3.4.0",
"react-parallax-tilt": "^1.7.231",
"react-responsive-modal": "^6.4.2",
"react-router-dom": "^6.24.0",
Expand Down
44 changes: 44 additions & 0 deletions frontend/src/components/PostsSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Skeleton from 'react-loading-skeleton';
import 'react-loading-skeleton/dist/skeleton.css';

const PostsPageSkeleton = () => {
const skeletonArray = Array(9).fill(0); // Create an array with 9 elements for the skeleton placeholders

return (
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 w-full p-24">
{skeletonArray.map((_, index) => (
<div
key={index}
className="text-[#000435] bg-white dark:text-white dark:bg-blue-950 border border-gray-600 p-6 rounded-lg shadow-lg hover:shadow-2xl transition-transform duration-300 ease-in-out"
// style={{ backgroundImage: `url(${bgHero})`, backgroundSize: 'cover', backgroundPosition: 'center' }}
>
<div className="flex justify-between items-center mb-0">
<Skeleton height={30} width="60%" />
<Skeleton circle={true} height={30} width={30} />
</div>
<Skeleton height={20} width="80%" className="mb-2 dark:bg-white" />
<Skeleton height={12} width="100%" className="mb-2 dark:bg-white" />
<Skeleton height={16} width="40%" className="mb-2 dark:bg-white" />
<div className="flex flex-wrap gap-2 mb-2">
{Array(3).fill(0).map((_, idx) => (
<Skeleton key={idx} height={24} width={50} className="rounded-md dark:bg-white" />
))}
</div>
<div className="flex justify-between">
<div className="flex rtl:space-x-reverse">
{Array(3).fill(0).map((_, idx) => (
<Skeleton key={idx} circle={true} height={32} width={32} />
))}
</div>
<div className="flex space-x-2">
<Skeleton height={24} width={24} />
<Skeleton height={24} width={24} />
</div>
</div>
</div>
))}
</div>
);
};

export default PostsPageSkeleton;
3 changes: 2 additions & 1 deletion frontend/src/pages/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useRecoilValue } from "recoil";
import usePosts from "../hooks/usePosts";
import bgHero from "../assets/bgHero.png";
import { IoIosArrowDown } from "react-icons/io";
import PostsPageSkeleton from "../components/PostsSkeleton";

const Posts = () => {
const currentUser = useRecoilValue(userState);
Expand Down Expand Up @@ -80,7 +81,7 @@ const Posts = () => {
};

if (loading) {
return <Loader />;
return <PostsPageSkeleton />;
}

if (error) {
Expand Down
Loading