Skip to content

Commit 01507f1

Browse files
authored
Merge pull request #25 from mscode07/dev
done with display tweet
2 parents ca19a9c + 8ce475b commit 01507f1

File tree

9 files changed

+152
-118
lines changed

9 files changed

+152
-118
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,35 @@ const prisma = new PrismaClient();
88

99
export async function GET() {
1010
const session = await getServerSession(authOptions);
11-
1211
if (!session) {
1312
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
1413
}
1514

15+
try {
16+
const posts = await prisma.tweet.findMany({
17+
include: {
18+
user: {
19+
select: {
20+
name: true,
21+
},
22+
},
23+
},
24+
});
25+
return NextResponse.json({ data: posts }, { status: 200 });
26+
} catch (error) {
27+
console.log("Error while fetching from DB", error);
28+
}
29+
1630
return NextResponse.json({ userId: session.user.id });
1731
}
1832

1933
export const POST = async (req: NextRequest) => {
2034
try {
2135
const session = await getServerSession(authOptions);
22-
console.log("Reaching in Post");
23-
console.log(session, "This is the user");
24-
console.log(session?.user.id, "This is the userID");
25-
console.log(session?.user, "This is the userID");
36+
// console.log("Reaching in Post");
37+
// console.log(session, "This is the user");
38+
// console.log(session?.user.id, "This is the userID");
39+
// console.log(session?.user, "This is the userID");
2640

2741
if (!session?.user?.id) {
2842
return NextResponse.json(

apps/X/app/lib/auth.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import GithubProvider from "next-auth/providers/github";
55
import GoogleProvider from "next-auth/providers/google";
66
import { Session } from "next-auth";
77
import z from "zod";
8-
8+
import type { Account, Profile, User } from "next-auth";
99
declare module "next-auth" {
1010
interface Session {
1111
user: {
@@ -115,7 +115,6 @@ export const authOptions = {
115115
} else {
116116
console.log("Invalid password for existing user");
117117
}
118-
console.log("This is name", existingUser.name);
119118
} catch (error) {
120119
console.log("Error while LogIn", error);
121120
}
@@ -151,9 +150,8 @@ export const authOptions = {
151150

152151
callbacks: {
153152
async jwt({ token, user, account }: any) {
154-
console.log("JWT Callback - User:", user);
155-
console.log("JWT Callback - Account:", account);
156-
console.log("OOOOOOOOOOO", token.id);
153+
//console.log("JWT Callback - User:", user);
154+
//console.log("JWT Callback - Account:", account);
157155

158156
if (user) {
159157
token.id = user.id;
@@ -163,16 +161,16 @@ export const authOptions = {
163161
return token;
164162
},
165163
async session({ session, token }: any) {
166-
console.log("Session Callback - Token:", token);
167-
console.log("Session Callback - Initial Session:", session);
164+
// console.log("Session Callback - Token:", token);
165+
// console.log("Session Callback - Initial Session:", session);
168166

169167
if (token && session.user) {
170168
session.user.id = token.id as string;
171169
session.user.username = token.username || null;
172170
session.user.email = token.email || null;
173171
}
174172

175-
console.log("Session Callback - Updated Session:", session);
173+
//console.log("Session Callback - Updated Session:", session);
176174
return session;
177175
},
178176

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import { Button } from "../button";
1414
import { Input } from "../input";
1515
import { UserAvatar } from "../usrAvatar";
1616
import X_Icon from "../X_Icon";
17-
interface TweetInput {
18-
content: string;
19-
userId: number;
20-
}
17+
// interface TweetInput {
18+
// content: string;
19+
// userId: number;
20+
// }
2121

2222
export const TopPost = () => {
2323
const [postInput, setPostInput] = useState("");

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

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,55 @@
1-
import { FaRegComment } from "react-icons/fa6";
1+
"use client";
22
import { BiRepost } from "react-icons/bi";
3-
import { UserAvatar } from "./usrAvatar";
3+
import { FaRegBookmark, FaRegComment } from "react-icons/fa6";
44
import { FiHeart } from "react-icons/fi";
55
import { IoIosStats } from "react-icons/io";
6-
import { FaRegBookmark } from "react-icons/fa6";
76
import { RiShare2Line } from "react-icons/ri";
8-
<RiShare2Line />;
9-
export const TweetComp = () => {
10-
return (
11-
<div className="border border-slate-800 border-spacing-x-0.5">
12-
<div className="flex p-3 gap-2">
13-
<div className="mt-1">
14-
<UserAvatar />
15-
</div>
16-
<div className="">
17-
<div className="grid grid-cols-6">
18-
<div className="flex col-span-5">
19-
<p>username</p>
20-
<p> @name</p>
21-
<p> . time</p>
22-
</div>
23-
<p className="text-end">...</p>
24-
</div>
25-
<div className="flex flex-col">
26-
<div className="list-inside">
27-
#day100 so finally I completed 100 day of code. Amazing journey
28-
amazing learning and amazing people I have got in this journey and
29-
here are some glimpse from the journey. Thank you everyone and
30-
specially @kirat_tw #100xdevs #buildinpublic #space
31-
#LearningJourney #WeekendPlans
32-
</div>
33-
<div className="">Image Part</div>
34-
</div>
35-
{/* <div className="grid grid-cols-5 space-x-8">
36-
<div className="flex col-span-1">
37-
<FaRegComment />
38-
</div>
39-
<div className="flex col-span-1">
40-
<BiRepost />
41-
</div>
42-
<div className="flex col-span-1">
43-
<FiHeart />
44-
</div>
45-
<div className="flex col-span-1">
46-
<IoIosStats />
47-
</div>
48-
<div className="flex">
49-
<FaRegBookmark />
50-
<RiShare2Line />
51-
</div>
52-
</div> */}
7+
import { UserAvatar } from "./usrAvatar";
538

54-
<div className="flex space-x-24">
55-
<FaRegComment />
56-
<BiRepost />
57-
<FiHeart />
58-
<IoIosStats />
59-
{/* <div className="">
60-
</div>
61-
<div className="">
62-
</div>
63-
<div className="">
9+
interface TweetProps {
10+
tweet: {
11+
id: number;
12+
content: string;
13+
userID: number;
14+
likes: number;
15+
createdDate: string;
16+
user: { name: string };
17+
};
18+
}
19+
20+
export const TweetComp = ({ tweet }: TweetProps) => {
21+
return (
22+
<div>
23+
<div>
24+
<div className="border border-slate-800 border-spacing-x-0.5">
25+
<div className="flex p-3 gap-2">
26+
<div className="mt-1">
27+
<UserAvatar />
6428
</div>
6529
<div className="">
66-
</div> */}
67-
<div className="flex">
68-
<FaRegBookmark />
69-
<RiShare2Line />
30+
<div className="grid grid-cols-6">
31+
<div className="flex col-span-5">
32+
<p>{tweet.user.name}</p>
33+
{/* <p> @tweet.content</p> */}
34+
<p> · {new Date(tweet.createdDate).toLocaleDateString()}</p>
35+
</div>
36+
<p className="text-end">...</p>
37+
</div>
38+
<div className="flex flex-col">
39+
<div className="list-inside">{tweet.content}</div>
40+
<div className="">Image Part</div>
41+
</div>
42+
<div className="flex space-x-24 text-slate-600">
43+
<FaRegComment />
44+
<BiRepost />
45+
<FiHeart />
46+
{/* <span>{tweet.likes} </span> */}
47+
<IoIosStats />
48+
<div className="flex">
49+
<FaRegBookmark />
50+
<RiShare2Line />
51+
</div>
52+
</div>
7053
</div>
7154
</div>
7255
</div>

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

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
1+
"use client";
2+
import axios from "axios";
3+
import { useEffect, useState } from "react";
14
import { TopHead, TopPost, TweetComp } from "..";
25

6+
interface Tweet {
7+
id: number;
8+
content: string;
9+
userID: number;
10+
likes: number;
11+
createdDate: string;
12+
user: { name: string };
13+
}
314
export const CenterComp = () => {
15+
const [tweets, setTweets] = useState<Tweet[]>([]);
16+
const [loading, setLoading] = useState(false);
17+
const [error, setError] = useState("");
18+
const fetchTweets = async () => {
19+
try {
20+
setLoading(true);
21+
const response = await axios.get("api/post");
22+
const tweetData = response.data.data;
23+
console.log(">>>>>>>>>>>>>>>>>>>>>>>>", tweetData);
24+
25+
if (Array.isArray(tweetData) && response.data.data.length > 0) {
26+
setTweets(tweetData);
27+
} else {
28+
setError("No tweets found");
29+
}
30+
} catch (error) {
31+
console.log("Getting error while fetching =>", error);
32+
} finally {
33+
setLoading(false);
34+
}
35+
const response = await axios.get("api/post");
36+
console.log("This is from the Centercomp", response);
37+
};
38+
useEffect(() => {
39+
fetchTweets();
40+
}, []);
441
return (
542
<div className="">
643
<div className="">
@@ -9,13 +46,19 @@ export const CenterComp = () => {
946
<div>
1047
<TopPost />
1148
</div>
12-
<div className="">
13-
<TweetComp />
14-
<TweetComp />
15-
<TweetComp />
16-
<TweetComp />
17-
<TweetComp />
18-
</div>
49+
{loading ? (
50+
<div>Loading</div>
51+
) : error ? (
52+
<div>{error}</div>
53+
) : (
54+
<div>
55+
<div className="">
56+
{tweets.map((tweet) => (
57+
<TweetComp key={tweet.id} tweet={tweet} />
58+
))}
59+
</div>
60+
</div>
61+
)}
1962
</div>
2063
);
2164
};

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@ import { CenterComp, HomeLeft, HomeRight } from "@/components/ui";
22

33
export const HomeComp = () => {
44
return (
5-
<div className="relative">
6-
<div className="flex h-full">
7-
<div className="custom:w-96 w-10 custom:ml-24 ml-10"></div>
8-
<div className="flex">
9-
<div className="custom:px-10 px-2 mr-10 custom:m-0 custom:left-10 left-0">
10-
<HomeLeft />
11-
</div>
12-
<div className="border border-y-0 custom:w-5/12 w-8/12 h-full overflow-y-hidden">
13-
<CenterComp />
14-
</div>
15-
<div className="">
16-
<HomeRight />
17-
</div>
5+
<div className="flex h-screen overflow-y-auto">
6+
<div className="custom:w-96 w-10 custom:ml-24 ml-24 h-screen sticky top-0 flex-shrink-0 mr-7 custom:mr-10">
7+
<HomeLeft />
8+
</div>
9+
<div className="flex flex-grow">
10+
<div className="border border-y-0 custom:w-5/12 w-">
11+
<CenterComp />
12+
</div>
13+
<div className="h-screen sticky top-0 flex-shrink-0">
14+
<HomeRight />
1815
</div>
1916
</div>
20-
{/* border-slate-800 border border-y-0 h-screen */}
2117
</div>
2218
);
2319
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const HomeLeft = () => {
130130
Post
131131
</Button>
132132
<TbOctagonPlus
133-
className="custom:hidden block text-4xl ml-3 cursor-pointer hover:bg-white hover:rounded-3xl hover:text-black "
133+
className="custom:hidden block text-4xl ml-3 cursor-pointer hover:bg-white hover:rounded-3xl hover:text-black"
134134
onClick={onPostClick}
135135
/>
136136
</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"@types/bcrypt": "^5.0.2",
2525
"bcrypt": "^5.1.1"
2626
}
27-
}
27+
}

0 commit comments

Comments
 (0)