Skip to content

Commit bfe66f5

Browse files
committed
working on userProfile
1 parent ba92fc5 commit bfe66f5

File tree

10 files changed

+145
-30
lines changed

10 files changed

+145
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ yarn-error.log*
3636
# Misc
3737
.DS_Store
3838
*.pem
39+
.qodo

apps/X/app/(pages)/profile/page.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ const page = () => {
1010
<HomeLeft />
1111
</div>
1212
<div className="flex flex-grow">
13-
<div className="border border-y-0 custom:w-5/12 w-">
13+
<div className="border border-y-0 custom:w-6/12 w-10/12">
1414
<div>
1515
<UserInfo />
1616
</div>
1717
</div>
18-
{/* <div className="invisible h-screen sticky top-0">
19-
<HomeRight />
20-
</div> */}
2118
</div>
2219
</div>
2320
);

apps/X/app/api/post/route.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { NextRequest, NextResponse } from "next/server";
66

77
const prisma = new PrismaClient();
88

9+
//? GET Tweet
910
export async function GET() {
1011
const session = await getServerSession(authOptions);
1112
if (!session) {
@@ -31,13 +32,10 @@ export async function GET() {
3132
return NextResponse.json({ userId: session.user.id });
3233
}
3334

35+
//? POST Tweet
3436
export const POST = async (req: NextRequest) => {
3537
try {
3638
const session = await getServerSession(authOptions);
37-
// console.log("Reaching in Post");
38-
// console.log(session, "This is the user");
39-
// console.log(session?.user.id, "This is the userID");
40-
// console.log(session?.user, "This is the userID");
4139

4240
if (!session?.user?.id) {
4341
return NextResponse.json(
@@ -74,10 +72,11 @@ export const POST = async (req: NextRequest) => {
7472
}
7573
};
7674

75+
//? DELETE Tweet
7776
export async function DELETE(req: NextRequest) {
78-
try {
77+
try {
7978
const session = await getServerSession(authOptions);
80-
79+
8180
if (!session?.user?.id) {
8281
return NextResponse.json(
8382
{ error: "Unauthorized - User not authenticated" },
@@ -96,23 +95,20 @@ export async function DELETE(req: NextRequest) {
9695
where: { id: Number(id) },
9796
});
9897
if (!tweet) {
99-
return NextResponse.json(
100-
{ message: "Tweet not found" },
101-
{ status: 404 }
102-
);
98+
return NextResponse.json({ message: "Tweet not found" }, { status: 404 });
10399
}
104100
if (tweet.userID !== Number(userDel)) {
105-
return NextResponse.json({message:"Unauthorized"})
101+
return NextResponse.json({ message: "Unauthorized" });
106102
}
107103
const tweetId = Number(id);
108104
const deleteTweet = await prisma.tweet.update({
109-
where: { id: tweetId},
105+
where: { id: tweetId },
110106
data: {
111107
IsDelete: true,
112108
},
113109
});
114110
console.log("This is the response", deleteTweet);
115-
111+
116112
return NextResponse.json({ message: "Done with delete" }, { status: 200 });
117113
} catch (error) {
118114
console.log("Getting error in Delete", error);

apps/X/app/api/user/route.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { PrismaClient } from "@prisma/client";
2+
import { authOptions } from "app/lib/auth";
3+
import { getServerSession } from "next-auth";
4+
import { NextResponse } from "next/server";
5+
6+
const prisma = new PrismaClient();
7+
8+
export const GET = async () => {
9+
console.log("Hitting the user get rout");
10+
11+
const session = await getServerSession(authOptions);
12+
if (!session) {
13+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
14+
}
15+
16+
const userID = session.user.id;
17+
18+
try {
19+
console.log("Hitting the user get rout 22");
20+
const user = await prisma.user.findMany({
21+
include: {
22+
tweets: {
23+
where: {
24+
IsDelete: false,
25+
},
26+
},
27+
},
28+
where: { id: Number(userID) },
29+
});
30+
console.log("This is the response", user);
31+
return NextResponse.json({ data: user }, { status: 200 });
32+
} catch (error) {
33+
console.log("Error while fetching from DB", error);
34+
return NextResponse.json({
35+
status: 400,
36+
message: "Error while fetching from DB",
37+
});
38+
}
39+
};
Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,89 @@
1+
"use client";
12
import { TopHeader } from "@/components/TopHeader";
3+
import axios from "axios";
4+
import { useSession } from "next-auth/react";
5+
import { useEffect } from "react";
6+
import { AiOutlineLink } from "react-icons/ai";
7+
import { GrLocation } from "react-icons/gr";
8+
import { IoCalendarOutline } from "react-icons/io5";
9+
import { PiBalloon } from "react-icons/pi";
210

311
export const UserInfo = () => {
12+
const { data: session } = useSession();
13+
useEffect(() => {
14+
const fetchUserData = async () => {
15+
try {
16+
const response = await axios.get("api/user");
17+
console.log("User data", response.data);
18+
} catch (error) {
19+
console.log("Getting user data failed", error);
20+
}
21+
};
22+
fetchUserData();
23+
}, []);
24+
425
return (
526
<div>
627
<div>
7-
<TopHeader />
28+
<div>
29+
<TopHeader />
30+
</div>
31+
<div>
32+
<div
33+
className="relative w-full h-64 bg-cover bg-center object-cover"
34+
style={{
35+
backgroundImage: `url('https://github.com/mscode07.png')`,
36+
}}
37+
>
38+
<div>
39+
<img
40+
className="absolute rounded-full w-40 h-40 border-4 border-black bottom-0 top-48 left-3
41+
"
42+
src="https://github.com/mscode07.png"
43+
alt="Extra large avatar"
44+
/>
45+
</div>
46+
</div>
47+
<div className="mt-24 ml-3">
48+
<p className="text-2xl font-bold">{session?.user?.name}</p>
49+
<p className="text-gray-500">@{session?.user?.username}</p>
50+
</div>
51+
</div>
52+
<div className="ml-3 mt-2 w-full">
53+
<p className="mb-3"></p>
54+
<div>
55+
<div className="flex gap-2">
56+
<p className="flex items-center text-gray-500 gap-1">
57+
<GrLocation className="text-xl" />
58+
location
59+
</p>
60+
<a
61+
className="text-blue-500 flex items-center gap-1"
62+
href="https://buymeacoffee.com/mscode07"
63+
>
64+
<AiOutlineLink className="text-gray-500 text-xl" />{" "}
65+
buymeacoffee.com/mscode07
66+
</a>
67+
<p className="flex items-center text-gray-500 gap-1">
68+
<PiBalloon className="text-xl font-bold" /> {}
69+
</p>
70+
</div>
71+
<p className="flex items-center text-gray-500 gap-2">
72+
<IoCalendarOutline className="text-lg" /> Joined December 2017
73+
</p>
74+
<div className="flex gap-2 mt-2">
75+
<div className="flex">
76+
<p className="font-bold">2,147</p>
77+
<span className="text-gray-500 ml-1 ">Following</span>
78+
</div>
79+
<div className="flex">
80+
<p className="font-bold">3,605</p>
81+
<span className="text-gray-500 ml-1">Followers</span>
82+
</div>
83+
</div>
84+
</div>
85+
</div>
886
</div>
9-
User profile info
1087
</div>
1188
);
1289
};

apps/X/src/components/ui/TweetComp.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ export const TweetComp = ({ tweet }: TweetProps) => {
3737
<div>
3838
<div>
3939
<div className="border border-slate-800 border-spacing-x-0.5">
40-
<div className="flex p-3 gap-2">
40+
<div className="flex p-3 gap-2 w-full">
4141
<div className="mt-1 cursor-pointer">
4242
<Avatar>
4343
<AvatarImage />
4444
<AvatarFallback>{tweet.user.name[0]}</AvatarFallback>
4545
</Avatar>
4646
</div>
47-
<div className="">
47+
<div className="w-full">
4848
<div className="grid grid-cols-6">
4949
<div className="flex col-span-5">
5050
<p className="font-bold cursor-pointer">{tweet.user.name}</p>
51-
{/* <p> @tweet.content</p> */}
51+
<p className="text-slate-500 pl-2">@{tweet.user.name}</p>
5252
<span className="px-1 mx-1 items-center text-slate-500">
5353
.
5454
</span>
@@ -61,7 +61,7 @@ export const TweetComp = ({ tweet }: TweetProps) => {
6161
</p>
6262
</div>
6363
{/* <p className="text-end">...</p> */}
64-
<div className="ml-auto cursor-pointer hover:bg-black hover:rounded-2xl">
64+
<div className="flex justify-end cursor-pointer hover:bg-black hover:rounded-2xl pr-3">
6565
<Popover>
6666
<PopoverTrigger className="font-bold text-slate-500">
6767
...
@@ -92,7 +92,7 @@ export const TweetComp = ({ tweet }: TweetProps) => {
9292
<FiHeart className="cursor-pointer" />
9393
{/* <span>{tweet.likes} </span> */}
9494
<IoIosStats className="cursor-pointer" />
95-
<div className="flex">
95+
<div className="flex gap-3">
9696
<FaRegBookmark className="cursor-pointer" />
9797
<RiShare2Line className="cursor-pointer" />
9898
</div>

apps/X/src/components/ui/home/HomeComp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { CenterComp, HomeLeft, HomeRight } from "@/components/ui";
33
export const HomeComp = () => {
44
return (
55
<div className="flex h-screen overflow-y-auto">
6-
<div className="custom:w-96 w-10 custom:ml-24 ml-16 h-screen sticky top-0 flex-shrink-0 mr-7 custom:mr-10">
6+
<div className="custom:w-96 w-10 custom:ml-24 ml-16 h-screen sticky top-0 flex-shrink-0 mr-7 custom:mr-10">
77
<HomeLeft />
88
</div>
99
<div className="flex flex-grow">
10-
<div className="border border-y-0 custom:w-5/12 w-">
10+
<div className="border border-y-0 custom:w-6/12 w-10/12">
1111
<CenterComp />
1212
</div>
1313
{/* <div className="invisible h-screen sticky top-0">

apps/X/src/components/ui/home/HomeLeft.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use client";
22

3+
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
4+
import { useSession } from "next-auth/react";
35
import Link from "next/link";
46
import { useRouter } from "next/navigation";
57
import { AiOutlineThunderbolt } from "react-icons/ai";
@@ -11,11 +13,9 @@ import { IoMdSearch } from "react-icons/io";
1113
import { MdOutlineMail } from "react-icons/md";
1214
import { RiGroupLine, RiNotification2Line } from "react-icons/ri";
1315
import { TbOctagonPlus } from "react-icons/tb";
14-
import { Button, UserAvatar, X_logo } from "..";
16+
import { Button, X_logo } from "..";
1517
import GrokIcon from "../Grok";
1618
import X_Icon from "../X_Icon";
17-
import { useSession } from "next-auth/react";
18-
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
1919

2020
export const HomeLeft = () => {
2121
const router = useRouter();
@@ -152,7 +152,7 @@ export const HomeLeft = () => {
152152
/>
153153
<AvatarFallback>{session?.user?.name?.[0]}</AvatarFallback>
154154
</Avatar>
155-
<div>
155+
<div className="hidden custom:block">
156156
<p className="font-bold">{session?.user?.name}</p>
157157
<p className="text-slate-600 font-semibold">
158158
@{session?.user?.username}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- AlterTable
2+
ALTER TABLE "User" ADD COLUMN "DOB" TIMESTAMP(3),
3+
ADD COLUMN "location" TEXT;

packages/db/prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ model User {
2323
image String?
2424
tweets Tweet[]
2525
createdDate DateTime @default(now())
26+
DOB DateTime?
27+
location String?
2628
}
2729

2830
model Tweet {

0 commit comments

Comments
 (0)