Skip to content

Commit

Permalink
Merge pull request #16 from yusupovbg/beta
Browse files Browse the repository at this point in the history
Update v1.0.1
  • Loading branch information
thebkht committed Nov 30, 2023
2 parents 2af0cd1 + fe1b762 commit 6da80d8
Show file tree
Hide file tree
Showing 36 changed files with 936 additions and 201 deletions.
4 changes: 2 additions & 2 deletions app/(Main)/[username]/[url]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
62 changes: 62 additions & 0 deletions app/(Main)/[username]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

import PostCardSkeletonV2 from "@/components/skeletons/post-card-2";
import { Skeleton } from "@/components/ui/skeleton";

export default function Loading() {
return (
<>
<div className="md:container mx-auto px-4 pt-5">
<div className="gap-5 lg:gap-6 flex flex-col md:flex-row items-start xl:px-4 pt-5" >
<div className="w-full md:w-1/3 lg:w-1/4">
<div className={"flex flex-col items-stretch justify-between xs:h-fit details"}>
<div className="flex-1">
<div className="flex lg:flex-col items-start">
<div className="user__header flex md:block md:items-start lg:space-y-4 space-y-2 pb-4" >
<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
" />
<div className="flex items-center md:py-4 w-full justify-between">
<div className="md:space-y-3 w-full">
<Skeleton className="w-full h-8" />
<Skeleton className="w-28 h-5" />
</div>
</div>
</div>
</div>
</div>

<Skeleton className="w-full h-9" />

<div className="w-full mt-5 space-y-1.5">
<Skeleton className="w-full h-5" />
<Skeleton className="w-full h-5" />
<Skeleton className="w-full h-5" />
</div>

<div className="py-4 items-center flex gap-5 w-full">
<Skeleton className="w-full h-8" />
<Skeleton className="w-full h-8" />
</div>

<ul className="details space-y-3">
<Skeleton className="w-full h-5" />
<Skeleton className="w-full h-5" />
<Skeleton className="w-full h-5" />
</ul>
</div>
</div>
<div className="lg:pl-8 w-full">
<div className="user-articles lg:mb-6 md:mb-5 mb-4">
<div className="flex flex-col lg:gap-6 md:gap-5 gap-4">
<PostCardSkeletonV2 />
<PostCardSkeletonV2 />
<PostCardSkeletonV2 />
<PostCardSkeletonV2 />
<PostCardSkeletonV2 />
</div>
</div>
</div>
</div>
</div>
</>
)
}
13 changes: 0 additions & 13 deletions app/(Main)/explore/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import { EmptyPlaceholder } from "@/components/empty-placeholder"
import Posts from "@/components/explore/posts"
import Search from "@/components/explore/search"
import { getSessionUser } from "@/components/get-session-user"
import { Icons } from "@/components/icon"
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { getPosts } from "@/lib/prisma/posts"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import Link from "next/link"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { redirect } from "next/navigation"
import { Hash } from "lucide-react"
import { getUsers } from "@/lib/prisma/users"
import { Separator } from "@/components/ui/separator"
import { Button } from "@/components/ui/button"
import UserHoverCard from "@/components/user-hover-card"
import { searchTags } from "@/lib/prisma/tags"
import { Badge } from "@/components/ui/badge"
import ExploreComponent from "@/components/explore/tab-content"
import ExploreTab from "@/components/explore/tab"
import Users from "@/components/explore/users"
Expand Down
9 changes: 9 additions & 0 deletions app/(Main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ const [latestPosts, tags, popularPosts] = await Promise.all([
readingTime: true,
publishedAt: true,
cover: true,
_count: {
select: {
likes: true,
savedUsers: true,
readedUsers: true,
shares: true,
comments: true,
},
},
author: {
select: {
username: true,
Expand Down
17 changes: 14 additions & 3 deletions app/(Main)/tags/[tagname]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { getSessionUser } from "@/components/get-session-user";
import TagDetails from "@/components/tags/details";
import TagLatestPosts from "@/components/tags/latest-posts";
import TagPopularPosts from "@/components/tags/post";
import TagFollowers from "@/components/tags/users";
import { Separator } from "@/components/ui/separator";
import postgres from "@/lib/postgres";
import { revalidatePath } from "next/cache";
import { getFollowersByTag } from "@/lib/prisma/tags";
import { redirect } from "next/navigation";

export default async function TagPage({ params }: { params: { tagname: string } }) {
Expand Down Expand Up @@ -38,7 +39,7 @@ export default async function TagPage({ params }: { params: { tagname: string }
},
savedUsers: true,
likes: true,
_count: { select: { comments: true, likes: true, savedUsers: true } },
_count: { select: { comments: true, likes: true, savedUsers: true, shares: true } },
},
orderBy: [
{ likes: { _count: 'desc' } },
Expand All @@ -65,7 +66,7 @@ export default async function TagPage({ params }: { params: { tagname: string }
Followings: true,
}
},
_count: { select: { comments: true, likes: true, savedUsers: true } },
_count: { select: { comments: true, likes: true, savedUsers: true, shares: true } },
savedUsers: true,
},
orderBy: {
Expand All @@ -75,6 +76,8 @@ export default async function TagPage({ params }: { params: { tagname: string }
});
if (!tag) redirect("/404");
const session = await getSessionUser();

const { followers } = await getFollowersByTag({ id: tag.id, limit: 5, session: session?.id });
return (
<>
<div className="flex flex-col space-y-6 my-8">
Expand All @@ -85,6 +88,14 @@ export default async function TagPage({ params }: { params: { tagname: string }
<TagPopularPosts posts={popularPosts} tag={tag} session={session} />
</>
)}
{
followers.length > 0 && (
<>
<Separator />
<TagFollowers followers={followers} tag={tag} session={session} />
</>
)
}
{
latestPosts.length > 0 && (
<>
Expand Down
79 changes: 77 additions & 2 deletions app/api/comments/[id]/like/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
77 changes: 52 additions & 25 deletions app/api/follow/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 });
}
Expand Down
Loading

0 comments on commit 6da80d8

Please sign in to comment.