Connect, collaborate, and grow with a community of TypeScript developers
chore: refactor + fix comment deletion bug
Chris Bautista72e706a24af7
diff --git a/apps/web/src/app/explore/[slug]/page.tsx b/apps/web/src/app/explore/[slug]/page.tsxindex 2d509bd3..ccd65e5b 100644--- a/apps/web/src/app/explore/[slug]/page.tsx+++ b/apps/web/src/app/explore/[slug]/page.tsx@@ -1,6 +1,6 @@import { Suspense } from 'react';-import { ExploreSlug } from '~/components/explore/explore-slug';-import { ExploreSlugSkeleton } from '~/components/explore/explore-slug-skeleton';+import { ExploreSlugSkeleton } from '../_components/explore-slug-skeleton';+import { ExploreSlug } from '../_components/explore-slug';export const dynamic = 'force-dynamic';diff --git a/apps/web/src/components/explore/explore-card-skeleton.tsx b/apps/web/src/app/explore/_components/explore-card-skeleton.tsxsimilarity index 100%rename from apps/web/src/components/explore/explore-card-skeleton.tsxrename to apps/web/src/app/explore/_components/explore-card-skeleton.tsxdiff --git a/apps/web/src/components/explore/explore-card.tsx b/apps/web/src/app/explore/_components/explore-card.tsxsimilarity index 100%rename from apps/web/src/components/explore/explore-card.tsxrename to apps/web/src/app/explore/_components/explore-card.tsxdiff --git a/apps/web/src/components/explore/explore-slug-skeleton.tsx b/apps/web/src/app/explore/_components/explore-slug-skeleton.tsxsimilarity index 100%rename from apps/web/src/components/explore/explore-slug-skeleton.tsxrename to apps/web/src/app/explore/_components/explore-slug-skeleton.tsxdiff --git a/apps/web/src/components/explore/explore-slug.tsx b/apps/web/src/app/explore/_components/explore-slug.tsxsimilarity index 100%rename from apps/web/src/components/explore/explore-slug.tsxrename to apps/web/src/app/explore/_components/explore-slug.tsxdiff --git a/apps/web/src/components/explore/explore.action.ts b/apps/web/src/app/explore/_components/explore.action.tssimilarity index 100%rename from apps/web/src/components/explore/explore.action.tsrename to apps/web/src/app/explore/_components/explore.action.tsdiff --git a/apps/web/src/components/explore/index.tsx b/apps/web/src/app/explore/_components/index.tsxsimilarity index 100%rename from apps/web/src/components/explore/index.tsxrename to apps/web/src/app/explore/_components/index.tsxdiff --git a/apps/web/src/components/explore/section-carousel.tsx b/apps/web/src/app/explore/_components/section-carousel.tsxsimilarity index 100%rename from apps/web/src/components/explore/section-carousel.tsxrename to apps/web/src/app/explore/_components/section-carousel.tsxdiff --git a/apps/web/src/components/explore/section-skeleton.tsx b/apps/web/src/app/explore/_components/section-skeleton.tsxsimilarity index 100%rename from apps/web/src/components/explore/section-skeleton.tsxrename to apps/web/src/app/explore/_components/section-skeleton.tsxdiff --git a/apps/web/src/components/explore/section.tsx b/apps/web/src/app/explore/_components/section.tsxsimilarity index 100%rename from apps/web/src/components/explore/section.tsxrename to apps/web/src/app/explore/_components/section.tsxdiff --git a/apps/web/src/components/explore/view-more-button.tsx b/apps/web/src/app/explore/_components/view-more-button.tsxsimilarity index 100%rename from apps/web/src/components/explore/view-more-button.tsxrename to apps/web/src/app/explore/_components/view-more-button.tsxdiff --git a/apps/web/src/app/explore/page.tsx b/apps/web/src/app/explore/page.tsxindex 42e3cd63..11f2d77d 100644--- a/apps/web/src/app/explore/page.tsx+++ b/apps/web/src/app/explore/page.tsx@@ -1,4 +1,4 @@// CI fails without thisexport const dynamic = 'force-dynamic';-export { Explore as default } from '~/components/explore';+export { Explore as default } from './_components/';diff --git a/apps/web/src/components/challenge/comments/comment.action.ts b/apps/web/src/components/challenge/comments/comment.action.tsindex c7b5e4d9..11da7740 100644--- a/apps/web/src/components/challenge/comments/comment.action.ts+++ b/apps/web/src/components/challenge/comments/comment.action.ts@@ -1,8 +1,8 @@'use server';-import type { CommentRoot } from '@repo/db/types';-import { prisma } from '@repo/db';import { getServerAuthSession } from '@repo/auth/server';+import { prisma } from '@repo/db';+import type { Comment, CommentRoot, PrismaClient } from '@repo/db/types';/***@@ -89,12 +89,31 @@ export async function deleteComment(comment_id: number) {if (!session?.user.id) return 'unauthorized';if (!comment_id) return 'invalid_comment';- return await prisma.comment.delete({+ const rootComment = await prisma.comment.findFirstOrThrow({where: {- userId: session.user.id,id: comment_id,},});++ await deleteCommentWithChildren(prisma, rootComment);+}++async function deleteCommentWithChildren(prisma: PrismaClient, node: Comment) {+ const children = await prisma.comment.findMany({+ where: {+ parentId: node.id,+ },+ });++ for (const child of children) {+ await deleteCommentWithChildren(prisma, child);+ }++ await prisma.comment.delete({+ where: {+ id: node.id,+ },+ });}export type CommentsByChallengeId = NonNullable<