Skip to content

Commit 676c043

Browse files
authored
Merge pull request #32 from mscode07/dev
Dev
2 parents e8199d6 + bfe66f5 commit 676c043

File tree

17 files changed

+247
-51
lines changed

17 files changed

+247
-51
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
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use client";
2+
3+
import { CenterComp, HomeLeft } from "@/components/ui";
4+
import { UserInfo } from "@/components/ui/Profile/UserInfo";
5+
6+
const page = () => {
7+
return (
8+
<div className="flex h-screen overflow-y-auto">
9+
<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">
10+
<HomeLeft />
11+
</div>
12+
<div className="flex flex-grow">
13+
<div className="border border-y-0 custom:w-6/12 w-10/12">
14+
<div>
15+
<UserInfo />
16+
</div>
17+
</div>
18+
</div>
19+
</div>
20+
);
21+
};
22+
export default page;

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const LoaderComp = () => {
2+
return (
3+
<div role="status">
4+
<svg
5+
aria-hidden="true"
6+
className="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
7+
viewBox="0 0 100 101"
8+
fill="none"
9+
xmlns="http://www.w3.org/2000/svg"
10+
>
11+
<path
12+
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
13+
fill="currentColor"
14+
/>
15+
<path
16+
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
17+
fill="currentFill"
18+
/>
19+
</svg>
20+
<span className="sr-only">Loading...</span>
21+
</div>
22+
);
23+
};

apps/X/src/components/RouteGuard.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { useSession } from "next-auth/react";
33
import { usePathname, useRouter } from "next/navigation";
44
import { useEffect } from "react";
5+
import { X_loaderComp } from "./X_loaderComp";
56

67
const publicPaths = ["/signin", "/login", "/error"];
78

@@ -33,19 +34,7 @@ export function RouteGard({ children }: { children: React.ReactNode }) {
3334
}, [session, status, router, pathname]);
3435

3536
if (status == "loading") {
36-
return (
37-
<div className="flex justify-center items-center h-screen ">
38-
<svg
39-
viewBox="0 0 24 24"
40-
aria-hidden="true"
41-
className=" w-24 h-24 fill-current text-black dark:text-white"
42-
>
43-
<g>
44-
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"></path>
45-
</g>
46-
</svg>
47-
</div>
48-
);
37+
return <X_loaderComp />;
4938
}
5039

5140
return <>{children}</>;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const TopHeader = () => {
2+
return <div>TopHeader</div>;
3+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const X_loaderComp = () => {
2+
return (
3+
<div className="flex justify-center items-center h-screen ">
4+
<svg
5+
viewBox="0 0 24 24"
6+
aria-hidden="true"
7+
className=" w-24 h-24 fill-current text-black dark:text-white"
8+
>
9+
<g>
10+
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"></path>
11+
</g>
12+
</svg>
13+
</div>
14+
);
15+
};
File renamed without changes.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use client";
2+
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";
10+
11+
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+
25+
return (
26+
<div>
27+
<div>
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>
86+
</div>
87+
</div>
88+
);
89+
};

0 commit comments

Comments
 (0)