Skip to content

Commit 833c8f9

Browse files
committed
refactor: renterd libs extract route variables
1 parent b3a0803 commit 833c8f9

File tree

10 files changed

+326
-155
lines changed

10 files changed

+326
-155
lines changed

apps/renterd/config/routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { busStateKey } from '@siafoundation/renterd-react'
1+
import { busStateRoute } from '@siafoundation/renterd-types'
22

33
export const routes = {
44
home: '/',
@@ -38,4 +38,4 @@ export const routes = {
3838
login: '/login',
3939
}
4040

41-
export const connectivityRoute = busStateKey
41+
export const connectivityRoute = busStateRoute

apps/renterd/contexts/config/useOnValid.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
} from '@siafoundation/design-system'
55
import { useCallback } from 'react'
66
import {
7-
autopilotHostsKey,
87
useAutopilotConfigUpdate,
98
useAutopilotTrigger,
109
useBusState,
@@ -22,6 +21,7 @@ import { delay, useMutate } from '@siafoundation/react-core'
2221
import { Resources } from './resources'
2322
import { useSyncContractSet } from './useSyncContractSet'
2423
import BigNumber from 'bignumber.js'
24+
import { autopilotHostsRoute } from '@siafoundation/renterd-types'
2525

2626
export function useOnValid({
2727
resources,
@@ -155,9 +155,9 @@ export function useOnValid({
155155
if (firstTimeSettingConfig) {
156156
const refreshHostsAfterDelay = async () => {
157157
await delay(5_000)
158-
mutate((key) => key.startsWith(autopilotHostsKey))
158+
mutate((key) => key.startsWith(autopilotHostsRoute))
159159
await delay(5_000)
160-
mutate((key) => key.startsWith(autopilotHostsKey))
160+
mutate((key) => key.startsWith(autopilotHostsRoute))
161161
}
162162
refreshHostsAfterDelay()
163163
}

apps/renterd/contexts/hosts/columns.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import { HostContext, HostData, TableColumnId } from './types'
2020
import { format, formatDistance, formatRelative } from 'date-fns'
2121
import { HostContextMenu } from '../../components/Hosts/HostContextMenu'
2222
import { useWorkflows } from '@siafoundation/react-core'
23-
import { AutopilotHost, RhpScanPayload } from '@siafoundation/renterd-types'
2423
import {
25-
useHostsAllowlist,
24+
AutopilotHost,
25+
RhpScanPayload,
2626
workerRhpScanRoute,
27-
} from '@siafoundation/renterd-react'
27+
} from '@siafoundation/renterd-types'
28+
import { useHostsAllowlist } from '@siafoundation/renterd-react'
2829
import BigNumber from 'bignumber.js'
2930
import React, { memo } from 'react'
3031

libs/react-core/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"version": "1.1.0",
55
"license": "MIT",
66
"peerDependencies": {
7-
"react": "^18.2.0",
7+
"react": "^18.2.0"
8+
},
9+
"dependencies": {
10+
"@siafoundation/next": "^0.1.3",
11+
"@siafoundation/request": "0.0.0",
812
"swr": "^2.1.1",
913
"axios": "^0.27.2",
1014
"use-local-storage-state": "^18.3.3",
11-
"@siafoundation/next": "^0.1.3",
12-
"@siafoundation/request": "0.0.0"
13-
},
14-
"dependencies": {
1515
"detect-gpu": "^5.0.34"
1616
},
1717
"types": "./src/index.d.ts"

libs/renterd-react/src/autopilot.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,27 @@ import {
2222
AutopilotTriggerParams,
2323
AutopilotTriggerPayload,
2424
AutopilotTriggerResponse,
25+
autopilotConfigRoute,
26+
autopilotHostsRoute,
27+
autopilotStateRoute,
28+
autopilotTriggerRoute,
2529
} from '@siafoundation/renterd-types'
2630

27-
const autopilotStateKey = '/autopilot/state'
28-
2931
export function useAutopilotState(
3032
args?: HookArgsSwr<AutopilotStateParams, AutopilotStateResponse>
3133
) {
3234
return useGetSwr({
3335
...args,
34-
route: autopilotStateKey,
36+
route: autopilotStateRoute,
3537
})
3638
}
3739

38-
const autopilotConfigKey = '/autopilot/config'
3940
export function useAutopilotConfig(
4041
args?: HookArgsSwr<AutopilotConfigParams, AutopilotConfigResponse>
4142
) {
4243
return useGetSwr({
4344
...args,
44-
route: autopilotConfigKey,
45+
route: autopilotConfigRoute,
4546
})
4647
}
4748

@@ -52,20 +53,21 @@ export function useAutopilotConfigUpdate(
5253
AutopilotConfigUpdateResponse
5354
>
5455
) {
55-
return usePutFunc({ ...args, route: autopilotConfigKey }, async (mutate) => {
56-
mutate((key) => key === autopilotConfigKey)
57-
// might need a delay before revalidating status which returns whether
58-
// or not autopilot is configured
59-
const func = async () => {
60-
await delay(1000)
61-
mutate((key) => key === autopilotStateKey)
56+
return usePutFunc(
57+
{ ...args, route: autopilotConfigRoute },
58+
async (mutate) => {
59+
mutate((key) => key === autopilotConfigRoute)
60+
// might need a delay before revalidating status which returns whether
61+
// or not autopilot is configured
62+
const func = async () => {
63+
await delay(1000)
64+
mutate((key) => key === autopilotStateRoute)
65+
}
66+
func()
6267
}
63-
func()
64-
})
68+
)
6569
}
6670

67-
export const autopilotHostsKey = '/autopilot/hosts'
68-
6971
export function useAutopilotHostsSearch(
7072
args?: HookArgsWithPayloadSwr<
7173
AutopilotHostsSearchParams,
@@ -75,7 +77,7 @@ export function useAutopilotHostsSearch(
7577
) {
7678
return usePostSwr({
7779
...args,
78-
route: autopilotHostsKey,
80+
route: autopilotHostsRoute,
7981
})
8082
}
8183

@@ -88,6 +90,6 @@ export function useAutopilotTrigger(
8890
) {
8991
return usePostFunc({
9092
...args,
91-
route: '/autopilot/trigger',
93+
route: autopilotTriggerRoute,
9294
})
9395
}

0 commit comments

Comments
 (0)