Skip to content

Commit 3e55163

Browse files
committed
hella basic refetch interval control
1 parent d9bb064 commit 3e55163

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

app/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './use-key'
33
export * from './use-params'
44
export * from './use-toast'
55
export * from './use-reduce-motion'
6+
export * from './use-refetch-interval'

app/hooks/use-refetch-interval.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useState } from 'react'
2+
3+
import { Listbox } from '@oxide/ui'
4+
5+
type RefetchIntervalKey = 'Off' | '5s' | '10s' | '1m' | '2m' | '5m'
6+
type RefetchInterval = false | 5_000 | 10_000 | 60_000 | 120_000 | 300_000
7+
8+
const intervalValues: Record<RefetchIntervalKey, RefetchInterval> = {
9+
Off: false,
10+
'5s': 5_000,
11+
'10s': 10_000,
12+
'1m': 60_000,
13+
'2m': 120_000,
14+
'5m': 300_000,
15+
}
16+
17+
const intervalItems = Object.keys(intervalValues).map((k) => ({ label: k, value: k }))
18+
19+
export function useRefetchInterval(initialKey: RefetchIntervalKey = 'Off') {
20+
const [intervalKey, setIntervalKey] = useState<RefetchIntervalKey>(initialKey)
21+
return {
22+
refetchInterval: intervalValues[intervalKey],
23+
intervalListbox: (
24+
<Listbox
25+
items={intervalItems}
26+
defaultValue={initialKey}
27+
onChange={(item) => {
28+
if (item) {
29+
setIntervalKey(item.value as RefetchIntervalKey)
30+
}
31+
}}
32+
/>
33+
),
34+
}
35+
}

app/pages/project/instances/InstancesPage.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
buttonStyle,
2020
} from '@oxide/ui'
2121

22-
import { requireProjectParams, useProjectParams, useQuickActions } from 'app/hooks'
22+
import {
23+
requireProjectParams,
24+
useProjectParams,
25+
useQuickActions,
26+
useRefetchInterval,
27+
} from 'app/hooks'
2328
import { pb } from 'app/util/path-builder'
2429

2530
import { useMakeInstanceActions } from './actions'
@@ -73,11 +78,13 @@ export function InstancesPage() {
7378
)
7479
)
7580

81+
const { refetchInterval, intervalListbox } = useRefetchInterval('10s')
82+
7683
const { Table, Column } = useQueryTable(
7784
'instanceList',
7885
{ path: projectParams },
7986
{
80-
refetchInterval: 5000,
87+
refetchInterval,
8188
keepPreviousData: true,
8289
}
8390
)
@@ -90,6 +97,7 @@ export function InstancesPage() {
9097
<PageTitle icon={<Instances24Icon />}>Instances</PageTitle>
9198
</PageHeader>
9299
<TableActions>
100+
{intervalListbox}
93101
<Link
94102
to={pb.instanceNew({ orgName, projectName })}
95103
className={buttonStyle({ size: 'sm', variant: 'default' })}

0 commit comments

Comments
 (0)