Skip to content

Commit e983f59

Browse files
committed
working on user Profile
1 parent 4671715 commit e983f59

File tree

8 files changed

+738
-28
lines changed

8 files changed

+738
-28
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import prisma from "@repo/db/client";
2+
import { authOptions } from "app/lib/auth";
3+
import { getServerSession } from "next-auth";
4+
import { NextResponse } from "next/server";
5+
6+
export async function GET() {
7+
try {
8+
const session = await getServerSession(authOptions);
9+
console.log("Getting the UserID ", session?.user?.id);
10+
const userId = Number(session?.user?.id);
11+
12+
console.log(typeof userId, "This is the type of UserID");
13+
if (!session) {
14+
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
15+
}
16+
17+
const userPost = await prisma.tweet.findMany({
18+
include: {
19+
user: {
20+
select: {
21+
name: true,
22+
},
23+
},
24+
},
25+
where: { userID: userId },
26+
});
27+
console.log(userPost, "This is the the users Tweet");
28+
return NextResponse.json({ data: userPost }, { status: 200 });
29+
} catch (error) {
30+
console.log("Getting Erroe while fetching user's Posts", error);
31+
return NextResponse.json(
32+
{ error: "Getting error for userTweets" },
33+
{ status: 200 }
34+
);
35+
}
36+
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { PrismaClient } from "@prisma/client";
22
import { authOptions } from "app/lib/auth";
3-
import { error } from "console";
43
import { getServerSession } from "next-auth";
54
//? https://github.com/code100x/cms/blob/main/src/app/api/admin/content/route.ts
65
import { NextRequest, NextResponse } from "next/server";
@@ -29,7 +28,6 @@ export async function GET() {
2928
} catch (error) {
3029
console.log("Error while fetching from DB", error);
3130
}
32-
3331
return NextResponse.json({ userId: session.user.id });
3432
}
3533

