Skip to content

Commit 6da80d8

Browse files
authored
Merge pull request #16 from yusupovbg/beta
Update v1.0.1
2 parents 2af0cd1 + fe1b762 commit 6da80d8

File tree

36 files changed

+936
-201
lines changed

36 files changed

+936
-201
lines changed

app/(Main)/[username]/[url]/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default async function PostLayout(
107107
published: true,
108108
},
109109
include: {
110-
_count: { select: { comments: true, savedUsers: true, likes: true } },
110+
_count: { select: { comments: true, savedUsers: true, likes: true, shares: true } },
111111
author: {
112112
include: {
113113
Followers: true,
@@ -181,7 +181,7 @@ export default async function PostLayout(
181181
published: true,
182182
},
183183
include: {
184-
_count: { select: { comments: true, savedUsers: true, likes: true } },
184+
_count: { select: { comments: true, savedUsers: true, likes: true, shares: true } },
185185
author: {
186186
include: {
187187
Followers: true,

app/(Main)/[username]/loading.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
import PostCardSkeletonV2 from "@/components/skeletons/post-card-2";
3+
import { Skeleton } from "@/components/ui/skeleton";
4+
5+
export default function Loading() {
6+
return (
7+
<>
8+
<div className="md:container mx-auto px-4 pt-5">
9+
<div className="gap-5 lg:gap-6 flex flex-col md:flex-row items-start xl:px-4 pt-5" >
10+
<div className="w-full md:w-1/3 lg:w-1/4">
11+
<div className={"flex flex-col items-stretch justify-between xs:h-fit details"}>
12+
<div className="flex-1">
13+
<div className="flex lg:flex-col items-start">
14+
<div className="user__header flex md:block md:items-start lg:space-y-4 space-y-2 pb-4" >
15+
<Skeleton className="rounded-full mr-3 lg:w-64 xl:w-[296px] w-16 md:w-56 md:h-56 lg:h-64 xl:h-[296px] border h-16
16+
" />
17+
<div className="flex items-center md:py-4 w-full justify-between">
18+
<div className="md:space-y-3 w-full">
19+
<Skeleton className="w-full h-8" />
20+
<Skeleton className="w-28 h-5" />
21+
</div>
22+
</div>
23+
</div>
24+
</div>
25+
</div>
26+
27+
<Skeleton className="w-full h-9" />
28+
29+
<div className="w-full mt-5 space-y-1.5">
30+
<Skeleton className="w-full h-5" />
31+
<Skeleton className="w-full h-5" />
32+
<Skeleton className="w-full h-5" />
33+
</div>
34+
35+
<div className="py-4 items-center flex gap-5 w-full">
36+
<Skeleton className="w-full h-8" />
37+
<Skeleton className="w-full h-8" />
38+
</div>
39+
40+
<ul className="details space-y-3">
41+
<Skeleton className="w-full h-5" />
42+
<Skeleton className="w-full h-5" />
43+
<Skeleton className="w-full h-5" />
44+
</ul>
45+
</div>
46+
</div>
47+
<div className="lg:pl-8 w-full">
48+
<div className="user-articles lg:mb-6 md:mb-5 mb-4">
49+
<div className="flex flex-col lg:gap-6 md:gap-5 gap-4">
50+
<PostCardSkeletonV2 />
51+
<PostCardSkeletonV2 />
52+
<PostCardSkeletonV2 />
53+
<PostCardSkeletonV2 />
54+
<PostCardSkeletonV2 />
55+
</div>
56+
</div>
57+
</div>
58+
</div>
59+
</div>
60+
</>
61+
)
62+
}

app/(Main)/explore/page.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
import { EmptyPlaceholder } from "@/components/empty-placeholder"
21
import Posts from "@/components/explore/posts"
32
import Search from "@/components/explore/search"
43
import { getSessionUser } from "@/components/get-session-user"
5-
import { Icons } from "@/components/icon"
6-
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
7-
import { Input } from "@/components/ui/input"
84
import { getPosts } from "@/lib/prisma/posts"
9-
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
10-
import Link from "next/link"
11-
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
12-
import { redirect } from "next/navigation"
13-
import { Hash } from "lucide-react"
145
import { getUsers } from "@/lib/prisma/users"
15-
import { Separator } from "@/components/ui/separator"
16-
import { Button } from "@/components/ui/button"
17-
import UserHoverCard from "@/components/user-hover-card"
186
import { searchTags } from "@/lib/prisma/tags"
19-
import { Badge } from "@/components/ui/badge"
207
import ExploreComponent from "@/components/explore/tab-content"
218
import ExploreTab from "@/components/explore/tab"
229
import Users from "@/components/explore/users"

app/(Main)/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const [latestPosts, tags, popularPosts] = await Promise.all([
3636
readingTime: true,
3737
publishedAt: true,
3838
cover: true,
39+
_count: {
40+
select: {
41+
likes: true,
42+
savedUsers: true,
43+
readedUsers: true,
44+
shares: true,
45+
comments: true,
46+
},
47+
},
3948
author: {
4049
select: {
4150
username: true,

app/(Main)/tags/[tagname]/page.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { getSessionUser } from "@/components/get-session-user";
44
import TagDetails from "@/components/tags/details";
55
import TagLatestPosts from "@/components/tags/latest-posts";
66
import TagPopularPosts from "@/components/tags/post";
7+
import TagFollowers from "@/components/tags/users";
78
import { Separator } from "@/components/ui/separator";
89
import postgres from "@/lib/postgres";
9-
import { revalidatePath } from "next/cache";
10+
import { getFollowersByTag } from "@/lib/prisma/tags";
1011
import { redirect } from "next/navigation";
1112

1213
export default async function TagPage({ params }: { params: { tagname: string } }) {
@@ -38,7 +39,7 @@ export default async function TagPage({ params }: { params: { tagname: string }
3839
},
3940
savedUsers: true,
4041
likes: true,
41-
_count: { select: { comments: true, likes: true, savedUsers: true } },
42+
_count: { select: { comments: true, likes: true, savedUsers: true, shares: true } },
4243
},
4344
orderBy: [
4445
{ likes: { _count: 'desc' } },
@@ -65,7 +66,7 @@ export default async function TagPage({ params }: { params: { tagname: string }
6566
Followings: true,
6667
}
6768
},
68-
_count: { select: { comments: true, likes: true, savedUsers: true } },
69+
_count: { select: { comments: true, likes: true, savedUsers: true, shares: true } },
6970
savedUsers: true,
7071
},
7172
orderBy: {
@@ -75,6 +76,8 @@ export default async function TagPage({ params }: { params: { tagname: string }
7576
});
7677
if (!tag) redirect("/404");
7778
const session = await getSessionUser();
79+
80+
const { followers } = await getFollowersByTag({ id: tag.id, limit: 5, session: session?.id });
7881
return (
7982
<>
8083
<div className="flex flex-col space-y-6 my-8">
@@ -85,6 +88,14 @@ export default async function TagPage({ params }: { params: { tagname: string }
8588
<TagPopularPosts posts={popularPosts} tag={tag} session={session} />
8689
</>
8790
)}
91+
{
92+
followers.length > 0 && (
93+
<>
94+
<Separator />
95+
<TagFollowers followers={followers} tag={tag} session={session} />
96+
</>
97+
)
98+
}
8899
{
89100
latestPosts.length > 0 && (
90101
<>

app/api/comments/[id]/like/route.ts

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,89 @@ export async function POST(req: Request) {
2929
id: isLiked.id,
3030
},
3131
});
32-
console.log("Deleted like");
32+
33+
const oneWeekAgo = new Date();
34+
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
35+
if (isLiked.createdAt > oneWeekAgo) {
36+
const notification = await postgres.notification.findFirst({
37+
where: {
38+
senderId: user.id,
39+
receiverId: comment.authorId,
40+
type: "commentLike",
41+
},
42+
orderBy: {
43+
createdAt: "desc",
44+
},
45+
select: {
46+
id: true,
47+
},
48+
});
49+
50+
if (notification) {
51+
await postgres.notification.delete({
52+
where: {
53+
id: notification.id,
54+
},
55+
});
56+
}
57+
}
3358
} else {
34-
await postgres.commentLike.create({
59+
const commentLike = await postgres.commentLike.create({
3560
data: {
3661
commentId,
3762
authorId: user.id,
3863
},
64+
include: {
65+
comment: {
66+
select: {
67+
post: {
68+
include: {
69+
author: {
70+
select: {
71+
username: true,
72+
},
73+
},
74+
}
75+
},
76+
content: true,
77+
},
78+
},
79+
},
80+
});
81+
82+
const sender = await postgres.user.findUnique({
83+
where: {
84+
id: user.id,
85+
},
86+
select: {
87+
id: true,
88+
username: true,
89+
},
3990
});
91+
92+
const receiver = await postgres.user.findUnique({
93+
where: {
94+
id: comment.authorId,
95+
},
96+
select: {
97+
id: true,
98+
},
99+
});
100+
101+
if (sender && receiver) {
102+
const message = `"${commentLike.comment.content}"`;
103+
const type = "commentLike";
104+
const url = `/@${commentLike.comment.post.author.username}/${commentLike.comment.post.url}?commentsOpen=true`;
105+
await postgres.notification.create({
106+
data: {
107+
content: message,
108+
type,
109+
url,
110+
receiverId: receiver?.id || "",
111+
senderId: sender?.id || "",
112+
},
113+
});
114+
}
40115
console.log("Created like");
41116
}
42117
return new Response(null, { status: 200 });

app/api/follow/route.ts

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ export async function GET(request: NextRequest) {
2929
},
3030
});
3131

32+
// if followed during 1 week, delete notification
33+
const oneWeekAgo = new Date();
34+
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
35+
if (isFollowed.createdAt > oneWeekAgo) {
36+
const notification = await postgres.notification.findFirst({
37+
where: {
38+
senderId: followerId,
39+
receiverId: followeeId,
40+
type: "follow",
41+
},
42+
orderBy: {
43+
createdAt: "desc",
44+
},
45+
select: {
46+
id: true,
47+
},
48+
});
49+
50+
if (notification) {
51+
await postgres.notification.delete({
52+
where: {
53+
id: notification.id,
54+
},
55+
});
56+
}
57+
}
58+
3259
return NextResponse.json({ message: "unfollowed" }, { status: 200 });
3360
} else {
3461
await postgres.follow.create({
@@ -40,33 +67,33 @@ export async function GET(request: NextRequest) {
4067

4168
// Check if followerId and followeeId are not null
4269
if (followerId && followeeId) {
43-
//Create notification
44-
const sender = await postgres.user.findUnique({
45-
where: {
46-
id: followerId,
47-
},
48-
});
49-
50-
const receiver = await postgres.user.findUnique({
51-
where: {
52-
id: followeeId,
53-
},
70+
//Create notification
71+
const sender = await postgres.user.findUnique({
72+
where: {
73+
id: followerId,
74+
},
75+
});
76+
77+
const receiver = await postgres.user.findUnique({
78+
where: {
79+
id: followeeId,
80+
},
81+
});
82+
83+
// Check if sender and receiver are not null
84+
if (sender && receiver) {
85+
const message = `${sender?.name || sender?.username} is now following you`;
86+
const type = "follow";
87+
const url = `/@${sender?.username}`;
88+
await create({
89+
content: message,
90+
type,
91+
url,
92+
receiverId: receiver?.id || "",
93+
senderId: sender?.id || "",
5494
});
55-
56-
// Check if sender and receiver are not null
57-
if (sender && receiver) {
58-
const message = `${sender?.name || sender?.username} followed you`;
59-
const type = "follow";
60-
const url = `/@${sender?.username}`
61-
await create({
62-
content: message,
63-
type,
64-
url,
65-
receiverId: receiver?.id || "",
66-
senderId: sender?.id || "",
67-
});
68-
}
6995
}
96+
}
7097

7198
return NextResponse.json({ message: "followed" }, { status: 200 });
7299
}

0 commit comments

Comments
 (0)