Skip to content

Commit 40da50a

Browse files
committed
feat: Add ArticleReaction component for managing article reactions
1 parent a45a0a7 commit 40da50a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use client";
2+
3+
import ReactionStatus from "@/components/render-props/ReactionStatus";
4+
import clsx from "clsx";
5+
import React from "react";
6+
7+
interface Props {
8+
article_id: string;
9+
}
10+
11+
const ArticleReaction: React.FC<Props> = ({ article_id }) => {
12+
return (
13+
<ReactionStatus
14+
resource_type="ARTICLE"
15+
resource_id={article_id}
16+
render={({ reactions, toggle }) => {
17+
return (
18+
<div className="flex gap-1">
19+
{reactions.map((r) => (
20+
<button
21+
className={clsx(
22+
"px-2 py-1 flex gap-1 cursor-pointer rounded-sm hover:bg-primary/20",
23+
{ "bg-primary/20": r.is_reacted }
24+
)}
25+
onClick={() => toggle(r.reaction_type!)}
26+
>
27+
<img
28+
src={`/reactions/${r.reaction_type}.svg`}
29+
alt={`reaction-${article_id}-${r.reaction_type}`}
30+
className="size-5 flex-none"
31+
/>
32+
<span>{r.count}</span>
33+
</button>
34+
))}
35+
</div>
36+
);
37+
}}
38+
/>
39+
);
40+
};
41+
42+
export default ArticleReaction;

src/app/[username]/[articleHandle]/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { notFound } from "next/navigation";
1313
import type { Article, WithContext } from "schema-dts";
1414
import { eq } from "sqlkit";
1515
import ArticleSidebar from "./_components/ArticleSidebar";
16+
import ReactionStatus from "@/components/render-props/ReactionStatus";
17+
import clsx from "clsx";
18+
import ArticleReaction from "./_components/ArticleReaction";
1619

1720
interface ArticlePageProps {
1821
params: Promise<{
@@ -150,6 +153,8 @@ const Page: NextPage<ArticlePageProps> = async ({ params }) => {
150153
<h1 className="text-2xl font-bold">{article?.title ?? ""}</h1>
151154
</div>
152155

156+
<ArticleReaction article_id={article.id} />
157+
153158
<div className="mx-auto content-typography">{parsedHTML}</div>
154159
</div>
155160
</HomepageLayout>

0 commit comments

Comments
 (0)