11import './style.css'
22import React from 'react'
33import { createRoot } from 'react-dom/client'
4- import {
5- Table ,
6- TableBody ,
7- TableCell ,
8- TableHead ,
9- TableHeader ,
10- TableRow ,
11- } from '@/components/ui/table'
4+ import { SpotTable } from '@/components/SpotTable'
125import type { CommentState } from '@/entrypoints/background'
136import { logger } from '@/lib/logger'
147import type { GetOpenSpotsMessage , GetOpenSpotsResponse , SwitchToTabMessage } from '@/lib/messages'
158import { EnhancerRegistry } from '@/lib/registries'
16- import { cn } from '@/lib/utils'
17-
18- const enhancers = new EnhancerRegistry ( )
199
2010async function getOpenSpots ( ) : Promise < CommentState [ ] > {
2111 logger . debug ( 'Sending message to background script...' )
@@ -40,38 +30,7 @@ function switchToTab(tabId: number, windowId: number): void {
4030 window . close ( )
4131}
4232
43- interface SpotRowProps {
44- commentState : CommentState
45- onClick : ( ) => void
46- }
47-
48- function SpotRow ( { commentState, onClick } : SpotRowProps ) {
49- const enhancer = enhancers . enhancerFor ( commentState . spot )
50-
51- if ( ! enhancer ) {
52- logger . error ( 'No enhancer found for:' , commentState . spot )
53- logger . error ( 'Only have enhancers for:' , enhancers . byType )
54- return null
55- }
56-
57- return (
58- < TableRow
59- className = { cn (
60- 'cursor-pointer transition-colors hover:bg-muted/50' ,
61- 'border-b border-border/40' ,
62- ) }
63- onClick = { onClick }
64- >
65- < TableCell className = 'p-3' >
66- < div className = 'flex items-center gap-2' >
67- < div className = 'font-medium text-sm text-foreground overflow-hidden text-ellipsis whitespace-nowrap' >
68- { enhancer . tableRow ( commentState . spot ) }
69- </ div >
70- </ div >
71- </ TableCell >
72- </ TableRow >
73- )
74- }
33+ const enhancers = new EnhancerRegistry ( )
7534
7635function PopupApp ( ) {
7736 const [ spots , setSpots ] = React . useState < CommentState [ ] > ( [ ] )
@@ -96,33 +55,25 @@ function PopupApp() {
9655 return < div className = 'p-4 text-center text-muted-foreground' > Loading...</ div >
9756 }
9857
99- if ( spots . length === 0 ) {
100- return (
101- < div className = 'p-10 text-center text-muted-foreground italic' > No open comment spots</ div >
102- )
58+ const handleSpotClick = ( spot : CommentState ) => {
59+ switchToTab ( spot . tab . tabId , spot . tab . windowId )
10360 }
10461
10562 return (
10663 < div className = 'w-full' >
10764 < h2 className = 'mb-4 text-lg font-semibold text-foreground' > Open Comment Spots</ h2 >
10865
10966 < div className = 'border rounded-md' >
110- < Table >
111- < TableHeader >
112- < TableRow >
113- < TableHead className = 'p-3 font-medium text-muted-foreground' > Comment Spots</ TableHead >
114- </ TableRow >
115- </ TableHeader >
116- < TableBody >
117- { spots . map ( ( spot ) => (
118- < SpotRow
119- key = { spot . spot . unique_key }
120- commentState = { spot }
121- onClick = { ( ) => switchToTab ( spot . tab . tabId , spot . tab . windowId ) }
122- />
123- ) ) }
124- </ TableBody >
125- </ Table >
67+ < SpotTable
68+ spots = { spots }
69+ enhancerRegistry = { enhancers }
70+ onSpotClick = { handleSpotClick }
71+ headerClassName = 'p-3 font-medium text-muted-foreground'
72+ rowClassName = 'transition-colors hover:bg-muted/50 border-b border-border/40'
73+ cellClassName = 'p-3'
74+ emptyStateMessage = 'No open comment spots'
75+ showHeader = { true }
76+ />
12677 </ div >
12778 </ div >
12879 )
0 commit comments