Skip to content

Commit 87342e5

Browse files
fix: delete collection with memes
1 parent c8ad587 commit 87342e5

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ model Meme {
3333
model Collection {
3434
id String @id @default(auto()) @map("_id") @db.ObjectId
3535
name String
36-
memes MemeCollection[]
36+
memes MemeCollection[]
3737
madeById String
3838
madeBy User @relation(fields: [madeById], references: [userId])
3939
}
@@ -43,7 +43,7 @@ model MemeCollection {
4343
memeId String @db.ObjectId
4444
meme Meme @relation(fields: [memeId], references: [id])
4545
collectionId String @db.ObjectId
46-
collection Collection @relation(fields: [collectionId], references: [id])
46+
collection Collection @relation(fields: [collectionId], references: [id], onDelete: Cascade)
4747
createdAt DateTime @default(now())
4848
updatedAt DateTime @updatedAt
4949

src/app/dashboard/collections/[id]/_components/delete-collection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export function DeleteCollection({ collectionId }: DeleteCollectionProps) {
3737
});
3838
if (res.ok) {
3939
toast({
40-
title: "Meme deleted",
41-
description: "The meme has been deleted",
40+
title: "Collection deleted!",
41+
description: "Collection was successfully deleted",
4242
});
4343
await refreshCollections();
4444
router.push("/dashboard/collections");

src/components/save-meme.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { Input } from "@/components/ui/input";
1414
import { Label } from "@/components/ui/label";
1515
import { ScrollArea } from "@/components/ui/scroll-area";
16-
import { FolderOpen } from "lucide-react";
16+
import { FolderOpen, Loader2 } from "lucide-react";
1717
import { useUser } from "@clerk/nextjs";
1818
import { Collection } from "@prisma/client";
1919
import { getCollections } from "@/app/_actions";
@@ -172,7 +172,7 @@ export default function SaveMeme({ src, name, memeId }: MemeProps) {
172172
className={`p-2 cursor-pointer dark:hover:bg-primary hover:bg-gray-100 rounded ${
173173
selectedCollection?.id === collection.id
174174
? "bg-primary text-white hover:bg-primary/80 hover:text-white"
175-
: ""
175+
: ""
176176
}`}
177177
onClick={() => {
178178
if (selectedCollection?.id !== collection.id) {
@@ -188,7 +188,14 @@ export default function SaveMeme({ src, name, memeId }: MemeProps) {
188188
</ScrollArea>
189189
<DialogFooter>
190190
<Button onClick={handleSaveMeme} disabled={loading}>
191-
{loading ? "Saving..." : "Save meme"}
191+
{loading ? (
192+
<span className="flex items-center justify-center">
193+
<Loader2 className="mr-2 animate-spin" />
194+
Saving
195+
</span>
196+
) : (
197+
"Save meme"
198+
)}
192199
</Button>
193200
</DialogFooter>
194201
</>
@@ -198,7 +205,10 @@ export default function SaveMeme({ src, name, memeId }: MemeProps) {
198205
return (
199206
<Dialog open={open} onOpenChange={handleOpenChange}>
200207
<DialogTrigger asChild>
201-
<Button variant="secondary" className="bg-gray-600 hover:bg-gray-800 text-white focus:bg-gray-900">
208+
<Button
209+
variant="secondary"
210+
className="bg-gray-600 hover:bg-gray-800 text-white focus:bg-gray-900"
211+
>
202212
<FolderOpen className="mr-2" /> Save to Collection
203213
</Button>
204214
</DialogTrigger>

0 commit comments

Comments
 (0)