Skip to content

Commit 596509f

Browse files
committed
migrate cardlink and clickable item to ts
1 parent bb3e0bf commit 596509f

6 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/components/Elements/CardLink/CardLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import ClickableItem from '../../ClickableItem'
2+
import { ClickableItem } from '../ClickableItem'
33

44
type CardLinkProps = {
55
link: string

src/components/CardItemWithActions.js renamed to src/components/Elements/CardWithActions/CardItemWithActions.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@ import { useBookmarks } from 'src/stores/bookmarks'
33
import { BiBookmarkPlus } from 'react-icons/bi'
44
import { BiBookmarkMinus } from 'react-icons/bi'
55
import { trackLinkBookmark, trackLinkUnBookmark, Attributes } from 'src/lib/analytics'
6+
import { BaseEntry } from 'src/types'
67

7-
export default function CardItemWithActions({ cardItem, item, index, source }) {
8+
type CardItemWithActionsProps = {
9+
item: BaseEntry
10+
index: number
11+
source: string
12+
cardItem: React.ReactNode
13+
}
14+
15+
export const CardItemWithActions = ({
16+
cardItem,
17+
item,
18+
index,
19+
source,
20+
}: CardItemWithActionsProps) => {
821
const { bookmarkPost, unbookmarkPost, userBookmarks } = useBookmarks()
922
const [isBookmarked, setIsBookmarked] = useState(
1023
userBookmarks.some((bm) => bm.source === source && bm.url === item.url)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./CardItemWithActions"

src/components/ClickableItem.js renamed to src/components/Elements/ClickableItem/ClickableItem.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@ import { ref } from 'src/config'
44

55
import { useUserPreferences } from 'src/stores/preferences'
66

7-
const ClickableItem = ({ link, className, children, analyticsAttributes, appendRef = true }) => {
7+
type ClickableItemProps = {
8+
link: string
9+
className?: string
10+
children: React.ReactNode
11+
analyticsAttributes: {
12+
[key: string]: string | number | undefined
13+
}
14+
appendRef?: boolean
15+
}
16+
export const ClickableItem = ({
17+
link,
18+
className,
19+
children,
20+
analyticsAttributes,
21+
appendRef = true,
22+
}: ClickableItemProps) => {
823
const { openLinksNewTab } = useUserPreferences()
924

10-
const handleClick = (e) => {
25+
const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
1126
e.preventDefault()
1227

1328
trackLinkOpen(analyticsAttributes)
@@ -39,5 +54,3 @@ const ClickableItem = ({ link, className, children, analyticsAttributes, appendR
3954
</a>
4055
)
4156
}
42-
43-
export default ClickableItem
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./ClickableItem"

src/components/Elements/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ export * from "./MarketingBanner"
44
export * from "./SearchBar"
55
export * from "./UserTags"
66
export * from "./BottomNavigation"
7-
export * from "./CardLink"
7+
export * from "./CardLink"
8+
export * from "./CardWithActions"
9+
export * from "./ClickableItem"

0 commit comments

Comments
 (0)