1
1
'use client'
2
2
3
3
import { useOnlineCount } from '~/atoms'
4
+ import { ImpressionView } from '~/components/common/ImpressionTracker'
5
+ import { Divider } from '~/components/ui/divider'
4
6
import { FloatPopover } from '~/components/ui/float-popover'
5
7
import { NumberSmoothTransition } from '~/components/ui/number-transition/NumberSmoothTransition'
8
+ import { TrackerAction } from '~/constants/tracker'
6
9
import { usePageIsActive } from '~/hooks/common/use-is-active'
10
+ import { useSocketIsConnect } from '~/socket/hooks'
7
11
8
12
export const GatewayCount = ( ) => {
9
13
return (
@@ -26,10 +30,51 @@ export const GatewayCount = () => {
26
30
WebSocket
27
31
用于通知站点,站长在站点的实时活动,包括不限于文章的发布和更新。
28
32
</ p >
33
+
34
+ < Divider />
35
+
36
+ < p >
37
+ 当前 Socket 状态: < ConnectedIndicator />
38
+ </ p >
29
39
</ div >
30
40
</ FloatPopover >
31
41
)
32
42
}
43
+
44
+ const ConnectedIndicator = ( ) => {
45
+ const connected = useSocketIsConnect ( )
46
+
47
+ return (
48
+ < div className = "inline-flex items-center" >
49
+ < ImpressionView
50
+ trackerMessage = "socket_status"
51
+ action = { TrackerAction . Impression }
52
+ />
53
+ { connected ? (
54
+ < >
55
+ < span className = "absolute h-5 w-5" >
56
+ < span className = "absolute inset-0 z-[3] m-auto flex h-3 w-3 rounded-full bg-green-400" />
57
+ < span className = "absolute inset-0 z-[2] m-auto flex h-4 w-4 rounded-full bg-green-300" />
58
+ < span className = "relative z-[1] flex h-5 w-5 rounded-full bg-green-200 center" />
59
+ </ span >
60
+
61
+ < span className = "ml-6" > 已连接</ span >
62
+ </ >
63
+ ) : (
64
+ < >
65
+ < span className = "absolute h-5 w-5" >
66
+ < span className = "absolute inset-0 z-[3] m-auto flex h-3 w-3 rounded-full bg-red-400" />
67
+ < span className = "absolute inset-0 z-[2] m-auto flex h-4 w-4 rounded-full bg-red-300" />
68
+ < span className = "relative z-[1] flex h-5 w-5 rounded-full bg-red-200 center" />
69
+ </ span >
70
+
71
+ < span className = "ml-6" > 未连接</ span >
72
+ </ >
73
+ ) }
74
+ </ div >
75
+ )
76
+ }
77
+
33
78
const GatewayCountTrigger = ( ) => {
34
79
const isActive = usePageIsActive ( )
35
80
const count = useOnlineCount ( )
0 commit comments