added relation between post replyid and id so we can show and link replies on the reply in the thread
This commit is contained in:
parent
4972b292b8
commit
a2e9314724
|
@ -56,7 +56,11 @@ export async function loader({ params }) {
|
||||||
id: parseInt(threadId),
|
id: parseInt(threadId),
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
posts: true,
|
posts: {
|
||||||
|
include: {
|
||||||
|
replies: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -80,15 +84,26 @@ export default function Thread() {
|
||||||
<ul className="flex flex-col m-8 ">
|
<ul className="flex flex-col m-8 ">
|
||||||
{data.posts.map(post =>
|
{data.posts.map(post =>
|
||||||
<li id={`${post.id}`} className="rounded shadow p-4 m-4 odd:bg-ctp-mantle even:bg-ctp-base" key={post.id}>
|
<li id={`${post.id}`} className="rounded shadow p-4 m-4 odd:bg-ctp-mantle even:bg-ctp-base" key={post.id}>
|
||||||
<span id={`${post.id}`}>Reply id: <strong>{post.id}</strong> Replied at: <strong>{post.createdAt} </strong></span>
|
<div className="flex">
|
||||||
<Link onClick={(event) => {
|
<span>Reply id: <strong>{post.id}</strong> Replied at: <strong>{post.createdAt} </strong></span>
|
||||||
event.preventDefault();
|
<Link className="mx-2 text-ctp-rosewater hover:text-ctp-maroon hover:underline" onClick={(event) => {
|
||||||
document.getElementById(`bottom`).scrollIntoView(true);
|
event.preventDefault();
|
||||||
setReplying(post.id);
|
document.getElementById(`bottom`).scrollIntoView(true);
|
||||||
}} to={`#bottom`}
|
setReplying(post.id);
|
||||||
>Reply
|
}} to={`#bottom`}
|
||||||
</Link>
|
>Reply
|
||||||
<br />
|
</Link>
|
||||||
|
<ul className="flex flex-wrap space-x-1">
|
||||||
|
{post?.replies?.map(reply =>
|
||||||
|
<li key={reply.id}>
|
||||||
|
<Link onClick={event => {
|
||||||
|
event.preventDefault();
|
||||||
|
document.getElementById(`${reply.id}`).scrollIntoView(true);
|
||||||
|
}} className="text-ctp-teal hover:text-ctp-sky hover:underline" to={`#${reply.id}`}>{reply.id}</Link>
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
{post.replyingTo ? <Link onClick={event => {
|
{post.replyingTo ? <Link onClick={event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.getElementById(`${post.replyingTo}`).scrollIntoView(true);
|
document.getElementById(`${post.replyingTo}`).scrollIntoView(true);
|
||||||
|
|
|
@ -29,6 +29,8 @@ model Post {
|
||||||
comment String
|
comment String
|
||||||
imageName String?
|
imageName String?
|
||||||
replyingTo Int?
|
replyingTo Int?
|
||||||
|
Reply Post? @relation("d", fields: [replyingTo], references: [id])
|
||||||
|
replies Post[] @relation("d")
|
||||||
|
|
||||||
post Thread @relation(fields: [postId], references: [id])
|
post Thread @relation(fields: [postId], references: [id])
|
||||||
postId Int
|
postId Int
|
||||||
|
|
Loading…
Reference in New Issue