diff --git a/app/(Main)/[username]/[url]/layout.tsx b/app/(Main)/[username]/[url]/layout.tsx
index 8e84046..609b574 100644
--- a/app/(Main)/[username]/[url]/layout.tsx
+++ b/app/(Main)/[username]/[url]/layout.tsx
@@ -107,7 +107,7 @@ export default async function PostLayout(
published: true,
},
include: {
- _count: { select: { comments: true, savedUsers: true, likes: true } },
+ _count: { select: { comments: true, savedUsers: true, likes: true, shares: true } },
author: {
include: {
Followers: true,
@@ -181,7 +181,7 @@ export default async function PostLayout(
published: true,
},
include: {
- _count: { select: { comments: true, savedUsers: true, likes: true } },
+ _count: { select: { comments: true, savedUsers: true, likes: true, shares: true } },
author: {
include: {
Followers: true,
diff --git a/app/(Main)/[username]/loading.tsx b/app/(Main)/[username]/loading.tsx
new file mode 100644
index 0000000..b872516
--- /dev/null
+++ b/app/(Main)/[username]/loading.tsx
@@ -0,0 +1,62 @@
+
+import PostCardSkeletonV2 from "@/components/skeletons/post-card-2";
+import { Skeleton } from "@/components/ui/skeleton";
+
+export default function Loading() {
+ return (
+ <>
+
@@ -85,6 +88,14 @@ export default async function TagPage({ params }: { params: { tagname: string }
>
)}
+ {
+ followers.length > 0 && (
+ <>
+
+
+ >
+ )
+ }
{
latestPosts.length > 0 && (
<>
diff --git a/app/api/comments/[id]/like/route.ts b/app/api/comments/[id]/like/route.ts
index 77a1a5e..17ef7b8 100644
--- a/app/api/comments/[id]/like/route.ts
+++ b/app/api/comments/[id]/like/route.ts
@@ -29,14 +29,89 @@ export async function POST(req: Request) {
id: isLiked.id,
},
});
- console.log("Deleted like");
+
+ const oneWeekAgo = new Date();
+ oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
+ if (isLiked.createdAt > oneWeekAgo) {
+ const notification = await postgres.notification.findFirst({
+ where: {
+ senderId: user.id,
+ receiverId: comment.authorId,
+ type: "commentLike",
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (notification) {
+ await postgres.notification.delete({
+ where: {
+ id: notification.id,
+ },
+ });
+ }
+ }
} else {
- await postgres.commentLike.create({
+ const commentLike = await postgres.commentLike.create({
data: {
commentId,
authorId: user.id,
},
+ include: {
+ comment: {
+ select: {
+ post: {
+ include: {
+ author: {
+ select: {
+ username: true,
+ },
+ },
+ }
+ },
+ content: true,
+ },
+ },
+ },
+ });
+
+ const sender = await postgres.user.findUnique({
+ where: {
+ id: user.id,
+ },
+ select: {
+ id: true,
+ username: true,
+ },
});
+
+ const receiver = await postgres.user.findUnique({
+ where: {
+ id: comment.authorId,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (sender && receiver) {
+ const message = `"${commentLike.comment.content}"`;
+ const type = "commentLike";
+ const url = `/@${commentLike.comment.post.author.username}/${commentLike.comment.post.url}?commentsOpen=true`;
+ await postgres.notification.create({
+ data: {
+ content: message,
+ type,
+ url,
+ receiverId: receiver?.id || "",
+ senderId: sender?.id || "",
+ },
+ });
+ }
console.log("Created like");
}
return new Response(null, { status: 200 });
diff --git a/app/api/follow/route.ts b/app/api/follow/route.ts
index cbc5cd7..55203e5 100644
--- a/app/api/follow/route.ts
+++ b/app/api/follow/route.ts
@@ -29,6 +29,33 @@ export async function GET(request: NextRequest) {
},
});
+ // if followed during 1 week, delete notification
+ const oneWeekAgo = new Date();
+ oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
+ if (isFollowed.createdAt > oneWeekAgo) {
+ const notification = await postgres.notification.findFirst({
+ where: {
+ senderId: followerId,
+ receiverId: followeeId,
+ type: "follow",
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (notification) {
+ await postgres.notification.delete({
+ where: {
+ id: notification.id,
+ },
+ });
+ }
+ }
+
return NextResponse.json({ message: "unfollowed" }, { status: 200 });
} else {
await postgres.follow.create({
@@ -40,33 +67,33 @@ export async function GET(request: NextRequest) {
// Check if followerId and followeeId are not null
if (followerId && followeeId) {
- //Create notification
- const sender = await postgres.user.findUnique({
- where: {
- id: followerId,
- },
- });
-
- const receiver = await postgres.user.findUnique({
- where: {
- id: followeeId,
- },
+ //Create notification
+ const sender = await postgres.user.findUnique({
+ where: {
+ id: followerId,
+ },
+ });
+
+ const receiver = await postgres.user.findUnique({
+ where: {
+ id: followeeId,
+ },
+ });
+
+ // Check if sender and receiver are not null
+ if (sender && receiver) {
+ const message = `${sender?.name || sender?.username} is now following you`;
+ const type = "follow";
+ const url = `/@${sender?.username}`;
+ await create({
+ content: message,
+ type,
+ url,
+ receiverId: receiver?.id || "",
+ senderId: sender?.id || "",
});
-
- // Check if sender and receiver are not null
- if (sender && receiver) {
- const message = `${sender?.name || sender?.username} followed you`;
- const type = "follow";
- const url = `/@${sender?.username}`
- await create({
- content: message,
- type,
- url,
- receiverId: receiver?.id || "",
- senderId: sender?.id || "",
- });
- }
}
+ }
return NextResponse.json({ message: "followed" }, { status: 200 });
}
diff --git a/app/api/post/[postid]/like/route.ts b/app/api/post/[postid]/like/route.ts
index 87c9fe0..b5081fe 100644
--- a/app/api/post/[postid]/like/route.ts
+++ b/app/api/post/[postid]/like/route.ts
@@ -29,6 +29,33 @@ export async function POST(req: Request) {
id: isLiked.id,
},
});
+
+ const oneWeekAgo = new Date();
+ oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
+ if (isLiked.createdAt > oneWeekAgo) {
+ const notification = await postgres.notification.findFirst({
+ where: {
+ senderId: user.id,
+ receiverId: post.authorId,
+ type: "postLike",
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ if (notification) {
+ await postgres.notification.delete({
+ where: {
+ id: notification.id,
+ },
+ });
+ }
+ }
+
console.log("Deleted like");
} else {
await postgres.like.create({
@@ -45,6 +72,31 @@ export async function POST(req: Request) {
},
},
});
+
+ const sender = await postgres.user.findUnique({
+ where: {
+ id: user.id,
+ },
+ });
+ const receiver = await postgres.user.findUnique({
+ where: {
+ id: post.authorId,
+ },
+ });
+ if (sender && receiver) {
+ const message = `"${post.title}"`;
+ const type = "postLike";
+
+ await postgres.notification.create({
+ data: {
+ content: message,
+ type,
+ url: `/@${sender.username}/${post.url}`,
+ receiverId: receiver.id,
+ senderId: sender.id,
+ }
+ });
+ }
console.log("Created like");
}
return new Response(null, { status: 200 });
diff --git a/app/api/user/[id]/bookmarks/route.ts b/app/api/user/[id]/bookmarks/route.ts
index 4d92bde..ea13daf 100644
--- a/app/api/user/[id]/bookmarks/route.ts
+++ b/app/api/user/[id]/bookmarks/route.ts
@@ -14,6 +14,15 @@ export async function GET(req: NextRequest, { params} : { params: { id: string }
include: {
author: true,
savedUsers: true,
+ _count: {
+ select: {
+ likes: true,
+ savedUsers: true,
+ readedUsers: true,
+ shares: true,
+ comments: true,
+ },
+ },
}
},
},
diff --git a/app/api/user/[id]/history/route.ts b/app/api/user/[id]/history/route.ts
index f78d1dd..52e1ace 100644
--- a/app/api/user/[id]/history/route.ts
+++ b/app/api/user/[id]/history/route.ts
@@ -13,8 +13,18 @@ export async function GET(req: NextRequest, { params} : { params: { id: string }
post: {
include: {
author: true,
+ _count: {
+ select: {
+ likes: true,
+ savedUsers: true,
+ readedUsers: true,
+ shares: true,
+ comments: true,
+ },
+ },
}
},
+
},
orderBy: {
updatedAt: "desc",
diff --git a/app/api/user/[id]/posts/route.ts b/app/api/user/[id]/posts/route.ts
index ac1997c..3b7991c 100644
--- a/app/api/user/[id]/posts/route.ts
+++ b/app/api/user/[id]/posts/route.ts
@@ -9,8 +9,11 @@ const baseQuery = {
savedUsers: true,
_count: {
select: {
- likes: true,
- savedUsers: true,
+ likes: true,
+ savedUsers: true,
+ readedUsers: true,
+ shares: true,
+ comments: true,
},
},
tags: {
diff --git a/app/globals.css b/app/globals.css
index dfcfa59..977a705 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -569,4 +569,15 @@
.details{
min-height: calc(100vh - 44rem);
}
-} */
\ No newline at end of file
+} */
+.swiper {
+ width: 100%;
+ height: 100%;
+}
+
+.swiper-slide img {
+ display: block;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
\ No newline at end of file
diff --git a/components/blog/feed-post-card.tsx b/components/blog/feed-post-card.tsx
index 2bf89d7..87fc7cd 100644
--- a/components/blog/feed-post-card.tsx
+++ b/components/blog/feed-post-card.tsx
@@ -19,6 +19,7 @@ import { usePathname } from "next/navigation";
import { Skeleton } from "../ui/skeleton";
import { shimmer, toBase64 } from "@/lib/image";
import { validate } from "@/lib/revalidate";
+import PostAnalyticsDialog from "./post-analytics-dialog";
export default function FeedPostCard(
@@ -92,14 +93,22 @@ export default function FeedPostCard(
{props.post.readingTime}