Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/X/app/(pages)/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { CenterComp, HomeLeft } from "@/components/ui";
import { HomeLeft } from "@/components/ui";
import { UserInfo } from "@/components/ui/Profile/UserInfo";

const page = () => {
Expand Down
21 changes: 15 additions & 6 deletions apps/X/app/api/post/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PrismaClient } from "@prisma/client";
import { authOptions } from "app/lib/auth";
import { error } from "console";
import { getServerSession } from "next-auth";
//? https://github.com/code100x/cms/blob/main/src/app/api/admin/content/route.ts
import { NextRequest, NextResponse } from "next/server";
Expand Down Expand Up @@ -42,33 +43,41 @@ export const POST = async (req: NextRequest) => {
{ error: "Unauthorized - User not authenticated" },
{ status: 401 }
);
} else {
console.log("reaching");
}
const sessionUserId = parseInt(session.user.id);
const user = await prisma.user.findFirst({ where: { id: sessionUserId } });

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

console.log("Checking body content...");
if (!body || !body.content) {
return NextResponse.json(
{ error: "content is requried" },
{ error: "content is required" },
{ status: 400 }
);
}
console.log("Parsing the content...");
const userId = parseInt(session.user.id);
if (isNaN(userId)) {
return NextResponse.json({ error: "Invalid user ID" }, { status: 400 });
}
const { content } = body;
console.log("Creating tweet with userId:", userId, "and content:", content);
const tweet = await prisma.tweet.create({
data: { content, userID: userId },
});
// router.push("")
console.log("This is the response", tweet);

return NextResponse.json(tweet, { status: 201 });
return NextResponse.json(tweet, { status: 200 });
} catch (error) {
console.log("Getting error in Creating", error);
return NextResponse.json(
{ error: "Internal Server Error" },
{ status: 500 }
);
}
};

Expand Down
27 changes: 26 additions & 1 deletion apps/X/src/components/TopHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
"use client";
import { IoArrowBack } from "react-icons/io5";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";

export const TopHeader = () => {
return <div>TopHeader</div>;
const { data: session } = useSession();

const router = useRouter();

const handleBackClick = () => {
router.back();
};

return (
<div>
<div className="mt-3 flex items-center gap-5 cursor-pointer">
<div className=" rounded-full p-2 hover:bg-neutral-800 transition duration-300 m-2">
<IoArrowBack className="text-xl" onClick={handleBackClick} />
</div>
<div>
<p className="font-bold text-xl">{session?.user?.name}</p>
<p className="text-gray-500">28.3K posts</p>
</div>
</div>
</div>
);
};
3 changes: 0 additions & 3 deletions apps/X/src/components/ui/Post/topHead.tsx

This file was deleted.

45 changes: 34 additions & 11 deletions apps/X/src/components/ui/Profile/UserInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
"use client";
import { TopHeader } from "@/components/TopHeader";
import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar";
import axios from "axios";
import { useSession } from "next-auth/react";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { AiOutlineLink } from "react-icons/ai";
import { GrLocation } from "react-icons/gr";
import { IoCalendarOutline } from "react-icons/io5";
import { PiBalloon } from "react-icons/pi";

interface UserDataProps {
DOB: string;
location: string;
createdDate: string;
bio: string;
}
export const UserInfo = () => {
const { data: session } = useSession();
const [userData, setUserData] = useState<UserDataProps[] | null>(null);
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);

useEffect(() => {
const fetchUserData = async () => {
try {
setLoading(true);
const response = await axios.get("api/user");
console.log("User data", response.data);
const u_Data = response.data.data;
if (Array.isArray(u_Data) && response.data.data.length > 0) {
setUserData(u_Data);
console.log(u_Data, "Here it is");
} else {
setError("No user data found");
}
} catch (error) {
console.log("Getting user data failed", error);
} finally {
setLoading(false);
}
};
fetchUserData();
Expand All @@ -36,12 +56,13 @@ export const UserInfo = () => {
}}
>
<div>
<img
className="absolute rounded-full w-40 h-40 border-4 border-black bottom-0 top-48 left-3
"
src="https://github.com/mscode07.png"
alt="Extra large avatar"
/>
<Avatar>
<AvatarImage
src={session?.user?.image || ""}
alt={session?.user?.name || "User"}
/>
<AvatarFallback>{session?.user?.name?.[0]}</AvatarFallback>
</Avatar>
</div>
</div>
<div className="mt-24 ml-3">
Expand All @@ -55,7 +76,7 @@ export const UserInfo = () => {
<div className="flex gap-2">
<p className="flex items-center text-gray-500 gap-1">
<GrLocation className="text-xl" />
location
{userData?.[0]?.location || "Location"}
</p>
<a
className="text-blue-500 flex items-center gap-1"
Expand All @@ -65,11 +86,13 @@ export const UserInfo = () => {
buymeacoffee.com/mscode07
</a>
<p className="flex items-center text-gray-500 gap-1">
<PiBalloon className="text-xl font-bold" /> {}
<PiBalloon className="text-xl font-bold" />
{userData?.[0]?.DOB || "DOB"}
</p>
</div>
<p className="flex items-center text-gray-500 gap-2">
<IoCalendarOutline className="text-lg" /> Joined December 2017
<IoCalendarOutline className="text-lg" />{" "}
{userData?.[0]?.createdDate}
</p>
<div className="flex gap-2 mt-2">
<div className="flex">
Expand Down
16 changes: 16 additions & 0 deletions apps/X/src/components/ui/TopNavHome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client";
export const TopHead = () => {
return (
<div>
<div>
<div className="mt-3 flex items-center gap-5 cursor-pointer">
<div className=" rounded-full p-2 hover:bg-neutral-800 transition duration-300 m-2"></div>
<div>
<p className="font-bold text-xl"></p>
<p className="text-gray-500"></p>
</div>
</div>
</div>
</div>
);
};
1 change: 0 additions & 1 deletion apps/X/src/components/ui/TweetComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const TweetComp = ({ tweet }: TweetProps) => {
})}
</p>
</div>
{/* <p className="text-end">...</p> */}
<div className="flex justify-end cursor-pointer hover:bg-black hover:rounded-2xl pr-3">
<Popover>
<PopoverTrigger className="font-bold text-slate-500">
Expand Down
4 changes: 2 additions & 2 deletions apps/X/src/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { UserAvatar } from "./usrAvatar";
import { Button } from "./button";
import { HomeComp } from "./home/HomeComp";
import { HomeLeft } from "./home/HomeLeft";
import { TopHead } from "./Post/topHead";
import { TopPost } from "./Post/TopNavbar";
import { TopHead } from "./TopNavHome";
import { TopPost } from "./Post/TopPostHome";
import { LoaderComp } from "../LoaderComp";
import { TopHeader } from "../TopHeader";
import { userInfo } from "os";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "bioLink" TEXT;
1 change: 1 addition & 0 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ model User {
createdDate DateTime @default(now())
DOB DateTime?
location String?
bioLink String?
}

model Tweet {
Expand Down