Skip to content

Commit 5169253

Browse files
committed
Pipe data to all of our row badges.
1 parent ea98356 commit 5169253

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

src/components/Badge.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type JSX, useState } from 'react'
22
import { twMerge } from 'tailwind-merge'
33
import type { VariantProps } from 'tailwind-variants'
44
import { badgeCVA, typeColors, typeIcons } from '@/components/design'
5+
import type { CommentTableRow } from '@/entrypoints/background'
56

67
import { CodePreview } from './BadgePopups/CodePreview'
78
import { ImagePreview } from './BadgePopups/ImagePreview'
@@ -17,12 +18,16 @@ const typePopups = {
1718
open: OpenTabPopup,
1819
text: TextPreview,
1920
time: TimePreview,
20-
} satisfies Partial<Record<keyof typeof typeIcons, (props?: any) => JSX.Element>>
21+
} satisfies Partial<Record<keyof typeof typeIcons, (props: BadgePopupProps) => JSX.Element>>
22+
23+
export interface BadgePopupProps {
24+
row: CommentTableRow
25+
}
2126

2227
export type BadgeProps = VariantProps<typeof badgeCVA> & {
2328
type: keyof typeof typeIcons
2429
text?: number | string
25-
data?: any
30+
data?: CommentTableRow
2631
}
2732

2833
const Badge = ({ text, type, data }: BadgeProps) => {
@@ -48,14 +53,14 @@ const Badge = ({ text, type, data }: BadgeProps) => {
4853
{type === 'blank' || <Icon className='h-3 w-3' />}
4954
{text || type}
5055
</span>
51-
{PopupComponent && (
56+
{PopupComponent && data && (
5257
<div
5358
className={twMerge(
5459
'absolute top-full z-10 w-30 rounded border px-2 py-1 text-left text-xs shadow-lg',
5560
typeColors[type],
5661
)}
5762
>
58-
<PopupComponent {...data} />
63+
<PopupComponent row={data} />
5964
</div>
6065
)}
6166
</button>

src/components/BadgePopups/CodePreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function CodePreview() {
1+
import type { BadgePopupProps } from '@/components/Badge'
2+
3+
export function CodePreview({ row: _row }: BadgePopupProps) {
24
return (
35
<>
46
TODO{' '}

src/components/BadgePopups/ImagePreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function ImagePreview() {
1+
import type { BadgePopupProps } from '@/components/Badge'
2+
3+
export function ImagePreview({ row: _row }: BadgePopupProps) {
24
return (
35
<>
46
TODO{' '}

src/components/BadgePopups/LinkPreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function LinkPreview() {
1+
import type { BadgePopupProps } from '@/components/Badge'
2+
3+
export function LinkPreview({ row: _row }: BadgePopupProps) {
24
return (
35
<>
46
TODO{' '}

src/components/BadgePopups/OpenTabPopup.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1+
import type { BadgePopupProps } from '@/components/Badge'
12
import { openOrFocusComment } from '@/entrypoints/popup/popup'
23

3-
interface OpenTabPopupProps {
4-
uniqueKey: string
5-
}
6-
7-
export function OpenTabPopup({ uniqueKey }: OpenTabPopupProps) {
4+
export function OpenTabPopup({ row }: BadgePopupProps) {
85
const handleClick = () => {
9-
openOrFocusComment(uniqueKey)
6+
openOrFocusComment(row.spot.unique_key)
107
}
118

129
return (

src/components/BadgePopups/TextPreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function TextPreview() {
1+
import type { BadgePopupProps } from '@/components/Badge'
2+
3+
export function TextPreview({ row: _row }: BadgePopupProps) {
24
return (
35
<>
46
TODO{' '}

src/components/BadgePopups/TimePreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export function TimePreview() {
1+
import type { BadgePopupProps } from '@/components/Badge'
2+
3+
export function TimePreview({ row: _row }: BadgePopupProps) {
24
return (
35
<>
46
TODO{' '}

src/components/CommentRow.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ export function CommentRow({ row, selectedIds, toggleSelection }: CommentRowProp
3939
</div>
4040
<div className='flex flex-shrink-0 items-center gap-1'>
4141
{row.latestDraft.stats.links.length > 0 && (
42-
<Badge type='link' text={row.latestDraft.stats.links.length} />
42+
<Badge type='link' text={row.latestDraft.stats.links.length} data={row} />
4343
)}
4444
{row.latestDraft.stats.images.length > 0 && (
45-
<Badge type='image' text={row.latestDraft.stats.images.length} />
45+
<Badge type='image' text={row.latestDraft.stats.images.length} data={row} />
4646
)}
4747
{row.latestDraft.stats.codeBlocks.length > 0 && (
48-
<Badge type='code' text={row.latestDraft.stats.codeBlocks.length} />
48+
<Badge type='code' text={row.latestDraft.stats.codeBlocks.length} data={row} />
4949
)}
50-
<Badge type='text' text={row.latestDraft.stats.charCount} />
51-
<Badge type='time' text={timeAgo(row.latestDraft.time)} />
52-
{row.isOpenTab && <Badge type='open' data={{ uniqueKey: row.spot.unique_key }} />}
50+
<Badge type='text' text={row.latestDraft.stats.charCount} data={row} />
51+
<Badge type='time' text={timeAgo(row.latestDraft.time)} data={row} />
52+
{row.isOpenTab && <Badge type='open' data={row} />}
5353
</div>
5454
</div>
5555

0 commit comments

Comments
 (0)