diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c5674da --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/apps/X/app/(pages)/post/page.tsx b/apps/X/app/(pages)/post/page.tsx new file mode 100644 index 0000000..5869bbb --- /dev/null +++ b/apps/X/app/(pages)/post/page.tsx @@ -0,0 +1,5 @@ +"use client" +function page() { + return
This is the Post page
+} +export default page \ No newline at end of file diff --git a/apps/X/app/api/post/route.ts b/apps/X/app/api/post/route.ts index a956e69..92dcb66 100644 --- a/apps/X/app/api/post/route.ts +++ b/apps/X/app/api/post/route.ts @@ -75,8 +75,9 @@ export const POST = async (req: NextRequest) => { }; 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" }, @@ -91,17 +92,27 @@ export async function DELETE(req: NextRequest) { { status: 400 } ); } + const tweet = await prisma.tweet.findUnique({ + where: { id: Number(id) }, + }); + if (!tweet) { + return NextResponse.json( + { message: "Tweet not found" }, + { status: 404 } + ); + } + if (tweet.userID !== Number(userDel)) { + return NextResponse.json({message:"Unauthorized"}) + } const tweetId = Number(id); const deleteTweet = await prisma.tweet.update({ - where: { id: tweetId, userID: userDel }, + where: { id: tweetId}, data: { IsDelete: true, }, }); - if (!deleteTweet) { - return NextResponse.json({ message: "Tweet not found" }, { status: 404 }); - } - + 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); diff --git a/apps/X/src/components/ui/TweetComp.tsx b/apps/X/src/components/ui/TweetComp.tsx index 87a6cf7..0309f4c 100644 --- a/apps/X/src/components/ui/TweetComp.tsx +++ b/apps/X/src/components/ui/TweetComp.tsx @@ -6,7 +6,6 @@ import { PopoverTrigger, } from "@/components/ui/popover"; import axios from "axios"; -import { NextResponse } from "next/server"; import { BiRepost } from "react-icons/bi"; import { FaRegBookmark, FaRegComment } from "react-icons/fa6"; import { FiHeart } from "react-icons/fi"; @@ -29,7 +28,7 @@ export const TweetComp = ({ tweet }: TweetProps) => { try { const response = await axios.delete(`/api/post?id=${tweet.id}`); console.log("Tweet Deleted", response); - return NextResponse.json({ status: 200 }); + return response.data; } catch (error) { console.log("Error while Deleting Tweet", error); } diff --git a/apps/X/src/components/ui/home/HomeComp.tsx b/apps/X/src/components/ui/home/HomeComp.tsx index 3cbaee6..ea8d4f9 100644 --- a/apps/X/src/components/ui/home/HomeComp.tsx +++ b/apps/X/src/components/ui/home/HomeComp.tsx @@ -3,7 +3,7 @@ import { CenterComp, HomeLeft, HomeRight } from "@/components/ui"; export const HomeComp = () => { return (
-
+
diff --git a/apps/X/src/components/ui/home/HomeLeft.tsx b/apps/X/src/components/ui/home/HomeLeft.tsx index 4ccee80..cdccd9b 100644 --- a/apps/X/src/components/ui/home/HomeLeft.tsx +++ b/apps/X/src/components/ui/home/HomeLeft.tsx @@ -1,25 +1,29 @@ "use client"; +import { getSession } from "next-auth/react"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; import { AiOutlineThunderbolt } from "react-icons/ai"; import { CgMoreO } from "react-icons/cg"; import { FaRegBookmark } from "react-icons/fa"; import { FaRegUser } from "react-icons/fa6"; import { GoHome } from "react-icons/go"; import { IoMdSearch } from "react-icons/io"; -import { TbOctagonPlus } from "react-icons/tb"; import { MdOutlineMail } from "react-icons/md"; import { RiGroupLine, RiNotification2Line } from "react-icons/ri"; +import { TbOctagonPlus } from "react-icons/tb"; import { Button, UserAvatar, X_logo } from ".."; import GrokIcon from "../Grok"; import X_Icon from "../X_Icon"; -import Link from "next/link"; -import { useState } from "react"; + export const HomeLeft = () => { - const [isOpen, setIsOpen] = useState(false); + const router = useRouter(); + const session = getSession(); const onPostClick = () => { console.log("Click"); - setIsOpen(!isOpen); + router.push("/post"); + console.log(session, "This is the session"); }; return (
@@ -138,8 +142,12 @@ export const HomeLeft = () => {
-
+
+
+

mscode

+

@mscode07

+