1- import React , { useEffect , useState } from 'react'
1+ import React , { useCallback , useEffect , useState } from 'react'
22import { BiBookmarkMinus , BiBookmarkPlus , BiShareAlt } from 'react-icons/bi'
33import { MdBugReport } from 'react-icons/md'
44import { reportLink } from 'src/config'
@@ -14,15 +14,22 @@ type CardItemWithActionsProps = {
1414 url : string
1515 id : string
1616 }
17+ showBookmarkAction ?: boolean
1718 source : string
1819 cardItem : React . ReactNode
20+ customActions ?: Array < {
21+ label : string
22+ Component : React . ReactNode
23+ } >
1924 sourceType ?: 'rss' | 'supported'
2025}
2126
2227export const CardItemWithActions = ( {
2328 cardItem,
2429 item,
2530 source,
31+ showBookmarkAction = true ,
32+ customActions,
2633 sourceType = 'supported' ,
2734} : CardItemWithActionsProps ) => {
2835 const [ shareModalData , setShareModalData ] = useState < ShareModalData > ( )
@@ -32,7 +39,7 @@ export const CardItemWithActions = ({
3239 userBookmarks . some ( ( bm ) => bm . source === source && bm . url === item . url )
3340 )
3441
35- const onBookmarkClick = ( ) => {
42+ const onBookmarkClick = useCallback ( ( ) => {
3643 const itemToBookmark = {
3744 title : item . title ,
3845 url : item . url ,
@@ -56,22 +63,22 @@ export const CardItemWithActions = ({
5663 } else {
5764 trackLinkBookmark ( analyticsAttrs )
5865 }
59- }
66+ } , [ isBookmarked , item , source , sourceType , bookmarkPost , unbookmarkPost ] )
6067
6168 useEffect ( ( ) => {
6269 setIsBookmarked ( userBookmarks . some ( ( bm ) => bm . source === source && bm . url === item . url ) )
6370 } , [ userBookmarks , source , item ] )
6471
65- const onShareModalClicked = ( ) => {
72+ const onShareModalClicked = useCallback ( ( ) => {
6673 setShareModalData ( { title : item . title , link : item . url , source : source } )
67- }
74+ } , [ item . title , item . url , source ] )
6875
69- const onReportClicked = ( ) => {
76+ const onReportClicked = useCallback ( ( ) => {
7077 const tags = useUserPreferences
7178 . getState ( )
7279 . userSelectedTags . map ( ( tag ) => tag . label . toLocaleLowerCase ( ) )
7380 window . open ( `${ reportLink } ?tags=${ tags . join ( ',' ) } &url=${ item . url } ` , '_blank' )
74- }
81+ } , [ item . url ] )
7582
7683 return (
7784 < div key = { item . id } className = "blockRow" >
@@ -96,12 +103,22 @@ export const CardItemWithActions = ({
96103 aria-label = "Open share modal" >
97104 < BiShareAlt />
98105 </ button >
99- < button
100- className = { `blockActionButton ${ isBookmarked ? 'active' : '' } ` }
101- onClick = { onBookmarkClick }
102- aria-label = "Bookmark item" >
103- { ! isBookmarked ? < BiBookmarkPlus /> : < BiBookmarkMinus /> }
104- </ button >
106+
107+ { customActions &&
108+ customActions . map ( ( action ) => (
109+ < div key = { action . label } aria-label = { action . label } >
110+ { action . Component }
111+ </ div >
112+ ) ) }
113+
114+ { showBookmarkAction && (
115+ < button
116+ className = { `blockActionButton ${ isBookmarked ? 'active' : '' } ` }
117+ onClick = { onBookmarkClick }
118+ aria-label = "Bookmark item" >
119+ { ! isBookmarked ? < BiBookmarkPlus /> : < BiBookmarkMinus /> }
120+ </ button >
121+ ) }
105122 </ div >
106123 </ div >
107124 )
0 commit comments