1
- import { defaultErrorHandler , trpc } from '@/api/trpc' ;
2
- import { CommonHeader } from '@/components/CommonHeader' ;
1
+ import { createFileRoute } from '@tanstack/react-router' ;
2
+ import { AIGatewayLogTable } from '@/components/aiGateway/AIGatewayLogTable' ;
3
+ import { AIGatewayOverview } from '@/components/aiGateway/AIGatewayOverview' ;
4
+ import { useState , useRef } from 'react' ;
5
+ import { useTranslation } from '@i18next-toolkit/react' ;
6
+ import { Switch } from '@/components/ui/switch' ;
7
+ import { Label } from '@/components/ui/label' ;
8
+ import { trpc , defaultErrorHandler } from '@/api/trpc' ;
9
+ import { AlertConfirm } from '@/components/AlertConfirm' ;
10
+ import { Button } from '@/components/ui/button' ;
3
11
import { CommonWrapper } from '@/components/CommonWrapper' ;
12
+ import { Tabs , TabsContent , TabsList , TabsTrigger } from '@/components/ui/tabs' ;
13
+ import { CommonHeader } from '@/components/CommonHeader' ;
4
14
import { ErrorTip } from '@/components/ErrorTip' ;
5
15
import { Loading } from '@/components/Loading' ;
6
- import { Button } from '@/components/ui/button' ;
7
- import { Tabs , TabsContent , TabsList , TabsTrigger } from '@/components/ui/tabs' ;
8
16
import { useCurrentWorkspaceId , useHasAdminPermission } from '@/store/user' ;
9
17
import { routeAuthBeforeLoad } from '@/utils/route' ;
10
- import { createFileRoute , useNavigate } from '@tanstack/react-router' ;
18
+ import { useNavigate } from '@tanstack/react-router' ;
11
19
import { LuPencil , LuTrash } from 'react-icons/lu' ;
12
- import { useTranslation } from '@i18next-toolkit/react' ;
13
- import { AlertConfirm } from '@/components/AlertConfirm' ;
14
20
import { message } from 'antd' ;
15
21
import { NotFoundTip } from '@/components/NotFoundTip' ;
16
22
import { useEvent } from '@/hooks/useEvent' ;
17
- import { AIGatewayLogTable } from '@/components/aiGateway/AIGatewayLogTable' ;
18
- import { AIGatewayOverview } from '@/components/aiGateway/AIGatewayOverview' ;
23
+ import { useWatch } from '@/hooks/useWatch' ;
19
24
20
25
export const Route = createFileRoute ( '/aiGateway/$gatewayId/' ) ( {
21
26
beforeLoad : routeAuthBeforeLoad ,
@@ -129,7 +134,10 @@ function PageComponent() {
129
134
className = "mt-4 w-full flex-1 space-y-4 overflow-hidden"
130
135
>
131
136
< div className = "flex h-full w-full flex-col overflow-auto rounded-lg border p-4" >
132
- < h3 className = "mb-2 text-lg font-medium" > { t ( 'Gateway Logs' ) } </ h3 >
137
+ < div className = "mb-2 flex items-center justify-between" >
138
+ < h3 className = "text-lg font-medium" > { t ( 'Gateway Logs' ) } </ h3 >
139
+ < RealtimeUpdateButton gatewayId = { gatewayId } />
140
+ </ div >
133
141
< AIGatewayLogTable gatewayId = { gatewayId } />
134
142
</ div >
135
143
</ TabsContent >
@@ -138,3 +146,49 @@ function PageComponent() {
138
146
</ CommonWrapper >
139
147
) ;
140
148
}
149
+
150
+ interface RealtimeUpdateButtonProps {
151
+ gatewayId : string ;
152
+ }
153
+
154
+ function RealtimeUpdateButton ( { gatewayId } : RealtimeUpdateButtonProps ) {
155
+ const { t } = useTranslation ( ) ;
156
+ const workspaceId = useCurrentWorkspaceId ( ) ;
157
+ const [ isRealtime , setIsRealtime ] = useState ( false ) ;
158
+ const utils = trpc . useUtils ( ) ;
159
+ const timerRef = useRef < NodeJS . Timeout | null > ( null ) ;
160
+
161
+ useWatch ( [ isRealtime , gatewayId ] , ( ) => {
162
+ if ( isRealtime ) {
163
+ timerRef . current = setInterval ( ( ) => {
164
+ utils . aiGateway . logs . invalidate ( {
165
+ workspaceId,
166
+ gatewayId,
167
+ } ) ;
168
+ } , 4000 ) ;
169
+ } else {
170
+ if ( timerRef . current ) {
171
+ clearInterval ( timerRef . current ) ;
172
+ timerRef . current = null ;
173
+ }
174
+ }
175
+
176
+ return ( ) => {
177
+ if ( timerRef . current ) {
178
+ clearInterval ( timerRef . current ) ;
179
+ timerRef . current = null ;
180
+ }
181
+ } ;
182
+ } ) ;
183
+
184
+ return (
185
+ < div className = "flex items-center space-x-2" >
186
+ < Switch
187
+ id = "realtime-mode"
188
+ checked = { isRealtime }
189
+ onCheckedChange = { setIsRealtime }
190
+ />
191
+ < Label htmlFor = "realtime-mode" > { t ( 'Realtime Update' ) } </ Label >
192
+ </ div >
193
+ ) ;
194
+ }
0 commit comments