1
1
import { Button } from '../core/Button'
2
- import { EntityList } from '../components/EntityList'
2
+ import { Heading } from '../core/Heading'
3
+ import { Panel } from '../core/Panel'
4
+ import { Text } from '../core/Text'
5
+ import { Skeleton } from '../core/Skeleton'
6
+ import { cx } from 'class-variance-authority'
3
7
4
8
type Props = {
5
9
peers ?: string [ ]
@@ -8,17 +12,67 @@ type Props = {
8
12
}
9
13
10
14
export function PeerList ( { peers, isLoading, connectPeer } : Props ) {
15
+ const showSkeleton = isLoading && ( ! peers || peers . length === 0 )
16
+ const showPeers = peers && peers . length > 0
17
+
11
18
return (
12
- < EntityList
13
- title = "Peers"
14
- actions = { < Button onClick = { connectPeer } > Connect</ Button > }
15
- isLoading = { isLoading }
16
- dataset = {
17
- peers ?. map ( ( netAddress ) => ( {
18
- type : 'ip' ,
19
- hash : netAddress ,
20
- } ) ) || [ ]
21
- }
22
- />
19
+ < Panel >
20
+ < div className = "flex flex-col rounded overflow-hidden" >
21
+ < div className = "flex items-center p-4 border-b border-gray-200 dark:border-graydark-300" >
22
+ < Heading size = "20" font = "mono" ellipsis >
23
+ Peers
24
+ </ Heading >
25
+ < div className = "flex-1" />
26
+ < Button onClick = { connectPeer } > Connect</ Button >
27
+ </ div >
28
+ < div className = "flex flex-col rounded overflow-hidden" >
29
+ { showSkeleton &&
30
+ Array . from ( { length : 10 } ) . map ( ( _ , i ) => (
31
+ < div
32
+ key = { i }
33
+ className = { cx (
34
+ 'flex items-center gap-4 p-4' ,
35
+ itemBorderStyles ( )
36
+ ) }
37
+ >
38
+ < Skeleton className = "w-[60px] h-[20px]" />
39
+ </ div >
40
+ ) ) }
41
+ { showPeers &&
42
+ peers . map ( ( ip , i ) => (
43
+ < div
44
+ key = { ip }
45
+ className = { cx (
46
+ 'flex items-center gap-4 p-4' ,
47
+ itemBorderStyles ( )
48
+ ) }
49
+ >
50
+ < Text size = "16" weight = "medium" ellipsis >
51
+ { ip }
52
+ </ Text >
53
+ </ div >
54
+ ) ) }
55
+ { ! showSkeleton && ( ! peers || peers . length === 0 ) && (
56
+ < div
57
+ className = { cx (
58
+ 'flex items-center justify-center h-[84px]' ,
59
+ itemBorderStyles ( )
60
+ ) }
61
+ >
62
+ < Text size = "18" color = "subtle" >
63
+ No peers
64
+ </ Text >
65
+ </ div >
66
+ ) }
67
+ </ div >
68
+ </ div >
69
+ </ Panel >
70
+ )
71
+ }
72
+
73
+ function itemBorderStyles ( ) {
74
+ return cx (
75
+ 'border-t border-gray-200 dark:border-graydark-300' ,
76
+ 'first:border-none'
23
77
)
24
78
}
0 commit comments