Skip to content
Merged

Dev #32

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ yarn-error.log*
# Misc
.DS_Store
*.pem
.qodo
22 changes: 22 additions & 0 deletions apps/X/app/(pages)/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use client";

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

const page = () => {
return (
<div className="flex h-screen overflow-y-auto">
<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">
<HomeLeft />
</div>
<div className="flex flex-grow">
<div className="border border-y-0 custom:w-6/12 w-10/12">
<div>
<UserInfo />
</div>
</div>
</div>
</div>
);
};
export default page;
22 changes: 9 additions & 13 deletions apps/X/app/api/post/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NextRequest, NextResponse } from "next/server";

const prisma = new PrismaClient();

//? GET Tweet
export async function GET() {
const session = await getServerSession(authOptions);
if (!session) {
Expand All @@ -31,13 +32,10 @@ export async function GET() {
return NextResponse.json({ userId: session.user.id });
}

//? POST Tweet
export const POST = async (req: NextRequest) => {
try {
const session = await getServerSession(authOptions);
// console.log("Reaching in Post");
// console.log(session, "This is the user");
// console.log(session?.user.id, "This is the userID");
// console.log(session?.user, "This is the userID");

if (!session?.user?.id) {
return NextResponse.json(
Expand Down Expand Up @@ -74,10 +72,11 @@ export const POST = async (req: NextRequest) => {
}
};

//? DELETE Tweet
export async function DELETE(req: NextRequest) {
try {
try {
const session = await getServerSession(authOptions);

if (!session?.user?.id) {
return NextResponse.json(
{ error: "Unauthorized - User not authenticated" },
Expand All @@ -96,23 +95,20 @@ export async function DELETE(req: NextRequest) {
where: { id: Number(id) },
});
if (!tweet) {
return NextResponse.json(
{ message: "Tweet not found" },
{ status: 404 }
);
return NextResponse.json({ message: "Tweet not found" }, { status: 404 });
}
if (tweet.userID !== Number(userDel)) {
return NextResponse.json({message:"Unauthorized"})
return NextResponse.json({ message: "Unauthorized" });
}
const tweetId = Number(id);
const deleteTweet = await prisma.tweet.update({
where: { id: tweetId},
where: { id: tweetId },
data: {
IsDelete: true,
},
});
console.log("This is the response", deleteTweet);

return NextResponse.json({ message: "Done with delete" }, { status: 200 });
} catch (error) {
console.log("Getting error in Delete", error);
Expand Down
39 changes: 39 additions & 0 deletions apps/X/app/api/user/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { PrismaClient } from "@prisma/client";
import { authOptions } from "app/lib/auth";
import { getServerSession } from "next-auth";
import { NextResponse } from "next/server";

const prisma = new PrismaClient();

export const GET = async () => {
console.log("Hitting the user get rout");

const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

const userID = session.user.id;

try {
console.log("Hitting the user get rout 22");
const user = await prisma.user.findMany({
include: {
tweets: {
where: {
IsDelete: false,
},
},
},
where: { id: Number(userID) },
});
console.log("This is the response", user);
return NextResponse.json({ data: user }, { status: 200 });
} catch (error) {
console.log("Error while fetching from DB", error);
return NextResponse.json({
status: 400,
message: "Error while fetching from DB",
});
}
};
23 changes: 23 additions & 0 deletions apps/X/src/components/LoaderComp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const LoaderComp = () => {
return (
<div role="status">
<svg
aria-hidden="true"
className="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
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"
fill="currentColor"
/>
<path
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"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
);
};
15 changes: 2 additions & 13 deletions apps/X/src/components/RouteGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useSession } from "next-auth/react";
import { usePathname, useRouter } from "next/navigation";
import { useEffect } from "react";
import { X_loaderComp } from "./X_loaderComp";

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

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

if (status == "loading") {
return (
<div className="flex justify-center items-center h-screen ">
<svg
viewBox="0 0 24 24"
aria-hidden="true"
className=" w-24 h-24 fill-current text-black dark:text-white"
>
<g>
<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>
</g>
</svg>
</div>
);
return <X_loaderComp />;
}

return <>{children}</>;
Expand Down
3 changes: 3 additions & 0 deletions apps/X/src/components/TopHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const TopHeader = () => {
return <div>TopHeader</div>;
};
15 changes: 15 additions & 0 deletions apps/X/src/components/X_loaderComp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const X_loaderComp = () => {
return (
<div className="flex justify-center items-center h-screen ">
<svg
viewBox="0 0 24 24"
aria-hidden="true"
className=" w-24 h-24 fill-current text-black dark:text-white"
>
<g>
<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>
</g>
</svg>
</div>
);
};
89 changes: 89 additions & 0 deletions apps/X/src/components/ui/Profile/UserInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"use client";
import { TopHeader } from "@/components/TopHeader";
import axios from "axios";
import { useSession } from "next-auth/react";
import { useEffect } 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";

export const UserInfo = () => {
const { data: session } = useSession();
useEffect(() => {
const fetchUserData = async () => {
try {
const response = await axios.get("api/user");
console.log("User data", response.data);
} catch (error) {
console.log("Getting user data failed", error);
}
};
fetchUserData();
}, []);

return (
<div>
<div>
<div>
<TopHeader />
</div>
<div>
<div
className="relative w-full h-64 bg-cover bg-center object-cover"
style={{
backgroundImage: `url('https://github.com/mscode07.png')`,
}}
>
<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"
/>
</div>
</div>
<div className="mt-24 ml-3">
<p className="text-2xl font-bold">{session?.user?.name}</p>
<p className="text-gray-500">@{session?.user?.username}</p>
</div>
</div>
<div className="ml-3 mt-2 w-full">
<p className="mb-3"></p>
<div>
<div className="flex gap-2">
<p className="flex items-center text-gray-500 gap-1">
<GrLocation className="text-xl" />
location
</p>
<a
className="text-blue-500 flex items-center gap-1"
href="https://buymeacoffee.com/mscode07"
>
<AiOutlineLink className="text-gray-500 text-xl" />{" "}
buymeacoffee.com/mscode07
</a>
<p className="flex items-center text-gray-500 gap-1">
<PiBalloon className="text-xl font-bold" /> {}
</p>
</div>
<p className="flex items-center text-gray-500 gap-2">
<IoCalendarOutline className="text-lg" /> Joined December 2017
</p>
<div className="flex gap-2 mt-2">
<div className="flex">
<p className="font-bold">2,147</p>
<span className="text-gray-500 ml-1 ">Following</span>
</div>
<div className="flex">
<p className="font-bold">3,605</p>
<span className="text-gray-500 ml-1">Followers</span>
</div>
</div>
</div>
</div>
</div>
</div>
);
};
10 changes: 5 additions & 5 deletions apps/X/src/components/ui/TweetComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ export const TweetComp = ({ tweet }: TweetProps) => {
<div>
<div>
<div className="border border-slate-800 border-spacing-x-0.5">
<div className="flex p-3 gap-2">
<div className="flex p-3 gap-2 w-full">
<div className="mt-1 cursor-pointer">
<Avatar>
<AvatarImage />
<AvatarFallback>{tweet.user.name[0]}</AvatarFallback>
</Avatar>
</div>
<div className="">
<div className="w-full">
<div className="grid grid-cols-6">
<div className="flex col-span-5">
<p className="font-bold cursor-pointer">{tweet.user.name}</p>
{/* <p> @tweet.content</p> */}
<p className="text-slate-500 pl-2">@{tweet.user.name}</p>
<span className="px-1 mx-1 items-center text-slate-500">
.
</span>
Expand All @@ -61,7 +61,7 @@ export const TweetComp = ({ tweet }: TweetProps) => {
</p>
</div>
{/* <p className="text-end">...</p> */}
<div className="ml-auto cursor-pointer hover:bg-black hover:rounded-2xl">
<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 Expand Up @@ -92,7 +92,7 @@ export const TweetComp = ({ tweet }: TweetProps) => {
<FiHeart className="cursor-pointer" />
{/* <span>{tweet.likes} </span> */}
<IoIosStats className="cursor-pointer" />
<div className="flex">
<div className="flex gap-3">
<FaRegBookmark className="cursor-pointer" />
<RiShare2Line className="cursor-pointer" />
</div>
Expand Down
8 changes: 4 additions & 4 deletions apps/X/src/components/ui/home/CenterComp.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import axios from "axios";
import { useEffect, useState } from "react";
import { TopHead, TopPost, TweetComp } from "..";
import { LoaderComp, TopHead, TopPost, TweetComp, X_logo } from "..";

interface Tweet {
id: number;
Expand All @@ -20,8 +20,6 @@ export const CenterComp = () => {
setLoading(true);
const response = await axios.get("api/post");
const tweetData = response.data.data;
// console.log(">>>>>>>>>>>>>>>>>>>>>>>>", tweetData);

if (Array.isArray(tweetData) && response.data.data.length > 0) {
setTweets(tweetData);
} else {
Expand Down Expand Up @@ -53,7 +51,9 @@ export const CenterComp = () => {
<TopPost />
</div>
{loading ? (
<div>Loading</div>
<div className="flex items-center justify-center h-screen">
<LoaderComp />
</div>
) : error ? (
<div>{error}</div>
) : (
Expand Down
4 changes: 2 additions & 2 deletions apps/X/src/components/ui/home/HomeComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { CenterComp, HomeLeft, HomeRight } from "@/components/ui";
export const HomeComp = () => {
return (
<div className="flex h-screen overflow-y-auto">
<div className="custom:w-96 w-10 custom:ml-24 ml-2 h-screen sticky top-0 flex-shrink-0 mr-7 custom:mr-10">
<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">
<HomeLeft />
</div>
<div className="flex flex-grow">
<div className="border border-y-0 custom:w-5/12 w-">
<div className="border border-y-0 custom:w-6/12 w-10/12">
<CenterComp />
</div>
{/* <div className="invisible h-screen sticky top-0">
Expand Down
Loading