diff --git a/app/components/ThreadReply.jsx b/app/components/ThreadReply.jsx new file mode 100644 index 0000000..c1f71d2 --- /dev/null +++ b/app/components/ThreadReply.jsx @@ -0,0 +1,79 @@ +import { Link } from "@remix-run/react"; + +export function ThreadReply({ post }) { + return ( +
  • +
    + + Reply id: {post.id} Replied at:{" "} + {new Date(post.createdAt).toLocaleString()} + + { + event.preventDefault(); + document.getElementById(`bottom`).scrollIntoView(true); + setReplying(post.id); + }} + to={`/threads/${post.postId}#bottom`} + > + Reply + + +
    + {post.replyingTo ? ( + { + event.preventDefault(); + document.getElementById(`${post.replyingTo}`).scrollIntoView(true); + }} + className="text-sm font-semibold hover:underline" + to={`#${post.replyingTo}`} + > + Replying to id: {post.replyingTo} + + ) : ( + "" + )} + {post.imageName !== null ? ( +
    + post image + + Click to show full image + +
    + ) : ( + "" + )} +

    {post.comment}

    +
  • + ); +} diff --git a/app/root.jsx b/app/root.jsx index 22c52ba..4434c2e 100644 --- a/app/root.jsx +++ b/app/root.jsx @@ -65,7 +65,6 @@ export default function App() { /> )} - diff --git a/app/routes/index.jsx b/app/routes/index.jsx index 48f9998..f82f25b 100644 --- a/app/routes/index.jsx +++ b/app/routes/index.jsx @@ -8,6 +8,7 @@ import { import prisma from "~/utils/db.server"; import Overlay from "~/components/Overlay"; import { useState } from "react"; +import { ThreadReply } from "~/components/ThreadReply"; export async function action({ request }) { const clonedData = request.clone(); @@ -100,7 +101,11 @@ export async function loader({ request }) { const data = await prisma.thread.findMany({ include: { - posts: true, + posts: { + include: { + replies: true, + }, + }, }, }); @@ -196,30 +201,48 @@ export default function Index() { {data.map((thread) => thread.title.includes(search) || thread.post.includes(search) ? (
  • -
    - thread image -
    -

    - {thread.title} -

    -

    - {thread.post} -

    -

    - Posts: {thread.posts.length} -

    +
    + thread image +
    +
    +

    + {thread.title} +

    +

    + {thread.post} +

    +

    + Posts: {thread.posts.length} +

    +
    +
    +
    +

    + Last {thread.posts.slice(-3).length} post(s) +

    +
      + {thread.posts.length > 0 ? ( + thread.posts + .slice(-3) + .map((post) => ( + + )) + ) : ( +
    • post has no replies yet...
    • + )} +
  • diff --git a/app/routes/threads/$threadId.jsx b/app/routes/threads/$threadId.jsx index 85164e5..db98354 100644 --- a/app/routes/threads/$threadId.jsx +++ b/app/routes/threads/$threadId.jsx @@ -7,6 +7,7 @@ import { import { useLoaderData, Form, useActionData, Link } from "@remix-run/react"; import { useState } from "react"; import Overlay from "~/components/Overlay"; +import { ThreadReply } from "~/components/ThreadReply"; import prisma from "~/utils/db.server"; export async function action({ request, params }) { @@ -156,83 +157,7 @@ export default function Thread() {