Skip to content

Commit 83e09a9

Browse files
authored
Merge pull request #26 from mscode07/dev
delete is working
2 parents 01507f1 + 27f0432 commit 83e09a9

File tree

9 files changed

+311
-34
lines changed

9 files changed

+311
-34
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { authOptions } from "app/lib/auth";
33
import { getServerSession } from "next-auth";
44
//? https://github.com/code100x/cms/blob/main/src/app/api/admin/content/route.ts
55
import { NextRequest, NextResponse } from "next/server";
6+
import { AiOutlineConsoleSql } from "react-icons/ai";
67

78
const prisma = new PrismaClient();
89

@@ -21,6 +22,7 @@ export async function GET() {
2122
},
2223
},
2324
},
25+
where: { IsDelete: false },
2426
});
2527
return NextResponse.json({ data: posts }, { status: 200 });
2628
} catch (error) {
@@ -70,3 +72,59 @@ export const POST = async (req: NextRequest) => {
7072
console.log("Getting error in Creating", error);
7173
}
7274
};
75+
interface RouteContext {
76+
params: {
77+
id: string;
78+
};
79+
}
80+
// export const DELETE = async (
81+
// req: NextRequest,
82+
// params: { param: { id: string } }
83+
// ) => {
84+
// console.log(params.param.id);
85+
86+
// try {
87+
// console.log("Hitting the Delete");
88+
// const tweetId = Number(params.param.id);
89+
// const deleteTweet = await prisma.tweet.delete({
90+
// where: {
91+
// id: tweetId,
92+
// },
93+
// });
94+
// console.log("Deleting the Tweet", deleteTweet);
95+
// return NextResponse.json({ mess: "Done with Delete", status: 200 });
96+
// } catch (error) {
97+
// console.log("Getting this error while deleting", error);
98+
// return NextResponse.json(
99+
// { error: "Failed to delete tweet" },
100+
// { status: 500 }
101+
// );
102+
// }
103+
// };
104+
105+
export async function DELETE(req: NextRequest) {
106+
try {
107+
console.log("Hitting the delete");
108+
const id = req.nextUrl.searchParams.get("id");
109+
if (!id) {
110+
return NextResponse.json(
111+
{ message: "Todi ID is required" },
112+
{ status: 400 }
113+
);
114+
}
115+
const deleteTweet = await prisma.tweet.delete({
116+
where: { id: Number(id) },
117+
});
118+
if (!deleteTweet) {
119+
return NextResponse.json({ message: "Tweet not found" }, { status: 404 });
120+
}
121+
122+
return NextResponse.json({ message: "Done with delete" }, { status: 200 });
123+
} catch (error) {
124+
console.log("Getting error in Delete", error);
125+
return NextResponse.json(
126+
{ message: "An unexpected error" },
127+
{ status: 500 }
128+
);
129+
}
130+
}

apps/X/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dependencies": {
1414
"@radix-ui/react-avatar": "^1.1.2",
1515
"@radix-ui/react-dialog": "^1.1.4",
16+
"@radix-ui/react-popover": "^1.1.6",
1617
"@radix-ui/react-slot": "^1.1.1",
1718
"@repo/ui": "*",
1819
"axios": "^1.7.9",

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

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
"use client";
2+
import {
3+
Popover,
4+
PopoverContent,
5+
PopoverTrigger,
6+
} from "@/components/ui/popover";
7+
import axios from "axios";
8+
import { NextResponse } from "next/server";
29
import { BiRepost } from "react-icons/bi";
310
import { FaRegBookmark, FaRegComment } from "react-icons/fa6";
411
import { FiHeart } from "react-icons/fi";
512
import { IoIosStats } from "react-icons/io";
6-
import { RiShare2Line } from "react-icons/ri";
13+
import { RiDeleteBinLine, RiShare2Line } from "react-icons/ri";
714
import { UserAvatar } from "./usrAvatar";
815

