File tree Expand file tree Collapse file tree 3 files changed +69
-34
lines changed
app/[username]/[articleHandle] Expand file tree Collapse file tree 3 files changed +69
-34
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { notFound } from "next/navigation";
1818import type { Article , WithContext } from "schema-dts" ;
1919import { eq } from "sqlkit" ;
2020import ArticleSidebar from "./_components/ArticleSidebar" ;
21+ import ResourceBookmark from "@/components/ResourceBookmark" ;
2122
2223interface ArticlePageProps {
2324 params : Promise < {
@@ -155,7 +156,16 @@ const Page: NextPage<ArticlePageProps> = async ({ params }) => {
155156 < h1 className = "text-2xl font-bold" > { article ?. title ?? "" } </ h1 >
156157 </ div >
157158
158- < ResourceReaction resource_type = "ARTICLE" resource_id = { article . id } />
159+ < div className = "flex items-center justify-between mb-4" >
160+ < ResourceReaction
161+ resource_type = "ARTICLE"
162+ resource_id = { article . id }
163+ />
164+ < ResourceBookmark
165+ resource_type = "ARTICLE"
166+ resource_id = { article . id }
167+ />
168+ </ div >
159169
160170 < div className = "mx-auto content-typography" > { parsedHTML } </ div >
161171 </ div >
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { ResourceBookmarkable } from "./render-props/ResourceBookmarkable";
1212import ResourceReaction from "./ResourceReaction" ;
1313import { HoverCard , HoverCardContent , HoverCardTrigger } from "./ui/hover-card" ;
1414import UserInformationCard from "./UserInformationCard" ;
15+ import ResourceBookmark from "./ResourceBookmark" ;
1516
1617interface ArticleCardProps {
1718 id : string ;
@@ -118,39 +119,7 @@ const ArticleCard = ({
118119
119120 < div className = "mt-4 flex items-center justify-between" >
120121 < ResourceReaction resource_type = "ARTICLE" resource_id = { id } />
121-
122- < ResourceBookmarkable
123- resource_type = "ARTICLE"
124- resource_id = { id }
125- render = { ( { bookmarked, toggle } ) => (
126- < button
127- onClick = { ( ) => {
128- if ( ! session ?. user ) {
129- loginPopup . show ( ) ;
130- return ;
131- }
132- toggle ( ) ;
133- } }
134- className = { clsx (
135- "transition-colors duration-300 flex cursor-pointer px-2 py-1 rounded-sm hover:bg-primary/20" ,
136- { "bg-primary/20" : bookmarked }
137- ) }
138- >
139- < svg
140- xmlns = "http://www.w3.org/2000/svg"
141- viewBox = "0 0 24 24"
142- strokeLinecap = "round"
143- strokeLinejoin = "round"
144- className = { clsx ( "size-5 stroke-2 fill-transparent" , {
145- "!stroke-current" : ! bookmarked ,
146- "!fill-current" : bookmarked ,
147- } ) }
148- >
149- < path d = "m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
150- </ svg >
151- </ button >
152- ) }
153- />
122+ < ResourceBookmark resource_type = "ARTICLE" resource_id = { id } />
154123 </ div >
155124 </ div >
156125 ) ;
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import React from "react" ;
4+ import { ResourceBookmarkable } from "./render-props/ResourceBookmarkable" ;
5+ import { useSession } from "@/store/session.atom" ;
6+ import { useLoginPopup } from "./app-login-popup" ;
7+ import clsx from "clsx" ;
8+
9+ interface ResourceBookmarkProps {
10+ resource_type : "ARTICLE" | "COMMENT" ;
11+ resource_id : string ;
12+ }
13+ const ResourceBookmark : React . FC < ResourceBookmarkProps > = ( {
14+ resource_type,
15+ resource_id,
16+ } ) => {
17+ const session = useSession ( ) ;
18+ const loginPopup = useLoginPopup ( ) ;
19+
20+ return (
21+ < ResourceBookmarkable
22+ resource_type = { resource_type }
23+ resource_id = { resource_id }
24+ render = { ( { bookmarked, toggle } ) => (
25+ < button
26+ onClick = { ( ) => {
27+ if ( ! session ?. user ) {
28+ loginPopup . show ( ) ;
29+ return ;
30+ }
31+ toggle ( ) ;
32+ } }
33+ className = { clsx (
34+ "transition-colors duration-300 flex cursor-pointer px-2 py-1 rounded-sm hover:bg-primary/20" ,
35+ { "bg-primary/20" : bookmarked }
36+ ) }
37+ >
38+ < svg
39+ xmlns = "http://www.w3.org/2000/svg"
40+ viewBox = "0 0 24 24"
41+ strokeLinecap = "round"
42+ strokeLinejoin = "round"
43+ className = { clsx ( "size-5 stroke-2 fill-transparent" , {
44+ "!stroke-current" : ! bookmarked ,
45+ "!fill-current" : bookmarked ,
46+ } ) }
47+ >
48+ < path d = "m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
49+ </ svg >
50+ </ button >
51+ ) }
52+ />
53+ ) ;
54+ } ;
55+
56+ export default ResourceBookmark ;
You can’t perform that action at this time.
0 commit comments