Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: renterd libs extract route variables #581

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/renterd/config/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { busStateKey } from '@siafoundation/renterd-react'
import { busStateRoute } from '@siafoundation/renterd-types'

export const routes = {
home: '/',
Expand Down Expand Up @@ -38,4 +38,4 @@ export const routes = {
login: '/login',
}

export const connectivityRoute = busStateKey
export const connectivityRoute = busStateRoute
6 changes: 3 additions & 3 deletions apps/renterd/contexts/config/useOnValid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
} from '@siafoundation/design-system'
import { useCallback } from 'react'
import {
autopilotHostsKey,
useAutopilotConfigUpdate,
useAutopilotTrigger,
useBusState,
Expand All @@ -22,6 +21,7 @@ import { delay, useMutate } from '@siafoundation/react-core'
import { Resources } from './resources'
import { useSyncContractSet } from './useSyncContractSet'
import BigNumber from 'bignumber.js'
import { autopilotHostsRoute } from '@siafoundation/renterd-types'

export function useOnValid({
resources,
Expand Down Expand Up @@ -155,9 +155,9 @@ export function useOnValid({
if (firstTimeSettingConfig) {
const refreshHostsAfterDelay = async () => {
await delay(5_000)
mutate((key) => key.startsWith(autopilotHostsKey))
mutate((key) => key.startsWith(autopilotHostsRoute))
await delay(5_000)
mutate((key) => key.startsWith(autopilotHostsKey))
mutate((key) => key.startsWith(autopilotHostsRoute))
}
refreshHostsAfterDelay()
}
Expand Down
7 changes: 4 additions & 3 deletions apps/renterd/contexts/hosts/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import { HostContext, HostData, TableColumnId } from './types'
import { format, formatDistance, formatRelative } from 'date-fns'
import { HostContextMenu } from '../../components/Hosts/HostContextMenu'
import { useWorkflows } from '@siafoundation/react-core'
import { AutopilotHost, RhpScanPayload } from '@siafoundation/renterd-types'
import {
useHostsAllowlist,
AutopilotHost,
RhpScanPayload,
workerRhpScanRoute,
} from '@siafoundation/renterd-react'
} from '@siafoundation/renterd-types'
import { useHostsAllowlist } from '@siafoundation/renterd-react'
import BigNumber from 'bignumber.js'
import React, { memo } from 'react'

Expand Down
10 changes: 5 additions & 5 deletions libs/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"version": "1.1.0",
"license": "MIT",
"peerDependencies": {
"react": "^18.2.0",
"react": "^18.2.0"
},
"dependencies": {
"@siafoundation/next": "^0.1.3",
"@siafoundation/request": "0.0.0",
"swr": "^2.1.1",
"axios": "^0.27.2",
"use-local-storage-state": "^18.3.3",
"@siafoundation/next": "^0.1.3",
"@siafoundation/request": "0.0.0"
},
"dependencies": {
"detect-gpu": "^5.0.34"
},
"types": "./src/index.d.ts"
Expand Down
38 changes: 20 additions & 18 deletions libs/renterd-react/src/autopilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,27 @@ import {
AutopilotTriggerParams,
AutopilotTriggerPayload,
AutopilotTriggerResponse,
autopilotConfigRoute,
autopilotHostsRoute,
autopilotStateRoute,
autopilotTriggerRoute,
} from '@siafoundation/renterd-types'

const autopilotStateKey = '/autopilot/state'

export function useAutopilotState(
args?: HookArgsSwr<AutopilotStateParams, AutopilotStateResponse>
) {
return useGetSwr({
...args,
route: autopilotStateKey,
route: autopilotStateRoute,
})
}

const autopilotConfigKey = '/autopilot/config'
export function useAutopilotConfig(
args?: HookArgsSwr<AutopilotConfigParams, AutopilotConfigResponse>
) {
return useGetSwr({
...args,
route: autopilotConfigKey,
route: autopilotConfigRoute,
})
}

Expand All @@ -52,20 +53,21 @@ export function useAutopilotConfigUpdate(
AutopilotConfigUpdateResponse
>
) {
return usePutFunc({ ...args, route: autopilotConfigKey }, async (mutate) => {
mutate((key) => key === autopilotConfigKey)
// might need a delay before revalidating status which returns whether
// or not autopilot is configured
const func = async () => {
await delay(1000)
mutate((key) => key === autopilotStateKey)
return usePutFunc(
{ ...args, route: autopilotConfigRoute },
async (mutate) => {
mutate((key) => key === autopilotConfigRoute)
// might need a delay before revalidating status which returns whether
// or not autopilot is configured
const func = async () => {
await delay(1000)
mutate((key) => key === autopilotStateRoute)
}
func()
}
func()
})
)
}

export const autopilotHostsKey = '/autopilot/hosts'

export function useAutopilotHostsSearch(
args?: HookArgsWithPayloadSwr<
AutopilotHostsSearchParams,
Expand All @@ -75,7 +77,7 @@ export function useAutopilotHostsSearch(
) {
return usePostSwr({
...args,
route: autopilotHostsKey,
route: autopilotHostsRoute,
})
}

Expand All @@ -88,6 +90,6 @@ export function useAutopilotTrigger(
) {
return usePostFunc({
...args,
route: '/autopilot/trigger',
route: autopilotTriggerRoute,
})
}
Loading
Loading