Skip to content

Commit ca09fe4

Browse files
committed
feat: add EditArticleButton component and integrate it into the article page
1 parent b5eec51 commit ca09fe4

3 files changed

Lines changed: 51 additions & 47 deletions

File tree

src/app/[username]/[articleHandle]/_components/ArticleReaction.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"use client";
2+
3+
import { Button } from "@/components/ui/button";
4+
import { useTranslation } from "@/i18n/use-translation";
5+
import { useSession } from "@/store/session.atom";
6+
import Link from "next/link";
7+
import React from "react";
8+
interface Props {
9+
article_id: string;
10+
article_author_id: string;
11+
}
12+
13+
const EditArticleButton: React.FC<Props> = ({
14+
article_id,
15+
article_author_id,
16+
}) => {
17+
const { _t } = useTranslation();
18+
const session = useSession();
19+
20+
if (
21+
!session?.session?.user_id ||
22+
session.session.user_id !== article_author_id
23+
) {
24+
return null;
25+
}
26+
27+
return (
28+
<Button size={"sm"} variant={"secondary"} asChild className=" py-[2px]">
29+
<Link href={`/dashboard/articles/${article_id}`}>{_t("Edit")}</Link>
30+
</Button>
31+
);
32+
};
33+
34+
export default EditArticleButton;

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { eq } from "sqlkit";
2020
import ArticleSidebar from "./_components/ArticleSidebar";
2121
import ResourceBookmark from "@/components/ResourceBookmark";
2222
import Markdown from "@/lib/markdown/Markdown";
23+
import { Button } from "@/components/ui/button";
24+
import _t from "@/i18n/_t";
25+
import EditArticleButton from "./_components/EditArticleButton";
2326

2427
interface ArticlePageProps {
2528
params: Promise<{
@@ -169,10 +172,20 @@ const Page: NextPage<ArticlePageProps> = async ({ params }) => {
169172
resource_type="ARTICLE"
170173
resource_id={article.id}
171174
/>
172-
<ResourceBookmark
173-
resource_type="ARTICLE"
174-
resource_id={article.id}
175-
/>
175+
176+
<div className="flex gap-1.5 items-center">
177+
{article.user?.id && (
178+
<EditArticleButton
179+
article_id={article.id}
180+
article_author_id={article.user?.id}
181+
/>
182+
)}
183+
184+
<ResourceBookmark
185+
resource_type="ARTICLE"
186+
resource_id={article.id}
187+
/>
188+
</div>
176189
</div>
177190

178191
<div className="mx-auto content-typography">

0 commit comments

Comments
 (0)