916
interface TweetProps {
@@ -18,36 +25,68 @@ interface TweetProps {
1825
}
1926

2027
export const TweetComp = ({ tweet }: TweetProps) => {
28+
const handleDelete = async () => {
29+
try {
30+
console.log("Deleting the Tweet", tweet.id);
31+
const response = await axios.delete(`/api/post?id=${tweet.id}`);
32+
console.log("Tweet Deleted", response);
33+
return NextResponse.json({ status: 200 });
34+
} catch (error) {
35+
console.log("Error while Deleting Tweet", error);
36+
}
37+
};
2138
return (
2239
<div>
2340
<div>
2441
<div className="border border-slate-800 border-spacing-x-0.5">
2542
<div className="flex p-3 gap-2">
26-
<div className="mt-1">
43+
<div className="mt-1 cursor-pointer">
2744
<UserAvatar />
2845
</div>
2946
<div className="">
3047
<div className="grid grid-cols-6">
3148
<div className="flex col-span-5">
32-
<p>{tweet.user.name}</p>
49+
<p className="font-bold cursor-pointer">{tweet.user.name}</p>
3350
{/* <p> @tweet.content</p> */}
34-
<p> · {new Date(tweet.createdDate).toLocaleDateString()}</p>
51+
<span className="px-1 ">.</span>
52+
<p className="text-slate-500">
53+
{" "}
54+
{new Date(tweet.createdDate).toLocaleDateString()}
55+
</p>
56+
</div>
57+
{/* <p className="text-end">...</p> */}
58+
<div className="ml-auto cursor-pointer hover:bg-black hover:rounded-2xl">
59+
<Popover>
60+
<PopoverTrigger className="font-bold text-slate-500">
61+
...
62+
</PopoverTrigger>
63+
<PopoverContent>
64+
<div className="text-red-700 flex items-center gap-2 cursor-pointer">
65+
<div
66+
className="flex items-center gap-1 cursor-pointer"
67+
onClick={handleDelete}
68+
>
69+
<RiDeleteBinLine />
70+
Delete
71+
</div>
72+
</div>
73+
</PopoverContent>
74+
</Popover>
3575
</div>
36-
<p className="text-end">...</p>
3776
</div>
3877
<div className="flex flex-col">
3978
<div className="list-inside">{tweet.content}</div>
40-
<div className="">Image Part</div>
79+
<div className="cursor-pointer">Image Part</div>
4180
</div>
4281
<div className="flex space-x-24 text-slate-600">
43-
<FaRegComment />
44-
<BiRepost />
45-
<FiHeart />
82+
<FaRegComment className="cursor-pointer" />
83+
<BiRepost className="cursor-pointer" />
84+
<FiHeart className="cursor-pointer" />
4685
{/* <span>{tweet.likes} </span> */}
47-
<IoIosStats />
86+
<IoIosStats className="cursor-pointer" />
4887
<div className="flex">
49-
<FaRegBookmark />
50-
<RiShare2Line />
88+
<FaRegBookmark className="cursor-pointer" />
89+
<RiShare2Line className="cursor-pointer" />
5190
</div>
5291
</div>
5392
</div>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export const HomeComp = () => {
1010
<div className="border border-y-0 custom:w-5/12 w-">
1111
<CenterComp />
1212
</div>
13-
<div className="h-screen sticky top-0 flex-shrink-0">
13+
{/* <div className="invisible h-screen sticky top-0">
1414
<HomeRight />
15-
</div>
15+
</div> */}
1616
</div>
1717
</div>
1818
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use client"
2+
3+
import * as React from "react"
4+
import * as PopoverPrimitive from "@radix-ui/react-popover"
5+
6+
import { cn } from "@/lib/utils"
7+
8+
const Popover = PopoverPrimitive.Root
9+
10+
const PopoverTrigger = PopoverPrimitive.Trigger
11+
12+
const PopoverAnchor = PopoverPrimitive.Anchor
13+
14+
const PopoverContent = React.forwardRef<
15+
React.ElementRef<typeof PopoverPrimitive.Content>,
16+
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
17+
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
18+
<PopoverPrimitive.Portal>
19+
<PopoverPrimitive.Content
20+
ref={ref}
21+
align={align}
22+
sideOffset={sideOffset}
23+
className={cn(
24+
"z-50 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
25+
className
26+
)}
27+
{...props}
28+
/>
29+
</PopoverPrimitive.Portal>
30+
))
31+
PopoverContent.displayName = PopoverPrimitive.Content.displayName
32+
33+
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Tweet" ADD COLUMN "IsDelete" BOOLEAN NOT NULL DEFAULT false;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
2-
# It should be added in your version-control system (i.e. Git)
2+
# It should be added in your version-control system (e.g., Git)
33
provider = "postgresql"

packages/db/prisma/schema.prisma

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@ datasource db {
1313
url = env("DATABASE_URL")
1414
}
1515

16-
model User{
17-
id Int @id @default(autoincrement())
18-
name String
19-
email String @unique
20-
username String @unique
21-
password String
22-
bio String?
23-
image String?
24-
tweets Tweet[]
16+
model User {
17+
id Int @id @default(autoincrement())
18+
name String
19+
email String @unique
20+
username String @unique
21+
password String
22+
bio String?
23+
image String?
24+
tweets Tweet[]
2525
createdDate DateTime @default(now())
2626
}
2727

28-
model Tweet{
29-
id Int @id @default(autoincrement())
30-
content String
31-
userID Int
32-
user User @relation(fields: [userID],references: [id])
33-
likes Int @default(0)
28+
model Tweet {
29+
id Int @id @default(autoincrement())
30+
content String
31+
userID Int
32+
user User @relation(fields: [userID], references: [id])
33+
likes Int @default(0)
3434
createdDate DateTime @default(now())
35-
}
35+
IsDelete Boolean @default(false)
36+
}

0 commit comments

Comments
 (0)