Skip to content

Commit

Permalink
Merge pull request #579 from Utsavladia/posts-skeleton
Browse files Browse the repository at this point in the history
Added skeleton for posts loading
  • Loading branch information
akbatra567 authored Aug 8, 2024
2 parents c15f69f + 9c46aed commit 3b664f2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
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;
4 changes: 2 additions & 2 deletions frontend/src/pages/Posts.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect, useState, useRef } from "react";
import Loader from "../components/Loader";
import PostCard from "../components/PostCard";
import { userState } from "../store/atoms/auth";
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 @@ -83,7 +83,7 @@ const Posts = () => {
};

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

if (error) {
Expand Down

0 comments on commit 3b664f2

Please sign in to comment.