Skip to content

Commit 2063138

Browse files
committed
fixing
1 parent bfe66f5 commit 2063138

File tree

11 files changed

+97
-25
lines changed

11 files changed

+97
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { CenterComp, HomeLeft } from "@/components/ui";
3+
import { HomeLeft } from "@/components/ui";
44
import { UserInfo } from "@/components/ui/Profile/UserInfo";
55

66
const page = () => {

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { PrismaClient } from "@prisma/client";
22
import { authOptions } from "app/lib/auth";
3+
import { error } from "console";
34
import { getServerSession } from "next-auth";
45
//? https://github.com/code100x/cms/blob/main/src/app/api/admin/content/route.ts
56
import { NextRequest, NextResponse } from "next/server";
@@ -42,33 +43,41 @@ export const POST = async (req: NextRequest) => {
4243
{ error: "Unauthorized - User not authenticated" },
4344
{ status: 401 }
4445
);
45-
} else {
46-
console.log("reaching");
4746
}
47+
const sessionUserId = parseInt(session.user.id);
48+
const user = await prisma.user.findFirst({ where: { id: sessionUserId } });
4849

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

56+
console.log("Checking body content...");
5257
if (!body || !body.content) {
5358
return NextResponse.json(
54-
{ error: "content is requried" },
59+
{ error: "content is required" },
5560
{ status: 400 }
5661
);
5762
}
63+
console.log("Parsing the content...");
5864
const userId = parseInt(session.user.id);
5965
if (isNaN(userId)) {
6066
return NextResponse.json({ error: "Invalid user ID" }, { status: 400 });
6167
}
6268
const { content } = body;
69+
console.log("Creating tweet with userId:", userId, "and content:", content);
6370
const tweet = await prisma.tweet.create({
6471
data: { content, userID: userId },
6572
});
66-
// router.push("")
6773
console.log("This is the response", tweet);
68-
69-
return NextResponse.json(tweet, { status: 201 });
74+
return NextResponse.json(tweet, { status: 200 });
7075
} catch (error) {
7176
console.log("Getting error in Creating", error);
77+
return NextResponse.json(
78+
{ error: "Internal Server Error" },
79+
{ status: 500 }
80+
);
7281
}
7382
};
7483

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
"use client";
2+
import { IoArrowBack } from "react-icons/io5";
3+
import { useSession } from "next-auth/react";
4+
import { useRouter } from "next/navigation";
5+
16
export const TopHeader = () => {
2-
return <div>TopHeader</div>;
7+
const { data: session } = useSession();
8+
9+
const router = useRouter();
10+
11+
const handleBackClick = () => {
12+
router.back();
13+
};
14+
15+
return (
16+
<div>
17+
<div className="mt-3 flex items-center gap-5 cursor-pointer">
18+
<div className=" rounded-full p-2 hover:bg-neutral-800 transition duration-300 m-2">
19+
<IoArrowBack className="text-xl" onClick={handleBackClick} />
20+
</div>
21+
<div>
22+
<p className="font-bold text-xl">{session?.user?.name}</p>
23+
<p className="text-gray-500">28.3K posts</p>
24+
</div>
25+
</div>
26+
</div>
27+
);
328
};
File renamed without changes.

apps/X/src/components/ui/Post/topHead.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
"use client";
22
import { TopHeader } from "@/components/TopHeader";
3+
import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar";
34
import axios from "axios";
45
import { useSession } from "next-auth/react";
5-
import { useEffect } from "react";
6+
import { useEffect, useState } from "react";
67
import { AiOutlineLink } from "react-icons/ai";
78
import { GrLocation } from "react-icons/gr";
89
import { IoCalendarOutline } from "react-icons/io5";
910
import { PiBalloon } from "react-icons/pi";
1011