@@ -47,9 +45,6 @@ export const POST = async (req: NextRequest) => {
4745
const sessionUserId = parseInt(session.user.id);
4846
const user = await prisma.user.findFirst({ where: { id: sessionUserId } });
4947

50-
// if (!user) {
51-
// return NextResponse.json({ error: "Not a valid User" }, { status: 401 });
52-
// }
5348
const body = await req.json();
5449
console.log("Request Body:", body);
5550

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { NextResponse } from "next/server";
66
const prisma = new PrismaClient();
77

88
export const GET = async () => {
9-
console.log("Hitting the user get rout");
10-
119
const session = await getServerSession(authOptions);
1210
if (!session) {
1311
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
@@ -16,7 +14,6 @@ export const GET = async () => {
1614
const userID = session.user.id;
1715

1816
try {
19-
console.log("Hitting the user get rout 22");
2017
const user = await prisma.user.findMany({
2118
include: {
2219
tweets: {
@@ -27,7 +24,7 @@ export const GET = async () => {
2724
},
2825
where: { id: Number(userID) },
2926
});
30-
console.log("This is the response", user);
27+
//console.log("This is the User from User Route", user);
3128
return NextResponse.json({ data: user }, { status: 200 });
3229
} catch (error) {
3330
console.log("Error while fetching from DB", error);

apps/X/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
"check-types": "tsc --noEmit"
1212
},
1313
"dependencies": {
14+
"@heroui/tabs": "^2.2.13",
1415
"@radix-ui/react-avatar": "^1.1.2",
1516
"@radix-ui/react-dialog": "^1.1.4",
1617
"@radix-ui/react-popover": "^1.1.6",
1718
"@radix-ui/react-slot": "^1.1.1",
19+
"@radix-ui/react-tabs": "^1.1.3",
1820
"@repo/ui": "*",
1921
"axios": "^1.7.9",
2022
"bcrypt": "^5.1.1",

apps/X/src/components/ui/Profile/UserInfo.tsx

Lines changed: 189 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use client";
2+
23
import { TopHeader } from "@/components/TopHeader";
34
import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar";
45
import axios from "axios";
@@ -8,6 +9,9 @@ import { AiOutlineLink } from "react-icons/ai";
89
import { GrLocation } from "react-icons/gr";
910
import { IoCalendarOutline } from "react-icons/io5";
1011
import { PiBalloon } from "react-icons/pi";
12+
import { Button } from "../button";
13+
import { TweetComp } from "../TweetComp";
14+
import { NextResponse } from "next/server";
1115

1216
interface UserDataProps {
1317
DOB: string;
@@ -17,9 +21,18 @@ interface UserDataProps {
1721
username: string;
1822
biolink: string;
1923
}
24+
interface Tweet {
25+
id: number;
26+
content: string;
27+
userID: number;
28+
likes: number;
29+
createdDate: string;
30+
user: { name: string };
31+
}
2032
export const UserInfo = () => {
2133
const { data: session } = useSession();
2234
const [userData, setUserData] = useState<UserDataProps[] | null>(null);
35+
const [userTweet, setUserTweet] = useState<Tweet[]>([]);
2336
const [error, setError] = useState("");
2437
const [loading, setLoading] = useState(false);
2538

@@ -31,7 +44,7 @@ export const UserInfo = () => {
3144
const u_Data = response.data.data;
3245
if (Array.isArray(u_Data) && response.data.data.length > 0) {
3346
setUserData(u_Data);
34-
console.log(u_Data, "Here it is");
47+
// console.log(u_Data, "Here it is");
3548
} else {
3649
setError("No user data found");
3750
}
@@ -42,30 +55,53 @@ export const UserInfo = () => {
4255
}
4356
};
4457
fetchUserData();
58+
59+
const fetchUserTweet = async () => {
60+
try {
61+
const response = await axios.get(`api/post/$[userID]`);
62+
const tweetsByUser = response.data.data;
63+
console.log(tweetsByUser, "This is from user");
64+
setUserTweet(tweetsByUser);
65+
} catch (error) {
66+
console.log(error);
67+
}
68+
};
69+
fetchUserTweet();
4570
}, []);
4671

4772
return (
4873
<div>
4974
<div>
5075
<div className=""></div>
5176
<div>
52-
<div
53-
className="w-full h-64 bg-cover bg-center object-cover relative"
54-
style={{
55-
backgroundImage: `url('https://github.com/mscode07.png')`,
56-
}}
57-
>
58-
<div className="absolute -bottom-16 left-4">
59-
<Avatar>
60-
<AvatarImage
61-
src="https://github.com/mscode07.png"
62-
className="rounded-full h-36 w-36 border-black border-4 "
63-
/>
64-
<AvatarFallback></AvatarFallback>
65-
</Avatar>
77+
<div>
78+
<div
79+
className="w-full h-64 bg-cover bg-center object-cover relative"
80+
style={{
81+
backgroundImage: `url('https://github.com/mscode07.png')`,
82+
}}
83+
>
84+
<div className="">
85+
<div className=" w-full">
86+
<Avatar className="absolute -bottom-20 left-4">
87+
<AvatarImage
88+
src="https://github.com/mscode07.png"
89+
className="rounded-full h-36 w-36 border-black border-4 "
90+
/>
91+
<AvatarFallback></AvatarFallback>
92+
</Avatar>
93+
</div>
94+
</div>
95+
</div>
96+
<div className="text-right pr-4 mt-4">
97+
<div>
98+
<Button className="bg-black text-white rounded-2xl border px-7 border-white hover:bg-neutral-900 transition duration-200 font-bold text-md">
99+
Edit Profile
100+
</Button>
101+
</div>
66102
</div>
67103
</div>
68-
<div className="mt-20 ml-3">
104+
<div className="mt-10 ml-3">
69105
<p className="text-2xl font-bold">{session?.user?.name}</p>
70106
<p className="text-gray-500">@{session?.user?.username}</p>
71107
</div>
@@ -109,8 +145,145 @@ export const UserInfo = () => {
109145
</div>
110146
</div>
111147
</div>
148+
149+
{/* <div className="mb-4 border-b border-gray-200 dark:border-gray-700">
150+
<ul
151+
className="flex flex-wrap -mb-px text-sm font-medium text-center"
152+
id="default-styled-tab"
153+
data-tabs-toggle="#default-styled-tab-content"
154+
data-tabs-active-classes="text-purple-600 hover:text-purple-600 dark:text-purple-500 dark:hover:text-purple-500 border-purple-600 dark:border-purple-500"
155+
data-tabs-inactive-classes="dark:border-transparent text-gray-500 hover:text-gray-600 dark:text-gray-400 border-gray-100 hover:border-gray-300 dark:border-gray-700 dark:hover:text-gray-300"
156+
role="tablist"
157+
>
158+
<li className="me-2" role="presentation">
159+
<button
160+
className="inline-block p-4 border-b-2 rounded-t-lg"
161+
id="profile-styled-tab"
162+
data-tabs-target="#styled-profile"
163+
type="button"
164+
role="tab"
165+
aria-controls="profile"
166+
aria-selected="false"
167+
>
168+
Profile
169+
</button>
170+
</li>
171+
<li className="me-2" role="presentation">
172+
<button
173+
className="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300"
174+
id="dashboard-styled-tab"
175+
data-tabs-target="#styled-dashboard"
176+
type="button"
177+
role="tab"
178+
aria-controls="dashboard"
179+
aria-selected="false"
180+
>
181+
Dashboard
182+
</button>
183+
</li>
184+
<li className="me-2" role="presentation">
185+
<button
186+
className="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300"
187+
id="settings-styled-tab"
188+
data-tabs-target="#styled-settings"
189+
type="button"
190+
role="tab"
191+
aria-controls="settings"
192+
aria-selected="false"
193+
>
194+
Settings
195+
</button>
196+
</li>
197+
<li role="presentation">
198+
<button
199+
className="inline-block p-4 border-b-2 rounded-t-lg hover:text-gray-600 hover:border-gray-300 dark:hover:text-gray-300"
200+
id="contacts-styled-tab"
201+
data-tabs-target="#styled-contacts"
202+
type="button"
203+
role="tab"
204+
aria-controls="contacts"
205+
aria-selected="false"
206+
>
207+
Contacts
208+
</button>
209+
</li>
210+
</ul>
211+
</div>
212+
<div id="default-styled-tab-content">
213+
<div
214+
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
215+
id="styled-profile"
216+
role="tabpanel"
217+
aria-labelledby="profile-tab"
218+
>
219+
<p className="text-sm text-gray-500 dark:text-gray-400">
220+
This is some placeholder content the{" "}
221+
<strong className="font-medium text-gray-800 dark:text-white">
222+
Profile tab associated content
223+
</strong>
224+
. Clicking another tab will toggle the visibility of this one
225+
for the next. The tab JavaScript swaps classes to control the
226+
content visibility and styling.
227+
</p>
228+
</div>
229+
<div
230+
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
231+
id="styled-dashboard"
232+
role="tabpanel"
233+
aria-labelledby="dashboard-tab"
234+
>
235+
<p className="text-sm text-gray-500 dark:text-gray-400">
236+
This is some placeholder content the{" "}
237+
<strong className="font-medium text-gray-800 dark:text-white">
238+
Dashboard tabs associated content
239+
</strong>
240+
. Clicking another tab will toggle the visibility of this one
241+
for the next. The tab JavaScript swaps classes to control the
242+
content visibility and styling.
243+
</p>
244+
</div>
245+
<div
246+
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
247+
id="styled-settings"
248+
role="tabpanel"
249+
aria-labelledby="settings-tab"
250+
>
251+
<p className="text-sm text-gray-500 dark:text-gray-400">
252+
This is some placeholder content the{" "}
253+
<strong className="font-medium text-gray-800 dark:text-white">
254+
Settings tabs associated content
255+
</strong>
256+
. Clicking another tab will toggle the visibility of this one
257+
for the next. The tab JavaScript swaps classNamees to control
258+
the content visibility and styling.
259+
</p>
260+
</div>
261+
<div
262+
className="hidden p-4 rounded-lg bg-gray-50 dark:bg-gray-800"
263+
id="styled-contacts"
264+
role="tabpanel"
265+
aria-labelledby="contacts-tab"
266+
>
267+
<p className="text-sm text-gray-500 dark:text-gray-400">
268+
This is some placeholder content the{" "}
269+
<strong className="font-medium text-gray-800 dark:text-white">
270+
Contacts tabs associated content
271+
</strong>
272+
. Clicking another tab will toggle the visibility of this one
273+
for the next. The tab JavaScript swaps classes to control the
274+
content visibility and styling.
275+
</p>
276+
</div>
277+
</div> */}
112278
</div>
113279
</div>
280+
<br />
281+
<hr />
282+
<div>
283+
{userTweet.map((tweet) => (
284+
<TweetComp key={tweet.id} tweet={tweet} />
285+
))}
286+
</div>
114287
</div>
115288
);
116289
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const HomeLeft = () => {
113113
</div>
114114
</div>
115115
<div className="flex items-center text-xl mb-3">
116-
<Link href="/profile">
116+
<Link href={`/${session?.user?.username}`}>
117117
<div className="custom:hover:bg-neutral-900 flex gap-4 custom:hover:bg-opacity-40 transition duration-200 custom:hover:rounded-2xl px-4 py-2">
118118
<div className="hover:bg-neutral-900 flex gap-4 hover:bg-opacity-40 transition duration-200 hover:rounded-2xl text-2xl">
119119
<FaRegUser />

0 commit comments

Comments
 (0)