Skip to content

Commit 06a0c9c

Browse files
committed
refactor: renterd libs extract route variables
1 parent e54efd3 commit 06a0c9c

File tree

12 files changed

+322
-152
lines changed

12 files changed

+322
-152
lines changed

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/react-core/src/useDelete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import {
88
buildRouteWithParams,
99
InternalCallbackArgs,
1010
mergeInternalCallbackArgs,
11-
RequestParams,
1211
Response,
1312
InternalHookArgsCallback,
1413
mergeInternalHookArgsCallback,
1514
After,
1615
getPathFromKey,
1716
} from './request'
1817
import { useAppSettings } from './useAppSettings'
18+
import { RequestParams } from '@siafoundation/request'
1919

2020
type DeleteFunc<Params extends RequestParams, Result> = {
2121
delete: (

libs/react-core/src/useGet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
buildRouteWithParams,
99
InternalCallbackArgs,
1010
mergeInternalCallbackArgs,
11-
RequestParams,
1211
Response,
1312
mergeInternalHookArgsCallback,
1413
InternalHookArgsSwr,
@@ -18,6 +17,7 @@ import {
1817
import { SWRError } from './types'
1918
import { useAppSettings } from './useAppSettings'
2019
import { keyOrNull } from './utils'
20+
import { RequestParams } from '@siafoundation/request'
2121

2222
export function useGetSwr<Params extends RequestParams, Result>(
2323
args: InternalHookArgsSwr<Params, Result>

libs/react-core/src/usePatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
InternalCallbackArgs,
1010
InternalHookArgsCallback,
1111
mergeInternalCallbackArgs,
12-
RequestParams,
1312
Response,
1413
mergeInternalHookArgsCallback,
1514
getPathFromKey,
@@ -22,6 +21,7 @@ import { useAppSettings } from './useAppSettings'
2221
import { useMemo } from 'react'
2322
import { keyOrNull } from './utils'
2423
import { SWRError } from './types'
24+
import { RequestParams } from '@siafoundation/request'
2525

2626
export function usePatchSwr<Params extends RequestParams, Payload, Result>(
2727
args: InternalHookArgsWithPayloadSwr<Params, Payload, Result>

libs/react-core/src/usePost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
buildRouteWithParams,
99
InternalCallbackArgs,
1010
mergeInternalCallbackArgs,
11-
RequestParams,
1211
Response,
1312
InternalHookArgsCallback,
1413
mergeInternalHookArgsCallback,
@@ -22,6 +21,7 @@ import { SWRError } from './types'
2221
import { useAppSettings } from './useAppSettings'
2322
import { keyOrNull } from './utils'
2423
import { useWorkflows } from './workflows'
24+
import { RequestParams } from '@siafoundation/request'
2525

2626
export function usePostSwr<Params extends RequestParams, Payload, Result>(
2727
args: InternalHookArgsWithPayloadSwr<Params, Payload, Result>

libs/react-core/src/usePut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
InternalCallbackArgs,
1010
InternalHookArgsCallback,
1111
mergeInternalCallbackArgs,
12-
RequestParams,
1312
Response,
1413
mergeInternalHookArgsCallback,
1514
getPathFromKey,
@@ -22,6 +21,7 @@ import { useAppSettings } from './useAppSettings'
2221
import { useMemo } from 'react'
2322
import { keyOrNull } from './utils'
2423
import { SWRError } from './types'
24+
import { RequestParams } from '@siafoundation/request'
2525

2626
export function usePutSwr<Params extends RequestParams, Payload, Result>(
2727
args: InternalHookArgsWithPayloadSwr<Params, Payload, Result>

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)