12+
interface UserDataProps {
13+
DOB: string;
14+
location: string;
15+
createdDate: string;
16+
bio: string;
17+
}
1118
export const UserInfo = () => {
1219
const { data: session } = useSession();
20+
const [userData, setUserData] = useState<UserDataProps[] | null>(null);
21+
const [error, setError] = useState("");
22+
const [loading, setLoading] = useState(false);
23+
1324
useEffect(() => {
1425
const fetchUserData = async () => {
1526
try {
27+
setLoading(true);
1628
const response = await axios.get("api/user");
17-
console.log("User data", response.data);
29+
const u_Data = response.data.data;
30+
if (Array.isArray(u_Data) && response.data.data.length > 0) {
31+
setUserData(u_Data);
32+
console.log(u_Data, "Here it is");
33+
} else {
34+
setError("No user data found");
35+
}
1836
} catch (error) {
1937
console.log("Getting user data failed", error);
38+
} finally {
39+
setLoading(false);
2040
}
2141
};
2242
fetchUserData();
@@ -36,12 +56,13 @@ export const UserInfo = () => {
3656
}}
3757
>
3858
<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-
/>
59+
<Avatar>
60+
<AvatarImage
61+
src={session?.user?.image || ""}
62+
alt={session?.user?.name || "User"}
63+
/>
64+
<AvatarFallback>{session?.user?.name?.[0]}</AvatarFallback>
65+
</Avatar>
4566
</div>
4667
</div>
4768
<div className="mt-24 ml-3">
@@ -55,7 +76,7 @@ export const UserInfo = () => {
5576
<div className="flex gap-2">
5677
<p className="flex items-center text-gray-500 gap-1">
5778
<GrLocation className="text-xl" />
58-
location
79+
{userData?.[0]?.location || "Location"}
5980
</p>
6081
<a
6182
className="text-blue-500 flex items-center gap-1"
@@ -65,11 +86,13 @@ export const UserInfo = () => {
6586
buymeacoffee.com/mscode07
6687
</a>
6788
<p className="flex items-center text-gray-500 gap-1">
68-
<PiBalloon className="text-xl font-bold" /> {}
89+
<PiBalloon className="text-xl font-bold" />
90+
{userData?.[0]?.DOB || "DOB"}
6991
</p>
7092
</div>
7193
<p className="flex items-center text-gray-500 gap-2">
72-
<IoCalendarOutline className="text-lg" /> Joined December 2017
94+
<IoCalendarOutline className="text-lg" />{" "}
95+
{userData?.[0]?.createdDate}
7396
</p>
7497
<div className="flex gap-2 mt-2">
7598
<div className="flex">
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use client";
2+
export const TopHead = () => {
3+
return (
4+
<div>
5+
<div>
6+
<div className="mt-3 flex items-center gap-5 cursor-pointer">
7+
<div className=" rounded-full p-2 hover:bg-neutral-800 transition duration-300 m-2"></div>
8+
<div>
9+
<p className="font-bold text-xl"></p>
10+
<p className="text-gray-500"></p>
11+
</div>
12+
</div>
13+
</div>
14+
</div>
15+
);
16+
};

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const TweetComp = ({ tweet }: TweetProps) => {
6060
})}
6161
</p>
6262
</div>
63-
{/* <p className="text-end">...</p> */}
6463
<div className="flex justify-end cursor-pointer hover:bg-black hover:rounded-2xl pr-3">
6564
<Popover>
6665
<PopoverTrigger className="font-bold text-slate-500">

apps/X/src/components/ui/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { UserAvatar } from "./usrAvatar";
1313
import { Button } from "./button";
1414
import { HomeComp } from "./home/HomeComp";
1515
import { HomeLeft } from "./home/HomeLeft";
16-
import { TopHead } from "./Post/topHead";
17-
import { TopPost } from "./Post/TopNavbar";
16+
import { TopHead } from "./TopNavHome";
17+
import { TopPost } from "./Post/TopPostHome";
1818
import { LoaderComp } from "../LoaderComp";
1919
import { TopHeader } from "../TopHeader";
2020
import { userInfo } from "os";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "User" ADD COLUMN "bioLink" TEXT;

0 commit comments

Comments
 (0)