-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
145f744
commit cf5ca94
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { json, type LoaderFunctionArgs } from '@remix-run/node' | ||
import { useLoaderData } from '@remix-run/react' | ||
import { z } from 'zod' | ||
import { Markdown } from '#app/components/markdown.tsx' | ||
import { db } from '#app/db.ts' | ||
import { getPostsAndPollsByTagId } from '#app/modules/posts/post-service.ts' | ||
import { type PollPagePost, type Post } from '#app/modules/posts/post-types.ts' | ||
import { getTagById } from '#app/modules/tags/tag-repository.ts' | ||
import { type Tag } from '#app/modules/tags/tag-types.ts' | ||
|
||
const tagIdSchema = z.coerce.number() | ||
|
||
export async function loader({ params }: LoaderFunctionArgs) { | ||
const tagId = tagIdSchema.parse(params.tagId) | ||
const { | ||
tag, | ||
posts, | ||
polls, | ||
}: { | ||
tag: Tag | ||
posts: Post[] | ||
polls: PollPagePost[] | ||
} = await db.transaction().execute(async trx => { | ||
const tag = await getTagById(trx, tagId) | ||
const { posts, polls } = await getPostsAndPollsByTagId(trx, tag.id) | ||
return { | ||
tag: tag, | ||
posts: posts, | ||
polls: polls, | ||
} | ||
}) | ||
|
||
return json({ tag, posts, polls }) | ||
} | ||
|
||
export default function TagPage() { | ||
const { tag, posts, polls } = useLoaderData<typeof loader>() | ||
|
||
return ( | ||
<> | ||
<div className="mb-6"> | ||
<Markdown deactivateLinks={false}>{`# # ${tag.tag}`}</Markdown> | ||
</div> | ||
<div className="mb-6"> | ||
<h1>Posts</h1> | ||
{posts.map(post => { | ||
return ( | ||
<div key={`post-${post.id}`} className="mb-4"> | ||
{post.content} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
<div className="mb-6"> | ||
<h1>Polls</h1> | ||
{polls.map(poll => { | ||
return ( | ||
<div key={`post-${poll.id}`} className="mb-4"> | ||
{poll.content} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</> | ||
) | ||
} |