Skip to content

Commit

Permalink
render sub comments, don't redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
blackmann committed Feb 12, 2024
1 parent 77cc64e commit c8e7be1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion client/app/routes/comments.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { LoaderFunctionArgs, json } from "@remix-run/node";
import { prisma } from "~/lib/prisma.server";
import { render } from "~/lib/render.server";

export const loader = async ({ request }: LoaderFunctionArgs) => {
const postId = new URL(request.url).searchParams.get("postId");

if (!postId) {
return new Response("Missing postId", { status: 400 });
return new Response("Missing `postId`", { status: 400 });
}

const comments = await prisma.post.findMany({
where: { parentId: Number(postId) },
include: { user: true, media: true },
});

for (const comment of comments) {
comment.content = await render(comment.content);
}

return json({ comments });
};
4 changes: 2 additions & 2 deletions client/app/routes/discussions_.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
});

for (const comment of comments) {
comment.content = await render(comment.content)
comment.content = await render(comment.content);
}

return json({
Expand All @@ -73,7 +73,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
return redirect("/discussions");
}

return redirect(`/discussions/${post.parentId}`);
return null;
}

case "POST": {
Expand Down

0 comments on commit c8e7be1

Please sign in to comment.