diff --git a/.gitignore b/.gitignore index 96fab4f..6e1d90e 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ yarn-error.log* # Misc .DS_Store *.pem +.qodo diff --git a/apps/X/app/(pages)/profile/page.tsx b/apps/X/app/(pages)/profile/page.tsx new file mode 100644 index 0000000..4241d06 --- /dev/null +++ b/apps/X/app/(pages)/profile/page.tsx @@ -0,0 +1,22 @@ +"use client"; + +import { CenterComp, HomeLeft } from "@/components/ui"; +import { UserInfo } from "@/components/ui/Profile/UserInfo"; + +const page = () => { + return ( +
+
+ +
+
+
+
+ +
+
+
+
+ ); +}; +export default page; diff --git a/apps/X/app/api/post/route.ts b/apps/X/app/api/post/route.ts index 92dcb66..b741956 100644 --- a/apps/X/app/api/post/route.ts +++ b/apps/X/app/api/post/route.ts @@ -6,6 +6,7 @@ import { NextRequest, NextResponse } from "next/server"; const prisma = new PrismaClient(); +//? GET Tweet export async function GET() { const session = await getServerSession(authOptions); if (!session) { @@ -31,13 +32,10 @@ export async function GET() { return NextResponse.json({ userId: session.user.id }); } +//? POST Tweet export const POST = async (req: NextRequest) => { try { const session = await getServerSession(authOptions); - // console.log("Reaching in Post"); - // console.log(session, "This is the user"); - // console.log(session?.user.id, "This is the userID"); - // console.log(session?.user, "This is the userID"); if (!session?.user?.id) { return NextResponse.json( @@ -74,10 +72,11 @@ export const POST = async (req: NextRequest) => { } }; +//? DELETE Tweet export async function DELETE(req: NextRequest) { - try { + try { const session = await getServerSession(authOptions); - + if (!session?.user?.id) { return NextResponse.json( { error: "Unauthorized - User not authenticated" }, @@ -96,23 +95,20 @@ export async function DELETE(req: NextRequest) { where: { id: Number(id) }, }); if (!tweet) { - return NextResponse.json( - { message: "Tweet not found" }, - { status: 404 } - ); + return NextResponse.json({ message: "Tweet not found" }, { status: 404 }); } if (tweet.userID !== Number(userDel)) { - return NextResponse.json({message:"Unauthorized"}) + return NextResponse.json({ message: "Unauthorized" }); } const tweetId = Number(id); const deleteTweet = await prisma.tweet.update({ - where: { id: tweetId}, + where: { id: tweetId }, data: { IsDelete: true, }, }); console.log("This is the response", deleteTweet); - + return NextResponse.json({ message: "Done with delete" }, { status: 200 }); } catch (error) { console.log("Getting error in Delete", error); diff --git a/apps/X/app/api/user/route.ts b/apps/X/app/api/user/route.ts new file mode 100644 index 0000000..e39eeeb --- /dev/null +++ b/apps/X/app/api/user/route.ts @@ -0,0 +1,39 @@ +import { PrismaClient } from "@prisma/client"; +import { authOptions } from "app/lib/auth"; +import { getServerSession } from "next-auth"; +import { NextResponse } from "next/server"; + +const prisma = new PrismaClient(); + +export const GET = async () => { + console.log("Hitting the user get rout"); + + const session = await getServerSession(authOptions); + if (!session) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + + const userID = session.user.id; + + try { + console.log("Hitting the user get rout 22"); + const user = await prisma.user.findMany({ + include: { + tweets: { + where: { + IsDelete: false, + }, + }, + }, + where: { id: Number(userID) }, + }); + console.log("This is the response", user); + return NextResponse.json({ data: user }, { status: 200 }); + } catch (error) { + console.log("Error while fetching from DB", error); + return NextResponse.json({ + status: 400, + message: "Error while fetching from DB", + }); + } +}; diff --git a/apps/X/src/components/LoaderComp.tsx b/apps/X/src/components/LoaderComp.tsx new file mode 100644 index 0000000..a849bcc --- /dev/null +++ b/apps/X/src/components/LoaderComp.tsx @@ -0,0 +1,23 @@ +export const LoaderComp = () => { + return ( +
+ + Loading... +
+ ); +}; diff --git a/apps/X/src/components/RouteGuard.tsx b/apps/X/src/components/RouteGuard.tsx index 29381a4..19d2681 100644 --- a/apps/X/src/components/RouteGuard.tsx +++ b/apps/X/src/components/RouteGuard.tsx @@ -2,6 +2,7 @@ import { useSession } from "next-auth/react"; import { usePathname, useRouter } from "next/navigation"; import { useEffect } from "react"; +import { X_loaderComp } from "./X_loaderComp"; const publicPaths = ["/signin", "/login", "/error"]; @@ -33,19 +34,7 @@ export function RouteGard({ children }: { children: React.ReactNode }) { }, [session, status, router, pathname]); if (status == "loading") { - return ( -
- -
- ); + return ; } return <>{children}; diff --git a/apps/X/src/components/TopHeader.tsx b/apps/X/src/components/TopHeader.tsx new file mode 100644 index 0000000..dad359a --- /dev/null +++ b/apps/X/src/components/TopHeader.tsx @@ -0,0 +1,3 @@ +export const TopHeader = () => { + return
TopHeader
; +}; diff --git a/apps/X/src/components/X_loaderComp.tsx b/apps/X/src/components/X_loaderComp.tsx new file mode 100644 index 0000000..abd8c21 --- /dev/null +++ b/apps/X/src/components/X_loaderComp.tsx @@ -0,0 +1,15 @@ +export const X_loaderComp = () => { + return ( +
+ +
+ ); +}; diff --git a/apps/X/src/components/ui/Post/TopPost.tsx b/apps/X/src/components/ui/Post/TopNavbar.tsx similarity index 100% rename from apps/X/src/components/ui/Post/TopPost.tsx rename to apps/X/src/components/ui/Post/TopNavbar.tsx diff --git a/apps/X/src/components/ui/Profile/UserInfo.tsx b/apps/X/src/components/ui/Profile/UserInfo.tsx new file mode 100644 index 0000000..f7615a4 --- /dev/null +++ b/apps/X/src/components/ui/Profile/UserInfo.tsx @@ -0,0 +1,89 @@ +"use client"; +import { TopHeader } from "@/components/TopHeader"; +import axios from "axios"; +import { useSession } from "next-auth/react"; +import { useEffect } from "react"; +import { AiOutlineLink } from "react-icons/ai"; +import { GrLocation } from "react-icons/gr"; +import { IoCalendarOutline } from "react-icons/io5"; +import { PiBalloon } from "react-icons/pi"; + +export const UserInfo = () => { + const { data: session } = useSession(); + useEffect(() => { + const fetchUserData = async () => { + try { + const response = await axios.get("api/user"); + console.log("User data", response.data); + } catch (error) { + console.log("Getting user data failed", error); + } + }; + fetchUserData(); + }, []); + + return ( +
+
+
+ +
+
+
+
+ Extra large avatar +
+
+
+

{session?.user?.name}

+

@{session?.user?.username}

+
+
+
+

+
+
+

+ + location +

+ + {" "} + buymeacoffee.com/mscode07 + +

+ {} +

+
+

+ Joined December 2017 +

+
+
+

2,147

+ Following +
+
+

3,605

+ Followers +
+
+
+
+
+
+ ); +}; diff --git a/apps/X/src/components/ui/TweetComp.tsx b/apps/X/src/components/ui/TweetComp.tsx index a481a5b..100f866 100644 --- a/apps/X/src/components/ui/TweetComp.tsx +++ b/apps/X/src/components/ui/TweetComp.tsx @@ -37,18 +37,18 @@ export const TweetComp = ({ tweet }: TweetProps) => {
-
+
{tweet.user.name[0]}
-
+

{tweet.user.name}

- {/*

@tweet.content

*/} +

@{tweet.user.name}

. @@ -61,7 +61,7 @@ export const TweetComp = ({ tweet }: TweetProps) => {

{/*

...

*/} -
+
... @@ -92,7 +92,7 @@ export const TweetComp = ({ tweet }: TweetProps) => { {/* {tweet.likes} */} -
+
diff --git a/apps/X/src/components/ui/home/CenterComp.tsx b/apps/X/src/components/ui/home/CenterComp.tsx index 7c5d31f..4758f4c 100644 --- a/apps/X/src/components/ui/home/CenterComp.tsx +++ b/apps/X/src/components/ui/home/CenterComp.tsx @@ -1,7 +1,7 @@ "use client"; import axios from "axios"; import { useEffect, useState } from "react"; -import { TopHead, TopPost, TweetComp } from ".."; +import { LoaderComp, TopHead, TopPost, TweetComp, X_logo } from ".."; interface Tweet { id: number; @@ -20,8 +20,6 @@ export const CenterComp = () => { setLoading(true); const response = await axios.get("api/post"); const tweetData = response.data.data; - // console.log(">>>>>>>>>>>>>>>>>>>>>>>>", tweetData); - if (Array.isArray(tweetData) && response.data.data.length > 0) { setTweets(tweetData); } else { @@ -53,7 +51,9 @@ export const CenterComp = () => {
{loading ? ( -
Loading
+
+ +
) : error ? (
{error}
) : ( diff --git a/apps/X/src/components/ui/home/HomeComp.tsx b/apps/X/src/components/ui/home/HomeComp.tsx index ea8d4f9..e7197b1 100644 --- a/apps/X/src/components/ui/home/HomeComp.tsx +++ b/apps/X/src/components/ui/home/HomeComp.tsx @@ -3,11 +3,11 @@ import { CenterComp, HomeLeft, HomeRight } from "@/components/ui"; export const HomeComp = () => { return (
-
+
-
+
{/*
diff --git a/apps/X/src/components/ui/home/HomeLeft.tsx b/apps/X/src/components/ui/home/HomeLeft.tsx index 0aa160d..b0bc073 100644 --- a/apps/X/src/components/ui/home/HomeLeft.tsx +++ b/apps/X/src/components/ui/home/HomeLeft.tsx @@ -1,5 +1,7 @@ "use client"; +import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +import { useSession } from "next-auth/react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { AiOutlineThunderbolt } from "react-icons/ai"; @@ -11,11 +13,9 @@ import { IoMdSearch } from "react-icons/io"; import { MdOutlineMail } from "react-icons/md"; import { RiGroupLine, RiNotification2Line } from "react-icons/ri"; import { TbOctagonPlus } from "react-icons/tb"; -import { Button, UserAvatar, X_logo } from ".."; +import { Button, X_logo } from ".."; import GrokIcon from "../Grok"; import X_Icon from "../X_Icon"; -import { useSession } from "next-auth/react"; -import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; export const HomeLeft = () => { const router = useRouter(); @@ -113,12 +113,14 @@ export const HomeLeft = () => {
-
-
- + +
+
+ +
+
Profile
-
Profile
-
+
@@ -144,10 +146,13 @@ export const HomeLeft = () => {
- + {session?.user?.name?.[0]} -
+

{session?.user?.name}

@{session?.user?.username} @@ -156,8 +161,8 @@ export const HomeLeft = () => {

-
+
-
+
); -}; \ No newline at end of file +}; diff --git a/apps/X/src/components/ui/index.ts b/apps/X/src/components/ui/index.ts index c4a4ed6..6d5d3ac 100644 --- a/apps/X/src/components/ui/index.ts +++ b/apps/X/src/components/ui/index.ts @@ -14,13 +14,22 @@ import { Button } from "./button"; import { HomeComp } from "./home/HomeComp"; import { HomeLeft } from "./home/HomeLeft"; import { TopHead } from "./Post/topHead"; -import { TopPost } from "./Post/TopPost"; +import { TopPost } from "./Post/TopNavbar"; +import { LoaderComp } from "../LoaderComp"; +import { TopHeader } from "../TopHeader"; +import { userInfo } from "os"; + +import { X_loaderComp } from "../X_loaderComp"; export { TopHead, TopPost, SigninComp, HomeComp, + LoaderComp, + TopHeader, + X_loaderComp, + userInfo, HomeLeft, Button, UserAvatar, diff --git a/packages/db/prisma/migrations/20250316134806_adding_new_cols/migration.sql b/packages/db/prisma/migrations/20250316134806_adding_new_cols/migration.sql new file mode 100644 index 0000000..558dd3a --- /dev/null +++ b/packages/db/prisma/migrations/20250316134806_adding_new_cols/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "DOB" TIMESTAMP(3), +ADD COLUMN "location" TEXT; diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 74529e4..0f5dc8c 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -23,6 +23,8 @@ model User { image String? tweets Tweet[] createdDate DateTime @default(now()) + DOB DateTime? + location String? } model Tweet {