Skip to content

Commit 344fa46

Browse files
authored
feat: skeleton for posts (#220)
* feat: skeleton for posts * refactor: added requested change
1 parent c4c356e commit 344fa46

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

src/components/core/createPost/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ const CreatePost = () => {
250250
</article>
251251
</div>
252252
</form>
253-
</motion.section>
253+
</motion.section >
254254
</>
255255
);
256256
};

src/components/core/posts/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { addLikesToAPost } from "@/redux/reducers/postsReducer";
88

99
import { PostInstanceType } from "@/types/index.d";
1010

11+
import PostSkeleton from "../../pages/feed/loading"
12+
1113
// Api
1214
// import { getAllPosts, likeTweet } from "@/backend/posts.api";
1315
// import { getBookmarks } from "@/backend/bookmarks.api";
@@ -53,7 +55,7 @@ export default function Posts() {
5355
}
5456

5557
if (postState.loading) {
56-
return <h1 className="text-white text-2xl text-center">Loading...</h1>;
58+
return <h1 className="text-white text-2xl text-center"><PostSkeleton /></h1>;
5759
}
5860

5961
if (postState.error) {
@@ -62,6 +64,7 @@ export default function Posts() {
6264

6365
return (
6466
<>
67+
{!copyPosts && <PostSkeleton />}
6568
{copyPosts &&
6669
copyPosts.length > 0 &&
6770
copyPosts.map((post: PostInstanceType, index: number) => (
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export default function PostSkeleton({ width }: { width?: string }) {
2+
return (
3+
<>
4+
<div className=" shadow dark:shadow-gray-600 mb-4 rounded-md">
5+
<div className="flex animate-pulse p-3">
6+
7+
8+
<div className="flex-shrink-0">
9+
<span className="w-12 h-12 block bg-gray-200 rounded-full dark:bg-gray-700"></span>
10+
</div>
11+
12+
<div className="ms-4 mt-2 w-full">
13+
<h3 className="h-4 bg-gray-200 rounded-full dark:bg-gray-700 w-[40%]"></h3>
14+
15+
<ul className="mt-5 space-y-3">
16+
<li className="w-full h-4 bg-gray-200 rounded-full dark:bg-gray-700"></li>
17+
<li className="w-full h-4 bg-gray-200 rounded-full dark:bg-gray-700"></li>
18+
</ul>
19+
</div>
20+
</div>
21+
</div>
22+
<div className=" shadow dark:shadow-gray-600 mb-4 rounded-md">
23+
<div className="flex animate-pulse p-3">
24+
25+
26+
<div className="flex-shrink-0">
27+
<span className="w-12 h-12 block bg-gray-200 rounded-full dark:bg-gray-700"></span>
28+
</div>
29+
30+
<div className="ms-4 mt-2 w-full">
31+
<h3 className="h-4 bg-gray-200 rounded-full dark:bg-gray-700 w-[40%]"></h3>
32+
33+
<ul className="mt-5 space-y-3">
34+
<li className="w-full h-4 bg-gray-200 rounded-full dark:bg-gray-700"></li>
35+
<li className="w-full h-4 bg-gray-200 rounded-full dark:bg-gray-700"></li>
36+
</ul>
37+
</div>
38+
</div>
39+
</div>
40+
<div className=" shadow dark:shadow-gray-600 mb-4 rounded-md">
41+
<div className="flex animate-pulse p-3">
42+
43+
44+
<div className="flex-shrink-0">
45+
<span className="w-12 h-12 block bg-gray-200 rounded-full dark:bg-gray-700"></span>
46+
</div>
47+
48+
<div className="ms-4 mt-2 w-full">
49+
<h3 className="h-4 bg-gray-200 rounded-full dark:bg-gray-700 w-[40%]"></h3>
50+
51+
<ul className="mt-5 space-y-3">
52+
<li className="w-full h-4 bg-gray-200 rounded-full dark:bg-gray-700"></li>
53+
<li className="w-full h-4 bg-gray-200 rounded-full dark:bg-gray-700"></li>
54+
</ul>
55+
</div>
56+
</div>
57+
</div>
58+
</>
59+
)
60+
}

src/components/pages/user/userPosts/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default function UserPosts({ userId, userName }: UserPostsProps) {
3131
try {
3232
const response = await removePost(id);
3333
if (response) {
34-
console.log(response);
3534
dispatch(removeUserPost(response.$id));
3635
toastify("Post deleted sucessfully", "success");
3736
}

src/redux/reducers/postsReducer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
import { createSlice } from "@reduxjs/toolkit";
33
import type { PayloadAction } from "@reduxjs/toolkit";
44
import { PostInstanceType, PostInitStateType } from "@/types/index.d";
5-
import { ACTION } from "next/dist/client/components/app-router-headers";
5+
6+
67

78
const initialState: PostInitStateType = {
89
posts: [],
910
error: false,
10-
loading: false,
11+
loading: true,
1112
};
1213

1314
export const postsReducer = createSlice({
1415
name: "posts",
1516
initialState: initialState,
17+
1618
reducers: {
1719
getPosts: (state, action: PayloadAction<any>) => {
1820
state.loading = true;

0 commit comments

Comments
 (0)