1- import { ChevronRight , Database , Hash , Loader2 , MessageSquare } from "lucide-react" ;
2- import { type ReactNode , useEffect , useRef , useState } from "react" ;
1+ import { ChevronRight , Database , Hash , MessageSquare } from "lucide-react" ;
2+ import { type ReactNode , useState } from "react" ;
33import type { Address } from "viem" ;
44import { EmptyState } from "@/components/shared/empty-state" ;
55import { StatCard } from "@/components/shared/stat-card" ;
@@ -13,7 +13,7 @@ import {
1313 TableHeader ,
1414 TableRow ,
1515} from "@/components/ui/table" ;
16- import { type DecodedMessage , useChannelMessages } from "@/hooks/use-channel-messages" ;
16+ import { useChannelMessages } from "@/hooks/use-channel-messages" ;
1717import { SensorCharts } from "@/components/shared/sensor-charts" ;
1818
1919function formatBytes ( bytes : bigint ) : string {
@@ -92,48 +92,13 @@ function highlightJson(json: string): ReactNode[] {
9292 return parts ;
9393}
9494
95- export interface ChannelData {
96- messages : DecodedMessage [ ] ;
97- messageCount : bigint | undefined ;
98- maxCapacity : bigint | undefined ;
99- totalBytes : bigint | undefined ;
100- isLoading : boolean ;
101- hasMore : boolean ;
102- isLoadingMore : boolean ;
103- loadMore : ( ) => void ;
104- }
105-
10695interface ChannelViewProps {
10796 address : Address ;
108- data ?: ChannelData ;
10997}
11098
111- export function ChannelView ( { address, data } : ChannelViewProps ) {
112- const hookData = useChannelMessages ( address ) ;
113- const { messages, messageCount, maxCapacity, totalBytes, isLoading, hasMore, isLoadingMore, loadMore } =
114- data ?? hookData ;
99+ export function ChannelView ( { address } : ChannelViewProps ) {
100+ const { messages, messageCount, maxCapacity, totalBytes, isLoading } = useChannelMessages ( address ) ;
115101 const [ expanded , setExpanded ] = useState < Set < string > > ( new Set ( ) ) ;
116- const sentinelRef = useRef < HTMLTableRowElement > ( null ) ;
117-
118- // Clear expanded rows when switching channels
119- useEffect ( ( ) => {
120- setExpanded ( new Set ( ) ) ;
121- } , [ address ] ) ;
122-
123- useEffect ( ( ) => {
124- const el = sentinelRef . current ;
125- if ( ! el || ! hasMore ) return ;
126- const observer = new IntersectionObserver (
127- ( [ entry ] ) => {
128- if ( entry . isIntersecting && ! isLoadingMore ) {
129- loadMore ( ) ;
130- }
131- } ,
132- { threshold : 0.1 } ,
133- ) ;
134- observer . observe ( el ) ;
135- return ( ) => observer . disconnect ( ) ;
136- } , [ hasMore , isLoadingMore , loadMore ] ) ;
137102
138103 const toggleExpand = ( key : string ) => {
139104 setExpanded ( ( prev ) => {
@@ -278,17 +243,6 @@ export function ChannelView({ address, data }: ChannelViewProps) {
278243 </ >
279244 ) ;
280245 } ) }
281- { ( hasMore || isLoadingMore ) && (
282- < TableRow ref = { sentinelRef } className = "hover:bg-transparent" >
283- < TableCell colSpan = { 6 } className = "py-3 text-center" >
284- { isLoadingMore ? (
285- < Loader2 className = "h-4 w-4 animate-spin inline-block text-muted-foreground" />
286- ) : (
287- < span className = "text-xs text-muted-foreground" > Scroll for older messages</ span >
288- ) }
289- </ TableCell >
290- </ TableRow >
291- ) }
292246 </ TableBody >
293247 </ Table >
294248 </ div >
0 commit comments