File tree Expand file tree Collapse file tree
src/app/[username]/[articleHandle] Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ import { eq } from "sqlkit";
2020import ArticleSidebar from "./_components/ArticleSidebar" ;
2121import ResourceBookmark from "@/components/ResourceBookmark" ;
2222import 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
2427interface 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" >
You can’t perform that action at this time.
0 commit comments